diff options
| author | RblSb <msrblsb@gmail.com> | 2023-01-05 06:17:55 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2023-01-05 06:17:55 +0300 |
| commit | c677e281d3d74d5925e19eb0479c27f46a3c7857 (patch) | |
| tree | e3e7084778b56f393d62d0167105408b231d23ca /src/client/Player.hx | |
| parent | e877f070e367a7a9d93b93bf676f4afdb948356f (diff) | |
Add /ad command
for skipping youtube sponsored blocks
Diffstat (limited to 'src/client/Player.hx')
| -rw-r--r-- | src/client/Player.hx | 37 |
1 files changed, 36 insertions, 1 deletions
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(); + } } |
