aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/players
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-05-01 10:11:40 +0300
committerRblSb <msrblsb@gmail.com>2020-05-01 10:11:40 +0300
commit104d4edeb5c0874412b0e91d0cb3c768995a0ce1 (patch)
tree36c7b72976305a682a8f4e8b96d58a64b130e54f /src/client/players
parent7408555ad16b5d0e380d1d90eb62e64eb14987f1 (diff)
Support youtube streams
Diffstat (limited to 'src/client/players')
-rw-r--r--src/client/players/Iframe.hx23
-rw-r--r--src/client/players/Youtube.hx16
2 files changed, 29 insertions, 10 deletions
diff --git a/src/client/players/Iframe.hx b/src/client/players/Iframe.hx
index 3268a61..2f875fb 100644
--- a/src/client/players/Iframe.hx
+++ b/src/client/players/Iframe.hx
@@ -24,11 +24,20 @@ class Iframe implements IPlayer {
return true;
}
- public function getVideoData(url:String, callback:(data:VideoData)->Void):Void {
- callback({
- duration: 99 * 60 * 60,
- title: "Custom Media"
- });
+ public function getVideoData(data:String, callback:(data:VideoData)->Void):Void {
+ final iframe = document.createDivElement();
+ iframe.innerHTML = data;
+ if (isValidIframe(iframe)) {
+ callback({duration: 99 * 60 * 60});
+ } else {
+ callback({duration: 0});
+ }
+ }
+
+ function isValidIframe(iframe:Element):Bool {
+ if (iframe.children.length != 1) return false;
+ return (iframe.firstChild.nodeName == "IFRAME"
+ || iframe.firstChild.nodeName == "OBJECT");
}
public function loadVideo(item:VideoItem):Void {
@@ -36,9 +45,7 @@ class Iframe implements IPlayer {
video = document.createDivElement();
video.id = "videoplayer";
video.innerHTML = item.url; // actually data
- if (video.firstChild.nodeName != "IFRAME"
- && video.firstChild.nodeName != "OBJECT") {
- // TODO move to getVideoData too
+ if (!isValidIframe(video)) {
video = null;
return;
}
diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx
index 0aa9f2b..f5f12a0 100644
--- a/src/client/players/Youtube.hx
+++ b/src/client/players/Youtube.hx
@@ -96,9 +96,21 @@ class Youtube implements IPlayer {
for (item in items) {
final title:String = item.snippet.title;
final duration:String = item.contentDetails.duration;
- // TODO duration is PT0S for streams
+ final duration = convertTime(duration);
+ // duration is PT0S for streams
+ if (duration == 0) {
+ callback({
+ duration: 99 * 60 * 60,
+ title: title,
+ url: '<iframe src="https://www.youtube.com/embed/$id" frameborder="0"
+ allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
+ allowfullscreen></iframe>',
+ isIframe: true
+ });
+ return;
+ }
callback({
- duration: convertTime(duration),
+ duration: duration,
title: title,
url: url
});
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage