aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/players/Youtube.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/players/Youtube.hx')
-rw-r--r--src/client/players/Youtube.hx55
1 files changed, 15 insertions, 40 deletions
diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx
index 3ad9030..5a8921a 100644
--- a/src/client/players/Youtube.hx
+++ b/src/client/players/Youtube.hx
@@ -1,5 +1,6 @@
package client.players;
+import Types.PlayerType;
import Types.VideoData;
import Types.VideoDataRequest;
import Types.VideoItem;
@@ -23,7 +24,6 @@ class Youtube implements IPlayer {
var apiKey:String;
var video:Element;
var youtube:YoutubePlayer;
- var tempYoutube:YoutubePlayer;
var isLoaded = false;
public function new(main:Main, player:Player) {
@@ -31,6 +31,10 @@ class Youtube implements IPlayer {
this.player = player;
}
+ public function getPlayerType():PlayerType {
+ return YoutubeType;
+ }
+
public function isSupportedLink(url:String):Bool {
return extractVideoId(url) != "" || extractPlaylistId(url) != "";
}
@@ -43,6 +47,10 @@ class Youtube implements IPlayer {
return YoutubeUtils.extractPlaylistId(url);
}
+ public function isPlaylistUrl(url:String):Bool {
+ return extractVideoId(url) == "" && extractPlaylistId(url) != "";
+ }
+
final matchHours = ~/([0-9]+)H/;
final matchMinutes = ~/([0-9]+)M/;
final matchSeconds = ~/([0-9]+)S/;
@@ -93,7 +101,7 @@ class Youtube implements IPlayer {
url: '<iframe src="https://www.youtube.com/embed/$id?autoplay=1$mute" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>',
- isIframe: true
+ playerType: IframeType
});
continue;
}
@@ -168,6 +176,7 @@ class Youtube implements IPlayer {
final video = document.createDivElement();
video.id = "temp-videoplayer";
Utils.prepend(playerEl, video);
+ var tempYoutube:YoutubePlayer = null;
tempYoutube = new YoutubePlayer(video.id, {
videoId: extractVideoId(url),
playerVars: {
@@ -181,12 +190,14 @@ class Youtube implements IPlayer {
callback({
duration: tempYoutube.getDuration()
});
+ tempYoutube.destroy();
},
onError: e -> {
// TODO message error codes
trace('Error ${e.data}');
if (playerEl.contains(video)) playerEl.removeChild(video);
callback({duration: 0});
+ tempYoutube.destroy();
}
}
});
@@ -243,49 +254,13 @@ class Youtube implements IPlayer {
onError: e -> {
// TODO message error codes
trace('Error ${e.data}');
- final item = player.getCurrentItem() ?? return;
- rawSourceFallback(item.url);
+ // final item = player.getCurrentItem() ?? return;
+ // rawSourceFallback(item.url);
}
}
});
}
- function rawSourceFallback(url:String):Void {
- JsApi.once(GetYoutubeVideoInfo, event -> {
- final data = event.getYoutubeVideoInfo;
- final info = data.response;
- final format = getBestStreamFormat(info) ?? {
- trace("format not found in response info:");
- trace(info);
- return;
- };
- player.changeVideoSrc(format.url);
- });
- main.send({
- type: GetYoutubeVideoInfo,
- getYoutubeVideoInfo: {
- url: url
- }
- });
- }
-
- function getBestStreamFormat(info:YouTubeVideoInfo):Null<YoutubeVideoFormat> {
- info.formats ??= [];
- info.adaptiveFormats ??= [];
- final formats = info.adaptiveFormats.concat(info.formats);
- trace(formats);
- final qPriority = [1080, 720, 480, 360, 240];
- for (q in qPriority) {
- final quality = '${q}p';
- for (format in formats) {
- if (format.audioQuality == null) continue; // no sound
- if (format.width == null) continue; // no video
- if (format.qualityLabel == quality) return format;
- }
- }
- return null;
- }
-
public function removeVideo():Void {
if (video == null) return;
isLoaded = false;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage