Skip to content

Commit

Permalink
[fix/ISSUE-68] Treat missing format key as empty array instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
azihassan committed May 2, 2024
1 parent 71ef384 commit 064f46e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/parsers.d
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ abstract class YoutubeVideoURLExtractor

private YoutubeFormat[] getFormats(string formatKey)
{
auto streamingData = html.matchOrFail!`"streamingData":(.*?),"player`;
string streamingData = html.matchOrFail!`"streamingData":(.*?),"player`;
auto json = streamingData.parseJSON();
if(formatKey !in json)
{
return [];
}
YoutubeFormat[] formats;
foreach(format; json[formatKey].array)
{
Expand Down Expand Up @@ -334,6 +338,10 @@ unittest
assert(formats[20] == YoutubeFormat(249, 1232413, "tiny", `audio/webm; codecs="opus"`, [AudioVisual.AUDIO]));
assert(formats[21] == YoutubeFormat(250, 1630086, "tiny", `audio/webm; codecs="opus"`, [AudioVisual.AUDIO]));
assert(formats[22] == YoutubeFormat(251, 3437753, "tiny", `audio/webm; codecs="opus"`, [AudioVisual.AUDIO]));

html = readText("tests/dQ-adaptiveFormats-only.html");
extractor = new AdvancedYoutubeVideoURLExtractor(html, "", new StdoutLogger());
assert(!extractor.getFormats().canFind!(f => f.itag == 18));
}


Expand Down
77 changes: 77 additions & 0 deletions tests/dQ-adaptiveFormats-only.html

Large diffs are not rendered by default.

0 comments on commit 064f46e

Please sign in to comment.