Add fallback to bestvideo and worstvideo (fixes #288)

This commit is contained in:
Pierre Rudloff 2020-06-20 13:33:16 +02:00
parent 4ef7a93dce
commit 29756cf290
3 changed files with 23 additions and 17 deletions

View file

@ -151,9 +151,9 @@ class Config
if (empty($this->genericFormats)) {
// We don't put this in the class definition so it can be detected by xgettext.
$this->genericFormats = [
'best' => $localeManager->t('Best'),
'best/bestvideo' => $localeManager->t('Best'),
'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) {
// 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 $newFormat New format
* @param string $format Format
*
* @return void
* @return string
*/
private function replaceGenericFormat($oldFormat, $newFormat)
public static function addHttpToFormat($format)
{
$keys = array_keys($this->genericFormats);
$keys[array_search($oldFormat, $keys)] = $newFormat;
if ($genericFormats = array_combine($keys, $this->genericFormats)) {
$this->genericFormats = $genericFormats;
$newFormat = [];
foreach (explode('/', $format) as $subformat) {
$newFormat[] = $subformat . '[protocol=https]';
$newFormat[] = $subformat . '[protocol=http]';
}
return implode('/', $newFormat);
}
/**

View file

@ -49,9 +49,9 @@ appName: AllTube Download
# Generic formats supported by youtube-dl
genericFormats:
best: Best
best/bestvideo: Best
bestvideo+bestaudio: Remux best video with best audio
worst: Worst
worst/worstvideo: Worst
# Enable debug mode.
debug: false

View file

@ -31,7 +31,7 @@ abstract class BaseController
*
* @var string
*/
protected $defaultFormat = 'best[protocol=https]/best[protocol=http]';
protected $defaultFormat = 'best/bestvideo';
/**
* Slim dependency container.
@ -74,8 +74,9 @@ abstract class BaseController
$this->sessionSegment = $session->getSegment(self::class);
$this->localeManager = $this->container->get('locale');
if ($this->config->stream) {
$this->defaultFormat = 'best';
if (!$this->config->stream) {
// Force HTTP if stream is not enabled.
$this->defaultFormat = Config::addHttpToFormat($this->defaultFormat);
}
}