Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Aug 13, 2018
2 parents 67283f5 + 7c908d2 commit b343084
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 223 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM php:7.0-apache
RUN apt-get update && apt-get install -my gnupg
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
Expand Down
5 changes: 5 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"PYTHON": {
"description": "Path to python binary",
"value": "/app/.heroku/python/bin/python"
},
"STREAM": {
"description": "Enable stream mode",
"value": "false",
"required": false
}
},
"website": "https://alltubedownload.net/"
Expand Down
2 changes: 1 addition & 1 deletion classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function __construct(array $options)
*/
private function getEnv()
{
foreach (['CONVERT', 'PYTHON', 'AUDIO_BITRATE'] as $var) {
foreach (['CONVERT', 'PYTHON', 'AUDIO_BITRATE', 'STREAM'] as $var) {
$env = getenv($var);
if ($env) {
$prop = lcfirst(str_replace('_', '', ucwords(strtolower($var), '_')));
Expand Down
93 changes: 59 additions & 34 deletions classes/VideoDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,26 @@ private function getRtmpArguments(stdClass $video)
{
$arguments = [];

foreach ([
'url' => '-rtmp_tcurl',
'webpage_url' => '-rtmp_pageurl',
'player_url' => '-rtmp_swfverify',
'flash_version' => '-rtmp_flashver',
'play_path' => '-rtmp_playpath',
'app' => '-rtmp_app',
] as $property => $option) {
if (isset($video->{$property})) {
$arguments[] = $option;
$arguments[] = $video->{$property};
if ($video->protocol == 'rtmp') {
foreach ([
'url' => '-rtmp_tcurl',
'webpage_url' => '-rtmp_pageurl',
'player_url' => '-rtmp_swfverify',
'flash_version' => '-rtmp_flashver',
'play_path' => '-rtmp_playpath',
'app' => '-rtmp_app',
] as $property => $option) {
if (isset($video->{$property})) {
$arguments[] = $option;
$arguments[] = $video->{$property};
}
}
}

if (isset($video->rtmp_conn)) {
foreach ($video->rtmp_conn as $conn) {
$arguments[] = '-rtmp_conn';
$arguments[] = $conn;
if (isset($video->rtmp_conn)) {
foreach ($video->rtmp_conn as $conn) {
$arguments[] = '-rtmp_conn';
$arguments[] = $conn;
}
}
}

Expand Down Expand Up @@ -268,41 +270,60 @@ private function checkCommand(array $command)
* @param int $audioBitrate Audio bitrate of the converted file
* @param string $filetype Filetype of the converted file
* @param bool $audioOnly True to return an audio-only file
* @param string $from Start the conversion at this time
* @param string $to End the conversion at this time
*
* @throws Exception If avconv/ffmpeg is missing
*
* @return Process Process
*/
private function getAvconvProcess(stdClass $video, $audioBitrate, $filetype = 'mp3', $audioOnly = true)
{
private function getAvconvProcess(
stdClass $video,
$audioBitrate,
$filetype = 'mp3',
$audioOnly = true,
$from = null,
$to = null
) {
if (!$this->checkCommand([$this->config->avconv, '-version'])) {
throw new Exception(_('Can\'t find avconv or ffmpeg at ').$this->config->avconv.'.');
}

if ($video->protocol == 'rtmp') {
$rtmpArguments = $this->getRtmpArguments($video);
} else {
$rtmpArguments = [];
}
$durationRegex = '/(\d+:)?(\d+:)?(\d+)/';

$afterArguments = [];

if ($audioOnly) {
$videoArguments = ['-vn'];
} else {
$videoArguments = [];
$afterArguments[] = '-vn';
}

if (!empty($from)) {
if (!preg_match($durationRegex, $from)) {
throw new Exception(_('Invalid start time: ').$from.'.');
}
$afterArguments[] = '-ss';
$afterArguments[] = $from;
}
if (!empty($to)) {
if (!preg_match($durationRegex, $to)) {
throw new Exception(_('Invalid end time: ').$to.'.');
}
$afterArguments[] = '-to';
$afterArguments[] = $to;
}

$arguments = array_merge(
[
$this->config->avconv,
'-v', $this->config->avconvVerbosity,
],
$rtmpArguments,
$this->getRtmpArguments($video),
[
'-i', $video->url,
'-f', $filetype,
'-b:a', $audioBitrate.'k',
],
$videoArguments,
$afterArguments,
[
'pipe:1',
]
Expand All @@ -322,27 +343,31 @@ private function getAvconvProcess(stdClass $video, $audioBitrate, $filetype = 'm
* @param string $url URL of page
* @param string $format Format to use for the video
* @param string $password Video password
* @param string $from Start the conversion at this time
* @param string $to End the conversion at this time
*
* @throws Exception If your try to convert and M3U8 video
* @throws Exception If the popen stream was not created correctly
*
* @return resource popen stream
*/
public function getAudioStream($url, $format, $password = null)
public function getAudioStream($url, $format, $password = null, $from = null, $to = null)
{
$video = $this->getJSON($url, $format, $password);

if (isset($video->_type) && $video->_type == 'playlist') {
throw new Exception(_('Conversion of playlists is not supported.'));
}

if (in_array($video->protocol, ['m3u8', 'm3u8_native'])) {
throw new Exception(_('Conversion of M3U8 files is not supported.'));
} elseif ($video->protocol == 'http_dash_segments') {
throw new Exception(_('Conversion of DASH segments is not supported.'));
if (isset($video->protocol)) {
if (in_array($video->protocol, ['m3u8', 'm3u8_native'])) {
throw new Exception(_('Conversion of M3U8 files is not supported.'));
} elseif ($video->protocol == 'http_dash_segments') {
throw new Exception(_('Conversion of DASH segments is not supported.'));
}
}

$avconvProc = $this->getAvconvProcess($video, $this->config->audioBitrate);
$avconvProc = $this->getAvconvProcess($video, $this->config->audioBitrate, 'mp3', true, $from, $to);

$stream = popen($avconvProc->getCommandLine(), 'r');

Expand Down
83 changes: 63 additions & 20 deletions controllers/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function __construct(ContainerInterface $container, Config $config = null
$session = $session_factory->newInstance($cookies);
$this->sessionSegment = $session->getSegment(self::class);
if ($this->config->remux) {
$this->defaultFormat = 'bestvideo+bestaudio';
$this->defaultFormat = 'bestvideo+bestaudio,best';
} elseif ($this->config->stream) {
$this->defaultFormat = 'best';
}
Expand Down Expand Up @@ -201,7 +201,57 @@ public function password(Request $request, Response $response)
}

/**
* 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)
{
if (!isset($params['from'])) {
$params['from'] = '';
}
if (!isset($params['to'])) {
$params['to'] = '';
}

$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
Expand All @@ -213,6 +263,10 @@ public function password(Request $request, Response $response)
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 {
Expand All @@ -223,23 +277,7 @@ private function getAudioResponse(Request $request, Response $response, array $p
} 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);
}
}

Expand Down Expand Up @@ -305,7 +343,12 @@ private function getVideoResponse(Request $request, Response $response, array $p
public function video(Request $request, Response $response)
{
$params = $request->getQueryParams();
if (isset($params['url'])) {

if (!isset($params['url']) && isset($params['v'])) {
$params['url'] = $params['v'];
}

if (isset($params['url']) && !empty($params['url'])) {
$password = $request->getParam('password');
if (isset($password)) {
$this->sessionSegment->setFlash($params['url'], $password);
Expand Down
13 changes: 10 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ footer a:hover {
width:622px;
}

.mp3 p {
.mp3-inner {
padding:3px;
}


.audio:not(:checked),
.audio:checked {
left: -9999px;
Expand All @@ -273,7 +272,7 @@ footer a:hover {
.audio:not(:checked) + label,
.audio:checked + label {
cursor: pointer;
line-height:22px;
line-height:20px;
padding-left: 82px;
position: relative;
}
Expand Down Expand Up @@ -373,7 +372,15 @@ footer a:hover {
width:73px;
}

.seekOptions {
display: none;
margin-top: 15px;
text-align: center;
}

.audio:checked ~ .seekOptions {
display: block;
}


/* Playlists */
Expand Down
Loading

0 comments on commit b343084

Please sign in to comment.