Skip to content

Commit

Permalink
Default to HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloo committed Aug 11, 2021
1 parent 5b9d552 commit 959f221
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/sponskrub/sponskrub.d
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions src/sponskrub/sponsorblock.d
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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) {
Expand Down

0 comments on commit 959f221

Please sign in to comment.