aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Main.hx3
-rw-r--r--src/client/Player.hx37
-rw-r--r--src/client/players/Youtube.hx2
3 files changed, 40 insertions, 2 deletions
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