Simplify PSR-4 autoload
This commit is contained in:
parent
65ccf95437
commit
d127964eff
12 changed files with 81 additions and 84 deletions
44
classes/Controller/JsonController.php
Normal file
44
classes/Controller/JsonController.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* JsonController class.
|
||||
*/
|
||||
|
||||
namespace Alltube\Controller;
|
||||
|
||||
use Alltube\Library\Exception\AlltubeLibraryException;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
/**
|
||||
* Controller that returns JSON.
|
||||
*/
|
||||
class JsonController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Return the JSON object generated by youtube-dl.
|
||||
*
|
||||
* @param Request $request PSR-7 request
|
||||
* @param Response $response PSR-7 response
|
||||
*
|
||||
* @return Response HTTP response
|
||||
* @throws AlltubeLibraryException
|
||||
*/
|
||||
public function json(Request $request, Response $response)
|
||||
{
|
||||
$url = $request->getQueryParam('url');
|
||||
|
||||
if (isset($url)) {
|
||||
$this->video = $this->downloader->getVideo(
|
||||
$url,
|
||||
$this->getFormat($request),
|
||||
$this->getPassword($request)
|
||||
);
|
||||
|
||||
return $response->withJson($this->video->getJson());
|
||||
} else {
|
||||
return $response->withJson(['error' => 'You need to provide the url parameter'])
|
||||
->withStatus(400);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue