feat: Add a way to trim the audio
This commit is contained in:
parent
c80828f300
commit
f1cf0a2cdc
4 changed files with 112 additions and 38 deletions
|
@ -201,7 +201,50 @@ class FrontController
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the converted MP3 file.
|
||||
* Return a converted MP3 file.
|
||||
*
|
||||
* @param Request $request PSR-7 request
|
||||
* @param Response $response PSR-7 response
|
||||
* @param array $params GET query parameters
|
||||
* @param string $password Video password
|
||||
*
|
||||
* @return Response HTTP response
|
||||
*/
|
||||
private function getConvertedAudioResponse(Request $request, Response $response, array $params, $password = null)
|
||||
{
|
||||
$response = $response->withHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename="'.
|
||||
$this->download->getAudioFilename($params['url'], 'bestaudio/best', $password).'"'
|
||||
);
|
||||
$response = $response->withHeader('Content-Type', 'audio/mpeg');
|
||||
|
||||
if ($request->isGet() || $request->isPost()) {
|
||||
try {
|
||||
$process = $this->download->getAudioStream(
|
||||
$params['url'],
|
||||
'bestaudio/best',
|
||||
$password,
|
||||
$params['from'],
|
||||
$params['to']
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$process = $this->download->getAudioStream(
|
||||
$params['url'],
|
||||
$this->defaultFormat,
|
||||
$password,
|
||||
$params['from'],
|
||||
$params['to']
|
||||
);
|
||||
}
|
||||
$response = $response->withBody(new Stream($process));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MP3 file.
|
||||
*
|
||||
* @param Request $request PSR-7 request
|
||||
* @param Response $response PSR-7 response
|
||||
|
@ -213,6 +256,10 @@ class FrontController
|
|||
private function getAudioResponse(Request $request, Response $response, array $params, $password = null)
|
||||
{
|
||||
try {
|
||||
if (isset($params['from']) || isset($params['to'])) {
|
||||
throw new Exception('Force convert when we need to seek.');
|
||||
}
|
||||
|
||||
if ($this->config->stream) {
|
||||
return $this->getStream($params['url'], 'mp3', $response, $request, $password);
|
||||
} else {
|
||||
|
@ -223,23 +270,7 @@ class FrontController
|
|||
} catch (PasswordException $e) {
|
||||
return $this->password($request, $response);
|
||||
} catch (Exception $e) {
|
||||
$response = $response->withHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename="'.
|
||||
$this->download->getAudioFilename($params['url'], 'bestaudio/best', $password).'"'
|
||||
);
|
||||
$response = $response->withHeader('Content-Type', 'audio/mpeg');
|
||||
|
||||
if ($request->isGet() || $request->isPost()) {
|
||||
try {
|
||||
$process = $this->download->getAudioStream($params['url'], 'bestaudio/best', $password);
|
||||
} catch (Exception $e) {
|
||||
$process = $this->download->getAudioStream($params['url'], $this->defaultFormat, $password);
|
||||
}
|
||||
$response = $response->withBody(new Stream($process));
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $this->getConvertedAudioResponse($request, $response, $params, $password);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue