feat: JSON API
This commit is contained in:
parent
618fb8416a
commit
74505cea57
4 changed files with 84 additions and 1 deletions
|
@ -548,6 +548,36 @@ class FrontController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSON object generated by youtube-dl.
|
||||
*
|
||||
* @param Request $request PSR-7 request
|
||||
* @param Response $response PSR-7 response
|
||||
*
|
||||
* @return Response HTTP response
|
||||
*/
|
||||
public function json(Request $request, Response $response)
|
||||
{
|
||||
$params = $request->getQueryParams();
|
||||
$format = $this->getFormat($request);
|
||||
if (isset($params['url'])) {
|
||||
try {
|
||||
return $response->withJson(
|
||||
$this->download->getJSON(
|
||||
$params['url'],
|
||||
$format
|
||||
)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $response->withJson(['error' => $e->getMessage()])
|
||||
->withStatus(500);
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(['error' => 'You need to provide the url parameter'])
|
||||
->withStatus(400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the canonical URL of the current page.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue