aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2023-01-05 06:17:55 +0300
committerRblSb <msrblsb@gmail.com>2023-01-05 06:17:55 +0300
commitc677e281d3d74d5925e19eb0479c27f46a3c7857 (patch)
treee3e7084778b56f393d62d0167105408b231d23ca
parente877f070e367a7a9d93b93bf676f4afdb948356f (diff)
Add /ad command
for skipping youtube sponsored blocks
-rw-r--r--res/client.js41
-rw-r--r--src/client/Main.hx3
-rw-r--r--src/client/Player.hx37
-rw-r--r--src/client/players/Youtube.hx2
4 files changed, 80 insertions, 3 deletions
diff --git a/res/client.js b/res/client.js
index c63a4ef..b5be1ad 100644
--- a/res/client.js
+++ b/res/client.js
@@ -1971,6 +1971,9 @@ client_Main.prototype = {
return false;
}
switch(command) {
+ case "ad":
+ this.player.skipAd();
+ return false;
case "ban":
this.mergeRedundantArgs(args,0,2);
var name = args[0];
@@ -2146,7 +2149,8 @@ var client_Player = function(main) {
this.videoItemsEl = window.document.querySelector("#queue");
this.videoList = new VideoList();
this.main = main;
- this.players = [new client_players_Youtube(main,this)];
+ this.youtube = new client_players_Youtube(main,this);
+ this.players = [this.youtube];
this.iframePlayer = new client_players_Iframe(main,this);
this.rawPlayer = new client_players_Raw(main,this);
this.initItemButtons();
@@ -2580,6 +2584,41 @@ client_Player.prototype = {
this.skipSetRate = isLocal;
this.player.setPlaybackRate(rate);
}
+ ,skipAd: function() {
+ var _gthis = this;
+ var _this = this.videoList;
+ var item = _this.items[_this.pos];
+ if(item == null) {
+ return;
+ }
+ if(!this.youtube.isSupportedLink(item.url)) {
+ return;
+ }
+ var http = new haxe_http_HttpJs("https://sponsor.ajay.app/api/skipSegments?videoID=" + this.youtube.extractVideoId(item.url));
+ http.onData = function(text) {
+ var json;
+ try {
+ json = JSON.parse(text);
+ } catch( _g ) {
+ return;
+ }
+ var _g = 0;
+ while(_g < json.length) {
+ var block = json[_g];
+ ++_g;
+ var start = block.segment[0];
+ var end = block.segment[1];
+ var time = _gthis.getTime();
+ if(time > start - 1 && time < end) {
+ _gthis.main.send({ type : "Rewind", rewind : { time : end - time - 1}});
+ }
+ }
+ };
+ http.onError = function(msg) {
+ haxe_Log.trace(msg,{ fileName : "src/client/Player.hx", lineNumber : 477, className : "client.Player", methodName : "skipAd"});
+ };
+ http.request();
+ }
};
var client_Settings = function() { };
client_Settings.__name__ = true;
diff --git a/src/client/Main.hx b/src/client/Main.hx
index ed63568..e1cb1ef 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -905,6 +905,9 @@ class Main {
case "flashback", "fb":
send({type: Flashback});
return false;
+ case "ad":
+ player.skipAd();
+ return false;
case "dump":
send({type: Dump});
return true;
diff --git a/src/client/Player.hx b/src/client/Player.hx
index 1979091..0227f05 100644
--- a/src/client/Player.hx
+++ b/src/client/Player.hx
@@ -7,6 +7,8 @@ import client.Main.ge;
import client.players.Iframe;
import client.players.Raw;
import client.players.Youtube;
+import haxe.Http;
+import haxe.Json;
import js.html.Element;
using Lambda;
@@ -14,6 +16,7 @@ using StringTools;
class Player {
final main:Main;
+ final youtube:Youtube;
final players:Array<IPlayer>;
final iframePlayer:IPlayer;
final rawPlayer:IPlayer;
@@ -27,8 +30,9 @@ class Player {
public function new(main:Main):Void {
this.main = main;
+ youtube = new Youtube(main, this);
players = [
- new Youtube(main, this)
+ youtube
];
iframePlayer = new Iframe(main, this);
rawPlayer = new Raw(main, this);
@@ -442,4 +446,35 @@ class Player {
skipSetRate = isLocal;
player.setPlaybackRate(rate);
}
+
+ public function skipAd():Void {
+ final item = videoList.getCurrentItem();
+ if (item == null) return;
+ if (!youtube.isSupportedLink(item.url)) return;
+ final id = youtube.extractVideoId(item.url);
+ final url = 'https://sponsor.ajay.app/api/skipSegments?videoID=$id';
+ final http = new Http(url);
+ http.onData = text -> {
+ final json:Array<{segment:Array<Float>}> = try {
+ Json.parse(text);
+ } catch (e) {
+ return;
+ }
+ for (block in json) {
+ final start = block.segment[0];
+ final end = block.segment[1];
+ final time = getTime();
+ if (time > start - 1 && time < end) {
+ main.send({
+ type: Rewind,
+ rewind: {
+ time: end - time - 1
+ }
+ });
+ }
+ }
+ }
+ http.onError = msg -> trace(msg);
+ http.request();
+ }
}
diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx
index ca8d415..9ed5630 100644
--- a/src/client/players/Youtube.hx
+++ b/src/client/players/Youtube.hx
@@ -41,7 +41,7 @@ class Youtube implements IPlayer {
return extractVideoId(url) != "" || extractPlaylistId(url) != "";
}
- function extractVideoId(url:String):String {
+ public function extractVideoId(url:String):String {
if (matchId.match(url)) {
return matchId.matched(1);
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage