Skip to content

Commit c734c2b

Browse files
authored
Merge pull request #246 from norkunas/extractor-args
Add extractor options
2 parents c0ef03a + 177195a commit c734c2b

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

src/Options.php

+81
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ class Options
230230
private ?string $convertSubsFormat = null;
231231
private bool $forceKeyframesAtCuts = false;
232232

233+
// Extractor Options
234+
/**
235+
* @var int|'infinite'|null
236+
*/
237+
private $extractorRetries;
238+
private bool $allowDynamicMpd = false;
239+
private bool $hlsSplitDiscontinuity = false;
240+
/**
241+
* @var array<non-empty-string, string>
242+
*/
243+
private array $extractorArgs = [];
244+
233245
/**
234246
* @var list<non-empty-string>
235247
*/
@@ -1666,6 +1678,69 @@ public function convertSubsFormat(?string $subsFormat): self
16661678
return $new;
16671679
}
16681680

1681+
/**
1682+
* @param int|'infinite'|null $retries
1683+
*/
1684+
public function extractorRetries($retries): self
1685+
{
1686+
$new = clone $this;
1687+
$new->extractorRetries = $retries;
1688+
1689+
return $new;
1690+
}
1691+
1692+
/**
1693+
* Process dynamic DASH manifests.
1694+
*/
1695+
public function allowDynamicMpd(bool $allowDynamicMpd): self
1696+
{
1697+
$new = clone $this;
1698+
$new->allowDynamicMpd = $allowDynamicMpd;
1699+
1700+
return $new;
1701+
}
1702+
1703+
/**
1704+
* Split HLS playlists to different formats at discontinuities such as ad breaks.
1705+
*/
1706+
public function hlsSplitDiscontinuity(bool $hlsSplitDiscontinuity): self
1707+
{
1708+
$new = clone $this;
1709+
$new->hlsSplitDiscontinuity = $hlsSplitDiscontinuity;
1710+
1711+
return $new;
1712+
}
1713+
1714+
/**
1715+
* Pass args for a single extractor.
1716+
*
1717+
* @see https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#extractor-arguments
1718+
*
1719+
* @param non-empty-string $extractor
1720+
*/
1721+
public function extractorArgs(string $extractor, string $args): self
1722+
{
1723+
$new = clone $this;
1724+
$new->extractorArgs[$extractor] = $args;
1725+
1726+
return $new;
1727+
}
1728+
1729+
/**
1730+
* Pass args for all extractors.
1731+
*
1732+
* @see https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#extractor-arguments
1733+
*
1734+
* @param array<non-empty-string, string> $extractorArgs
1735+
*/
1736+
public function extractorsArgs(array $extractorArgs): self
1737+
{
1738+
$new = clone $this;
1739+
$new->extractorArgs = $extractorArgs;
1740+
1741+
return $new;
1742+
}
1743+
16691744
/**
16701745
* @param non-empty-string $url
16711746
* @param non-empty-string ...$urls
@@ -1825,6 +1900,12 @@ public function toArray(): array
18251900
'exec' => $this->exec,
18261901
'convert-subs-format' => $this->convertSubsFormat,
18271902
'force-keyframes-at-cuts' => $this->forceKeyframesAtCuts,
1903+
// Extractor Options
1904+
'extractor-retries' => $this->extractorRetries,
1905+
'allow-dynamic-mpd' => $this->allowDynamicMpd,
1906+
'hls-split-discontinuity' => $this->hlsSplitDiscontinuity,
1907+
'extractor-args' => $this->extractorArgs,
1908+
18281909
'url' => $this->url,
18291910
];
18301911
}

src/Process/ArgvBuilder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public static function build(Options $options): array
3333
if (count($value) > 0) {
3434
$cmd[] = sprintf('--%s=%s', $option, implode(',', $value));
3535
}
36-
} elseif ($option === 'add-header') {
37-
foreach ($value as $header => $headerValue) {
38-
$cmd[] = sprintf('--%s=%s:%s', $option, $header, $headerValue);
36+
} elseif ($option === 'add-header' || $option === 'extractor-args') {
37+
foreach ($value as $key => $v) {
38+
$cmd[] = sprintf('--%s=%s:%s', $option, $key, $v);
3939
}
4040
} else {
4141
foreach ($value as $v) {

tests/Process/ArgvBuilderTest.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ public function testFluentBuild(): void
2020
->headers([
2121
'Accept' => 'text/html',
2222
])
23-
->header('User-Agent', 'youtube-downloader')
23+
->header('User-Agent', 'yt-dlp')
2424
->yesPlaylist()
2525
->playlistItems(['1-3', '7', '10-13'])
2626
->dateBefore(new DateTimeImmutable('2020-08-31'))
2727
->dateAfter(new DateTimeImmutable('2020-08-01'))
28+
->extractorsArgs([
29+
'youtube' => 'player-client=mediaconnect,web;formats=incomplete',
30+
])
31+
->extractorArgs('funimation', 'version=uncut')
2832
->url(
2933
'https://www.youtube.com/watch?v=-FZ-pPFAjYY',
3034
'https://www.youtube.com/watch?v=Q-g_YNZ90tI',
@@ -39,7 +43,9 @@ public function testFluentBuild(): void
3943
'--yes-playlist',
4044
'--output=/path/to/downloads/%(title)s-%(id)s.%(ext)s',
4145
'--add-header=Accept:text/html',
42-
'--add-header=User-Agent:youtube-downloader',
46+
'--add-header=User-Agent:yt-dlp',
47+
'--extractor-args=youtube:player-client=mediaconnect,web;formats=incomplete',
48+
'--extractor-args=funimation:version=uncut',
4349
'https://www.youtube.com/watch?v=-FZ-pPFAjYY',
4450
'https://www.youtube.com/watch?v=Q-g_YNZ90tI',
4551
], ArgvBuilder::build($options));

0 commit comments

Comments
 (0)