aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/players/Raw.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-02-29 14:01:12 +0300
committerRblSb <msrblsb@gmail.com>2020-02-29 14:01:12 +0300
commit2ade04273717807096a07b6eb132b7677917392d (patch)
tree1598ad62bcb1f3c42b37edb7383df2704005bee5 /src/client/players/Raw.hx
parentec7e4b5ad120828f1464cf4186287d4928b462a8 (diff)
Get youtube video title/duration with api
Diffstat (limited to 'src/client/players/Raw.hx')
-rw-r--r--src/client/players/Raw.hx18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx
index 1e5d245..44a33f2 100644
--- a/src/client/players/Raw.hx
+++ b/src/client/players/Raw.hx
@@ -5,6 +5,7 @@ import js.html.Element;
import js.html.VideoElement;
import js.Browser.document;
import client.Main.ge;
+import Types.VideoData;
import Types.VideoItem;
class Raw implements IPlayer {
@@ -19,17 +20,24 @@ class Raw implements IPlayer {
this.player = player;
}
- public function getRemoteDuration(src:String, callback:(duration:Float)->Void):Void {
+ public function getVideoData(url:String, callback:(data:VideoData)->Void):Void {
+ var title = url.substr(url.lastIndexOf('/') + 1);
+ final matchName = ~/^(.+)\./;
+ if (matchName.match(title)) title = matchName.matched(1);
+ else title = Lang.get("rawVideo");
+
final video = document.createVideoElement();
- video.src = src;
- // TODO catch errors on AddVideo and getRemoteVideoDuration
+ video.src = url;
video.onerror = e -> {
if (playerEl.contains(video)) playerEl.removeChild(video);
- callback(0);
+ callback({duration: 0});
}
video.onloadedmetadata = () -> {
if (playerEl.contains(video)) playerEl.removeChild(video);
- callback(video.duration);
+ callback({
+ duration: video.duration,
+ title: title
+ });
}
Utils.prepend(playerEl, video);
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage