From c677e281d3d74d5925e19eb0479c27f46a3c7857 Mon Sep 17 00:00:00 2001 From: RblSb Date: Thu, 5 Jan 2023 06:17:55 +0300 Subject: Add /ad command for skipping youtube sponsored blocks --- res/client.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'res') 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; -- cgit v1.2.3