Skip to content

Commit

Permalink
Add extractor options
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Sep 23, 2024
1 parent c0ef03a commit 177195a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
81 changes: 81 additions & 0 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ class Options
private ?string $convertSubsFormat = null;
private bool $forceKeyframesAtCuts = false;

// Extractor Options
/**
* @var int|'infinite'|null
*/
private $extractorRetries;
private bool $allowDynamicMpd = false;
private bool $hlsSplitDiscontinuity = false;
/**
* @var array<non-empty-string, string>
*/
private array $extractorArgs = [];

/**
* @var list<non-empty-string>
*/
Expand Down Expand Up @@ -1666,6 +1678,69 @@ public function convertSubsFormat(?string $subsFormat): self
return $new;
}

/**
* @param int|'infinite'|null $retries
*/
public function extractorRetries($retries): self
{
$new = clone $this;
$new->extractorRetries = $retries;

return $new;
}

/**
* Process dynamic DASH manifests.
*/
public function allowDynamicMpd(bool $allowDynamicMpd): self
{
$new = clone $this;
$new->allowDynamicMpd = $allowDynamicMpd;

return $new;
}

/**
* Split HLS playlists to different formats at discontinuities such as ad breaks.
*/
public function hlsSplitDiscontinuity(bool $hlsSplitDiscontinuity): self
{
$new = clone $this;
$new->hlsSplitDiscontinuity = $hlsSplitDiscontinuity;

return $new;
}

/**
* Pass args for a single extractor.
*
* @see https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#extractor-arguments
*
* @param non-empty-string $extractor
*/
public function extractorArgs(string $extractor, string $args): self
{
$new = clone $this;
$new->extractorArgs[$extractor] = $args;

return $new;
}

/**
* Pass args for all extractors.
*
* @see https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#extractor-arguments
*
* @param array<non-empty-string, string> $extractorArgs
*/
public function extractorsArgs(array $extractorArgs): self
{
$new = clone $this;
$new->extractorArgs = $extractorArgs;

return $new;
}

/**
* @param non-empty-string $url
* @param non-empty-string ...$urls
Expand Down Expand Up @@ -1825,6 +1900,12 @@ public function toArray(): array
'exec' => $this->exec,
'convert-subs-format' => $this->convertSubsFormat,
'force-keyframes-at-cuts' => $this->forceKeyframesAtCuts,
// Extractor Options
'extractor-retries' => $this->extractorRetries,
'allow-dynamic-mpd' => $this->allowDynamicMpd,
'hls-split-discontinuity' => $this->hlsSplitDiscontinuity,
'extractor-args' => $this->extractorArgs,

'url' => $this->url,
];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Process/ArgvBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public static function build(Options $options): array
if (count($value) > 0) {
$cmd[] = sprintf('--%s=%s', $option, implode(',', $value));
}
} elseif ($option === 'add-header') {
foreach ($value as $header => $headerValue) {
$cmd[] = sprintf('--%s=%s:%s', $option, $header, $headerValue);
} elseif ($option === 'add-header' || $option === 'extractor-args') {
foreach ($value as $key => $v) {
$cmd[] = sprintf('--%s=%s:%s', $option, $key, $v);
}
} else {
foreach ($value as $v) {
Expand Down
10 changes: 8 additions & 2 deletions tests/Process/ArgvBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public function testFluentBuild(): void
->headers([
'Accept' => 'text/html',
])
->header('User-Agent', 'youtube-downloader')
->header('User-Agent', 'yt-dlp')
->yesPlaylist()
->playlistItems(['1-3', '7', '10-13'])
->dateBefore(new DateTimeImmutable('2020-08-31'))
->dateAfter(new DateTimeImmutable('2020-08-01'))
->extractorsArgs([
'youtube' => 'player-client=mediaconnect,web;formats=incomplete',
])
->extractorArgs('funimation', 'version=uncut')
->url(
'https://www.youtube.com/watch?v=-FZ-pPFAjYY',
'https://www.youtube.com/watch?v=Q-g_YNZ90tI',
Expand All @@ -39,7 +43,9 @@ public function testFluentBuild(): void
'--yes-playlist',
'--output=/path/to/downloads/%(title)s-%(id)s.%(ext)s',
'--add-header=Accept:text/html',
'--add-header=User-Agent:youtube-downloader',
'--add-header=User-Agent:yt-dlp',
'--extractor-args=youtube:player-client=mediaconnect,web;formats=incomplete',
'--extractor-args=funimation:version=uncut',
'https://www.youtube.com/watch?v=-FZ-pPFAjYY',
'https://www.youtube.com/watch?v=Q-g_YNZ90tI',
], ArgvBuilder::build($options));
Expand Down

0 comments on commit 177195a

Please sign in to comment.