aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2021-02-14 06:46:05 +0300
committerRblSb <msrblsb@gmail.com>2021-02-14 06:46:05 +0300
commit600156045aa6f93c79fd57ee4e76d588b3f734e6 (patch)
tree85f1910e202091a2c446e21a4f938214c66b311c /src
parent5b4d9c6257f7563ef685ab383037906355fbf054 (diff)
Subtitles url input
Can be enabled by plugins
Diffstat (limited to 'src')
-rw-r--r--src/Types.hx2
-rw-r--r--src/client/Buttons.hx8
-rw-r--r--src/client/JsApi.hx15
-rw-r--r--src/client/Main.hx4
-rw-r--r--src/client/Player.hx1
-rw-r--r--src/client/players/Raw.hx9
6 files changed, 34 insertions, 5 deletions
diff --git a/src/Types.hx b/src/Types.hx
index 02a2cee..519ac76 100644
--- a/src/Types.hx
+++ b/src/Types.hx
@@ -11,6 +11,7 @@ typedef VideoData = {
duration:Float,
?title:String,
?url:String,
+ ?subs:String,
?isIframe:Bool
}
@@ -90,6 +91,7 @@ typedef VideoItem = {
title:String,
author:String,
duration:Float,
+ ?subs:String,
isTemp:Bool,
isIframe:Bool
}
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx
index 538aaa0..8ed259a 100644
--- a/src/client/Buttons.hx
+++ b/src/client/Buttons.hx
@@ -154,10 +154,10 @@ class Buttons {
final mediaUrl:InputElement = cast ge("#mediaurl");
mediaUrl.oninput = () -> {
final value = mediaUrl.value;
- if (value != "" && main.isRawPlayerLink(value) && main.isSingleVideoLink(value)) {
- ge("#mediatitleblock").style.display = "";
- } else {
- ge("#mediatitleblock").style.display = "none";
+ final isRawSingleVideo = value != "" && main.isRawPlayerLink(value) && main.isSingleVideoLink(value);
+ ge("#mediatitleblock").style.display = isRawSingleVideo ? "" : "none";
+ if (JsApi.hasSubtitleSupport()) {
+ ge("#subsurlblock").style.display = isRawSingleVideo ? "" : "none";
}
}
mediaUrl.onfocus = mediaUrl.oninput;
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx
index b0938f8..b97c0f0 100644
--- a/src/client/JsApi.hx
+++ b/src/client/JsApi.hx
@@ -6,6 +6,7 @@ import Types.VideoItem;
import js.Browser.document;
import js.Browser.window;
import js.Syntax;
+using StringTools;
private typedef VideoChangeFunc = (item:VideoItem)->Void;
private typedef OnceEventFunc = (event:WsEvent)->Void;
@@ -14,6 +15,7 @@ class JsApi {
static var main:Main;
static var player:Player;
+ static final subtitleFormats = [];
static final videoChange:Array<VideoChangeFunc> = [];
static final videoRemove:Array<VideoChangeFunc> = [];
static final onceListeners:Array<{type:WsEventType, func:OnceEventFunc}> = [];
@@ -101,6 +103,19 @@ class JsApi {
}
@:expose
+ static function addSubtitleSupport(format:String):Void {
+ format = format.trim().toLowerCase();
+ if (subtitleFormats.contains(format)) return;
+ subtitleFormats.push(format);
+ }
+
+ @:expose
+ public static function hasSubtitleSupport(?format:String):Bool {
+ if (format == null) return subtitleFormats.length > 0;
+ return subtitleFormats.contains(format);
+ }
+
+ @:expose
public static function once(type:WsEventType, func:OnceEventFunc):Void {
onceListeners.push({type: type, func: func});
}
diff --git a/src/client/Main.hx b/src/client/Main.hx
index 78b3504..b9c9892 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -150,6 +150,9 @@ class Main {
ge("#mediatitle").onkeydown = (e:KeyboardEvent) -> {
if (e.keyCode == KeyCode.Return) addVideoUrl(true);
}
+ ge("#subsurl").onkeydown = (e:KeyboardEvent) -> {
+ if (e.keyCode == KeyCode.Return) addVideoUrl(true);
+ }
ge("#ce_queue_next").onclick = e -> addIframe(false);
ge("#ce_queue_end").onclick = e -> addIframe(true);
@@ -267,6 +270,7 @@ class Main {
author: personal.name,
duration: data.duration,
isTemp: isTemp,
+ subs: data.subs,
isIframe: data.isIframe == true
},
atEnd: atEnd
diff --git a/src/client/Player.hx b/src/client/Player.hx
index 9ee3ead..735f73c 100644
--- a/src/client/Player.hx
+++ b/src/client/Player.hx
@@ -142,6 +142,7 @@ class Player {
title: item.title,
author: item.author,
duration: item.duration,
+ subs: item.subs,
isTemp: item.isTemp,
isIframe: item.isIframe
});
diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx
index 2b1530d..cafe147 100644
--- a/src/client/players/Raw.hx
+++ b/src/client/players/Raw.hx
@@ -18,6 +18,7 @@ class Raw implements IPlayer {
final player:Player;
final playerEl:Element = ge("#ytapiplayer");
final titleInput:InputElement = cast ge("#mediatitle");
+ final subsInput:InputElement = cast ge("#subsurl");
final matchName = ~/^(.+)\.(.+)/;
var controlsHider:Timer;
var playAllowed = true;
@@ -53,6 +54,11 @@ class Raw implements IPlayer {
}
titleInput.value = "";
+ var subs = "";
+ if (JsApi.hasSubtitleSupport()) {
+ subs = subsInput.value.trim();
+ subsInput.value = "";
+ }
final video = document.createVideoElement();
video.src = url;
video.onerror = e -> {
@@ -63,7 +69,8 @@ class Raw implements IPlayer {
if (playerEl.contains(video)) playerEl.removeChild(video);
callback({
duration: video.duration,
- title: title
+ title: title,
+ subs: subs
});
}
Utils.prepend(playerEl, video);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage