From 558b9d5de3d20e43714787eecc20e2886ead8c6c Mon Sep 17 00:00:00 2001 From: Azi Hassan Date: Sat, 27 Jan 2024 21:48:54 +0100 Subject: [PATCH 1/2] [feature/ISSUE-53] Download HTML and JS resources with gzip encoding --- source/cache.d | 26 ++++++++++++++++++++++++-- source/parsers.d | 2 -- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/source/cache.d b/source/cache.d index 8be075e..1e42e7b 100644 --- a/source/cache.d +++ b/source/cache.d @@ -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; @@ -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) diff --git a/source/parsers.d b/source/parsers.d index 121265a..0e2c869 100644 --- a/source/parsers.d +++ b/source/parsers.d @@ -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()); From 958a85501e55a64e2b830c39377a17c79e4ad079 Mon Sep 17 00:00:00 2001 From: Azi Hassan Date: Sat, 27 Jan 2024 21:54:56 +0100 Subject: [PATCH 2/2] [feature/ISSUE-53] Add missing -d flag to windows tests --- tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.ps1 b/tests.ps1 index 22f482a..31fbd26 100644 --- a/tests.ps1 +++ b/tests.ps1 @@ -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"