Move Video class to a separate library

+ improve error handling
+ youtube-dl update
This commit is contained in:
Pierre Rudloff 2020-06-21 01:44:20 +02:00
parent 7d94271a49
commit 5c2823e3f1
30 changed files with 649 additions and 1152 deletions

View file

@ -6,8 +6,7 @@
namespace Alltube\Controller;
use Alltube\Video;
use Exception;
use Alltube\Library\Exception\AlltubeLibraryException;
use Slim\Http\Request;
use Slim\Http\Response;
@ -19,24 +18,24 @@ class JsonController extends BaseController
/**
* Return the JSON object generated by youtube-dl.
*
* @param Request $request PSR-7 request
* @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)) {
try {
$this->video = new Video($url, $this->getFormat($request), $this->getPassword($request));
$this->video = $this->downloader->getVideo(
$url,
$this->getFormat($request),
$this->getPassword($request)
);
return $response->withJson($this->video->getJson());
} catch (Exception $e) {
return $response->withJson(['error' => $e->getMessage()])
->withStatus(500);
}
return $response->withJson($this->video->getJson());
} else {
return $response->withJson(['error' => 'You need to provide the url parameter'])
->withStatus(400);