From 959f22173bba873808b614bf1172f0ec03067824 Mon Sep 17 00:00:00 2001 From: faissaloo Date: Wed, 11 Aug 2021 17:44:08 +0100 Subject: [PATCH] Default to HTTPS --- src/sponskrub/sponskrub.d | 13 +++++++++++-- src/sponskrub/sponsorblock.d | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/sponskrub/sponskrub.d b/src/sponskrub/sponskrub.d index 55beb44..a7da079 100644 --- a/src/sponskrub/sponskrub.d +++ b/src/sponskrub/sponskrub.d @@ -49,6 +49,7 @@ int main(string[] args) new ArgTemplate("include-selfpromo", true), new ArgTemplate("include-nonmusic", true), new ArgTemplate("no-id", true), + new ArgTemplate("force-http", true), new ArgTemplate("keep-date", true), new ArgTemplate("api-url", true, false, 1), new ArgTemplate("proxy", true, false, 1), @@ -113,10 +114,18 @@ Options: -proxy Allows you to specify a proxy to route any requests through + + -force-http + By default sponskrub connects to the API via HTTPS, use this to force HTTP "); return 1; } + bool force_http = false; + if ("force-http" in parsed_arguments.flag_arguments) { + force_http = true; + } + string api_url; if ("api-url" in parsed_arguments.flag_arguments) { api_url = parsed_arguments.flag_arguments["api-url"].join; @@ -151,9 +160,9 @@ Options: } else { try { if ("no-id" in parsed_arguments.flag_arguments) { - sponsor_times = get_video_skip_times_private(video_id, categories, api_url, proxy); + sponsor_times = get_video_skip_times_private(video_id, categories, api_url, proxy, force_http); } else { - sponsor_times = get_video_skip_times_direct(video_id, categories, api_url, proxy); + sponsor_times = get_video_skip_times_direct(video_id, categories, api_url, proxy, force_http); } } catch (std.net.curl.HTTPStatusException e) { if (e.status == 404) { diff --git a/src/sponskrub/sponsorblock.d b/src/sponskrub/sponsorblock.d index c5f1a80..e022316 100644 --- a/src/sponskrub/sponsorblock.d +++ b/src/sponskrub/sponsorblock.d @@ -50,8 +50,12 @@ string stringify_timestamp(JSONValue raw_timestamp) { return "%6f".format(timestamp); } -ClipTime[] get_video_skip_times_direct(string video_id, Categories[] categories, string api_url, string proxy="") { - auto data = proxy_get("http://%s/api/skipSegments?videoID=%s&categories=%s".format(api_url, video_id, `["`~(cast(string[])categories).join(`","`)~`"]`), proxy); +ClipTime[] get_video_skip_times_direct(string video_id, Categories[] categories, string api_url, string proxy="", bool force_http = false) { + auto protocol = "https"; + if (force_http) { + protocol = "http"; + } + auto data = proxy_get("%s://%s/api/skipSegments?videoID=%s&categories=%s".format(protocol, api_url, video_id, `["`~(cast(string[])categories).join(`","`)~`"]`), proxy); auto json = parseJSON(data); //This array needs sorting or whatever so they get lined up properly //Or maybe we should get the thing that figures out the times to do that? @@ -60,8 +64,12 @@ ClipTime[] get_video_skip_times_direct(string video_id, Categories[] categories, ).array; } -ClipTime[] get_video_skip_times_private(string video_id, Categories[] categories, string api_url, string proxy="") { - auto data = proxy_get("http://%s/api/skipSegments/%s?categories=%s".format(api_url, sha256Of(video_id).toHexString!(LetterCase.lower)[0..uniform(3,32)], `["`~(cast(string[])categories).join(`","`)~`"]`), proxy); +ClipTime[] get_video_skip_times_private(string video_id, Categories[] categories, string api_url, string proxy="", bool force_http = false) { + auto protocol = "https"; + if (force_http) { + protocol = "http"; + } + auto data = proxy_get("%s://%s/api/skipSegments/%s?categories=%s".format(protocol, api_url, sha256Of(video_id).toHexString!(LetterCase.lower)[0..uniform(3,32)], `["`~(cast(string[])categories).join(`","`)~`"]`), proxy); auto json = parseJSON(data); foreach (JSONValue video; json.array) { if (video["videoID"].str == video_id) {