Skip to content

Commit

Permalink
Add -no-id for more privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloo committed Feb 13, 2021
1 parent f0e3514 commit 514821c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/sponskrub/sponskrub.d
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int main(string[] args)
new ArgTemplate("include-interactions", true),
new ArgTemplate("include-selfpromo", true),
new ArgTemplate("include-nonmusic", true),
new ArgTemplate("no-id", true),
new ArgTemplate("api-url", true, false, 1),
]);

Expand Down Expand Up @@ -97,6 +98,11 @@ Options:
-api-url
Specify the url where the API is located, defaults to sponsor.ajay.app
-no-id
Searches for sponsor data by the partial hash of the video id instead of
directly requesting it.
This adds a degree of privacy, but is slightly slower and uses more bandwidth.
");
return 1;
}
Expand Down Expand Up @@ -126,7 +132,11 @@ Options:
return 4;
} else {
try {
sponsor_times = get_video_skip_times(video_id, categories, api_url);
if ("no-id" in parsed_arguments.flag_arguments) {
sponsor_times = get_video_skip_times_private(video_id, categories, api_url);
} else {
sponsor_times = get_video_skip_times_direct(video_id, categories, api_url);
}
} catch (std.net.curl.HTTPStatusException e) {
if (e.status == 404) {
writeln("This video has no ad information available, either it has no ads or no one has logged any on SponsorBlock yet.");
Expand Down
20 changes: 19 additions & 1 deletion src/sponskrub/sponsorblock.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import std.string;
import std.array;
import std.conv;
import std.stdio;
import std.digest.sha;
import std.random;

enum Categories: string {
Sponsor = "sponsor",
Expand All @@ -48,7 +50,7 @@ string stringify_timestamp(JSONValue raw_timestamp) {
return "%6f".format(timestamp);
}

ClipTime[] get_video_skip_times(string video_id, Categories[] categories, string api_url) {
ClipTime[] get_video_skip_times_direct(string video_id, Categories[] categories, string api_url) {
auto data = get("http://%s/api/skipSegments?videoID=%s&categories=%s".format(api_url, video_id, `["`~(cast(string[])categories).join(`", "`)~`"]`));
auto json = parseJSON(data);
//This array needs sorting or whatever so they get lined up properly
Expand All @@ -57,3 +59,19 @@ ClipTime[] get_video_skip_times(string video_id, Categories[] categories, string
clip_times => ClipTime(stringify_timestamp(clip_times["segment"][0]), stringify_timestamp(clip_times["segment"][1]), clip_times["category"].str)
).array;
}

ClipTime[] get_video_skip_times_private(string video_id, Categories[] categories, string api_url) {
auto data = get("http://%s/api/skipSegments/%s?categories=%s".format(api_url, sha256Of(video_id).toHexString!()[0..uniform(3,32)], `["`~(cast(string[])categories).join(`", "`)~`"]`));
auto json = parseJSON(data);
foreach (JSONValue video; json.array) {
if (video["videoID"].str == video_id) {
return video["segments"].array.map!(
clip_times => ClipTime(stringify_timestamp(clip_times["segment"][0]), stringify_timestamp(clip_times["segment"][1]), clip_times["category"].str)
).array;
} else {
writeln("VIDEO ID WAS: ");
writeln(video["videoID"]);
}
}
return null;
}

0 comments on commit 514821c

Please sign in to comment.