From d31f0b30481f6180e7907aee27413e5d208539aa Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 7 Jun 2020 18:45:22 +0300 Subject: Playlists "at next" order --- src/client/players/Iframe.hx | 7 +++---- src/client/players/Raw.hx | 9 ++++++--- src/client/players/Youtube.hx | 32 ++++++++++++++++++++------------ 3 files changed, 29 insertions(+), 19 deletions(-) (limited to 'src/client/players') diff --git a/src/client/players/Iframe.hx b/src/client/players/Iframe.hx index 2f875fb..ae37c94 100644 --- a/src/client/players/Iframe.hx +++ b/src/client/players/Iframe.hx @@ -1,10 +1,9 @@ package client.players; -import haxe.Timer; import js.html.Element; -import js.html.VideoElement; import js.Browser.document; import client.Main.ge; +import Types.VideoDataRequest; import Types.VideoData; import Types.VideoItem; @@ -24,9 +23,9 @@ class Iframe implements IPlayer { return true; } - public function getVideoData(data:String, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { final iframe = document.createDivElement(); - iframe.innerHTML = data; + iframe.innerHTML = data.url; if (isValidIframe(iframe)) { callback({duration: 99 * 60 * 60}); } else { diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx index 57dd9b3..9a9d52e 100644 --- a/src/client/players/Raw.hx +++ b/src/client/players/Raw.hx @@ -6,6 +6,7 @@ import js.html.Element; import js.html.VideoElement; import js.Browser.document; import client.Main.ge; +import Types.VideoDataRequest; import Types.VideoData; import Types.VideoItem; using StringTools; @@ -30,7 +31,8 @@ class Raw implements IPlayer { return true; } - public function getVideoData(url:String, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + final url = data.url; final decodedUrl = url.urlDecode(); var title = decodedUrl.substr(decodedUrl.lastIndexOf("/") + 1); final isNameMatched = matchName.match(title); @@ -40,7 +42,7 @@ class Raw implements IPlayer { if (isNameMatched) { isHls = matchName.matched(2).contains("m3u8"); if (isHls && !isHlsLoaded) { - loadHlsPlugin(() -> getVideoData(url, callback)); + loadHlsPlugin(() -> getVideoData(data, callback)); return; } } @@ -63,7 +65,8 @@ class Raw implements IPlayer { } function loadHlsPlugin(callback:()->Void):Void { - JsApi.addScriptToHead("https://cdn.jsdelivr.net/npm/hls.js@latest", () -> { + final url = "https://cdn.jsdelivr.net/npm/hls.js@latest"; + JsApi.addScriptToHead(url, () -> { isHlsLoaded = true; callback(); }); diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx index f5f12a0..45f74dd 100644 --- a/src/client/players/Youtube.hx +++ b/src/client/players/Youtube.hx @@ -7,6 +7,7 @@ import js.Browser.document; import client.Main.ge; import js.youtube.Youtube as YtInit; import js.youtube.YoutubePlayer; +import Types.VideoDataRequest; import Types.VideoData; import Types.VideoItem; using StringTools; @@ -72,17 +73,18 @@ class Youtube implements IPlayer { return total; } - public function getVideoData(url:String, callback:(data:VideoData)->Void):Void { + public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + final url = data.url; if (apiKey == null) apiKey = main.getYoutubeApiKey(); - var id = extractVideoId(url); + final id = extractVideoId(url); if (id == "") { - getPlaylistVideoData(url, callback); + getPlaylistVideoData(data, callback); return; } final dataUrl = '$videosUrl$urlTitleDuration&id=$id&key=$apiKey'; final http = new Http(dataUrl); - http.onData = data -> { - final json = Json.parse(data); + http.onData = text -> { + final json = Json.parse(text); if (json.error != null) { youtubeApiError(json.error); getRemoteDataFallback(url, callback); @@ -103,11 +105,11 @@ class Youtube implements IPlayer { duration: 99 * 60 * 60, title: title, url: '', + allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" + allowfullscreen>', isIframe: true }); - return; + continue; } callback({ duration: duration, @@ -120,12 +122,13 @@ class Youtube implements IPlayer { http.request(); } - function getPlaylistVideoData(url:String, callback:(data:VideoData)->Void):Void { + function getPlaylistVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { + final url = data.url; final id = extractPlaylistId(url); final dataUrl = '$playlistUrl$urlVideoId&maxResults=50&playlistId=$id&key=$apiKey'; final http = new Http(dataUrl); - http.onData = data -> { - final json = Json.parse(data); + http.onData = text -> { + final json = Json.parse(text); if (json.error != null) { youtubeApiError(json.error); callback({duration: 0}); @@ -136,10 +139,15 @@ class Youtube implements IPlayer { callback({duration: 0}); return; } + if (!data.atEnd) main.sortItemsForQueueNext(items); function loadNextItem():Void { final item = items.shift(); final id:String = item.snippet.resourceId.videoId; - getVideoData('youtu.be/$id', data -> { + final obj = { + url: 'https://youtu.be/$id', + atEnd: data.atEnd + }; + getVideoData(obj, data -> { callback(data); if (items.length > 0) loadNextItem(); }); -- cgit v1.2.3