Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-53] Download gzipped assets #54

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions source/cache.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import std.base64 : Base64URL;
import std.conv : to;
import std.datetime : SysTime, Clock, days;
import std.file : exists, getcwd, readText, remove, tempDir, write;
import std.net.curl : get;
import std.net.curl : Curl, CurlOption;
import std.path : buildPath;
import std.typecons : Flag, Yes, No;
import std.string : indexOf;
import std.regex : ctRegex, matchFirst;
import std.algorithm : map;

import helpers : StdoutLogger, parseID, parseQueryString, parseBaseJSKey;
import parsers : parseBaseJSURL, YoutubeVideoURLExtractor, SimpleYoutubeVideoURLExtractor, AdvancedYoutubeVideoURLExtractor;
Expand All @@ -23,9 +24,30 @@ struct Cache
this(StdoutLogger logger, Flag!"forceRefresh" forceRefresh = No.forceRefresh)
{
this.logger = logger;
downloadAsString = (string url) => url.get().idup;
this.forceRefresh = forceRefresh;
cacheDirectory = tempDir();

downloadAsString = (string url) {
string result;
Curl curl;
curl.initialize();
curl.set(CurlOption.url, url);
curl.set(CurlOption.encoding, "deflate, gzip");

curl.onReceive = (ubyte[] chunk) {
result ~= chunk.map!(to!(const(char))).to!string;
return chunk.length;
};

curl.onReceiveHeader = (in char[] header) {
if(header.indexOf("Content-Length", No.caseSensitive) == 0)
{
logger.displayVerbose("Length of " ~ url ~ " : " ~ header["Content-Length: ".length .. $]);
}
};
curl.perform();
return result;
};
}

this(StdoutLogger logger, string delegate(string url) downloadAsString, Flag!"forceRefresh" forceRefresh = No.forceRefresh)
Expand Down
2 changes: 0 additions & 2 deletions source/parsers.d
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ struct ThrottlingAlgorithm
try
{
string implementation = format!`var descramble = function(a) { %s return b.join("")};`(findChallengeImplementation());
logger.displayVerbose("Challenge implementation :");
logger.displayVerbose(implementation);
duk_peval_string(context, implementation.toStringz());
duk_get_global_string(context, "descramble");
duk_push_string(context, n.toStringz());
Expand Down
2 changes: 1 addition & 1 deletion tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
& ".\youtube-d.exe" -p --no-progress https://www.youtube.com/watch?v=R85MK830mMo
& ".\youtube-d.exe" -p -d --no-progress https://www.youtube.com/watch?v=R85MK830mMo

$filename = "Debugging Github actions-R85MK830mMo-18.mp4"

Expand Down
Loading