Add fallback to bestvideo and worstvideo (fixes #288)
This commit is contained in:
parent
4ef7a93dce
commit
29756cf290
3 changed files with 23 additions and 17 deletions
|
@ -151,9 +151,9 @@ class Config
|
||||||
if (empty($this->genericFormats)) {
|
if (empty($this->genericFormats)) {
|
||||||
// We don't put this in the class definition so it can be detected by xgettext.
|
// We don't put this in the class definition so it can be detected by xgettext.
|
||||||
$this->genericFormats = [
|
$this->genericFormats = [
|
||||||
'best' => $localeManager->t('Best'),
|
'best/bestvideo' => $localeManager->t('Best'),
|
||||||
'bestvideo+bestaudio' => $localeManager->t('Remux best video with best audio'),
|
'bestvideo+bestaudio' => $localeManager->t('Remux best video with best audio'),
|
||||||
'worst' => $localeManager->t('Worst'),
|
'worst/worstvideo' => $localeManager->t('Worst'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,26 +165,31 @@ class Config
|
||||||
}
|
}
|
||||||
} elseif (!$this->stream) {
|
} elseif (!$this->stream) {
|
||||||
// Force HTTP if stream is not enabled.
|
// Force HTTP if stream is not enabled.
|
||||||
$this->replaceGenericFormat($format, $format . '[protocol=https]/' . $format . '[protocol=http]');
|
$keys = array_keys($this->genericFormats);
|
||||||
|
$keys[array_search($format, $keys)] = $this->addHttpToFormat($format);
|
||||||
|
if ($genericFormats = array_combine($keys, $this->genericFormats)) {
|
||||||
|
$this->genericFormats = $genericFormats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace a format key.
|
* Add HTTP condition to a format.
|
||||||
*
|
*
|
||||||
* @param string $oldFormat Old format
|
* @param string $format Format
|
||||||
* @param string $newFormat New format
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function replaceGenericFormat($oldFormat, $newFormat)
|
public static function addHttpToFormat($format)
|
||||||
{
|
{
|
||||||
$keys = array_keys($this->genericFormats);
|
$newFormat = [];
|
||||||
$keys[array_search($oldFormat, $keys)] = $newFormat;
|
foreach (explode('/', $format) as $subformat) {
|
||||||
if ($genericFormats = array_combine($keys, $this->genericFormats)) {
|
$newFormat[] = $subformat . '[protocol=https]';
|
||||||
$this->genericFormats = $genericFormats;
|
$newFormat[] = $subformat . '[protocol=http]';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return implode('/', $newFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,9 +49,9 @@ appName: AllTube Download
|
||||||
|
|
||||||
# Generic formats supported by youtube-dl
|
# Generic formats supported by youtube-dl
|
||||||
genericFormats:
|
genericFormats:
|
||||||
best: Best
|
best/bestvideo: Best
|
||||||
bestvideo+bestaudio: Remux best video with best audio
|
bestvideo+bestaudio: Remux best video with best audio
|
||||||
worst: Worst
|
worst/worstvideo: Worst
|
||||||
|
|
||||||
# Enable debug mode.
|
# Enable debug mode.
|
||||||
debug: false
|
debug: false
|
||||||
|
|
|
@ -31,7 +31,7 @@ abstract class BaseController
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $defaultFormat = 'best[protocol=https]/best[protocol=http]';
|
protected $defaultFormat = 'best/bestvideo';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slim dependency container.
|
* Slim dependency container.
|
||||||
|
@ -74,8 +74,9 @@ abstract class BaseController
|
||||||
$this->sessionSegment = $session->getSegment(self::class);
|
$this->sessionSegment = $session->getSegment(self::class);
|
||||||
$this->localeManager = $this->container->get('locale');
|
$this->localeManager = $this->container->get('locale');
|
||||||
|
|
||||||
if ($this->config->stream) {
|
if (!$this->config->stream) {
|
||||||
$this->defaultFormat = 'best';
|
// Force HTTP if stream is not enabled.
|
||||||
|
$this->defaultFormat = Config::addHttpToFormat($this->defaultFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue