diff options
| author | RblSb <msrblsb@gmail.com> | 2021-01-24 13:12:58 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2021-01-24 13:12:58 +0300 |
| commit | 35beab11cdccf09dc77917a795b033314e62a5b1 (patch) | |
| tree | 23134d53f46ac678742f7fc4095b66dd68010617 /src | |
| parent | 3444b413ab12783c85ce73df9931142fea11b749 (diff) | |
Video title input
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/Buttons.hx | 17 | ||||
| -rw-r--r-- | src/client/InputWithHistory.hx | 21 | ||||
| -rw-r--r-- | src/client/Main.hx | 13 | ||||
| -rw-r--r-- | src/client/Player.hx | 4 | ||||
| -rw-r--r-- | src/client/players/Raw.hx | 27 |
5 files changed, 65 insertions, 17 deletions
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index cdc9780..538aaa0 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -8,6 +8,7 @@ import js.html.Element; import client.Main.ge; import js.Browser.window; import js.Browser.document; +using StringTools; class Buttons { @@ -150,10 +151,20 @@ class Buttons { final showCustomEmbed = ge("#showcustomembed"); showCustomEmbed.onclick = e -> showPlayerGroup(showCustomEmbed); + 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"; + } + } + mediaUrl.onfocus = mediaUrl.oninput; + ge("#insert_template").onclick = e -> { - final input:InputElement = cast ge("#mediaurl"); - input.value = main.getTemplateUrl(); - input.focus(); + mediaUrl.value = main.getTemplateUrl(); + mediaUrl.focus(); } final showOptions = ge("#showoptions"); diff --git a/src/client/InputWithHistory.hx b/src/client/InputWithHistory.hx index ecba43a..c4e8bf4 100644 --- a/src/client/InputWithHistory.hx +++ b/src/client/InputWithHistory.hx @@ -29,8 +29,9 @@ class InputWithHistory { } function onKeyDown(e:KeyboardEvent) { - switch (e.keyCode) { - case 13: // Enter + final key:KeyCode = cast e.keyCode; + switch (key) { + case Return: final value = element.value; if (value.length == 0) return; final isAdd = onEnter(value); @@ -38,23 +39,31 @@ class InputWithHistory { if (history.length > maxItems) history.shift(); historyId = -1; element.value = ""; - case 38: // Up + onInput(); + case Up: historyId--; if (historyId == -2) { historyId = history.length - 1; if (historyId == -1) return; } else if (historyId == -1) historyId++; element.value = history[historyId]; - case 40: // Down + onInput(); + case Down: if (historyId == -1) return; historyId++; if (historyId > history.length - 1) { historyId = -1; element.value = ""; - return; + } else { + element.value = history[historyId]; } - element.value = history[historyId]; + onInput(); + default: } } + function onInput():Void { + if (element.oninput != null) element.oninput(); + } + } diff --git a/src/client/Main.hx b/src/client/Main.hx index 5c29d29..31558eb 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -146,6 +146,9 @@ class Main { addVideoUrl(true); return false; }); + ge("#mediatitle").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); @@ -210,6 +213,16 @@ class Main { addVideoArray(links, atEnd, isTemp); } + public function isRawPlayerLink(url:String):Bool { + return player.isRawPlayerLink(url); + } + + public function isSingleVideoLink(url:String):Bool { + if (~/, ?(https?)/g.match(url)) return false; + if (mask.match(url)) return false; + return true; + } + public function sortItemsForQueueNext<T>(items:Array<T>):Void { if (items.length == 0) return; // except first item when list empty diff --git a/src/client/Player.hx b/src/client/Player.hx index 59ca11f..9ee3ead 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -104,6 +104,10 @@ class Player { player.getVideoData(data, callback); } + public function isRawPlayerLink(url:String):Bool { + return !players.exists(player -> player.isSupportedLink(url)); + } + public function getIframeData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { iframePlayer.getVideoData(data, callback); } diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx index 9a9d52e..fdb5e73 100644 --- a/src/client/players/Raw.hx +++ b/src/client/players/Raw.hx @@ -3,6 +3,7 @@ package client.players; import js.hlsjs.Hls; import haxe.Timer; import js.html.Element; +import js.html.InputElement; import js.html.VideoElement; import js.Browser.document; import client.Main.ge; @@ -34,17 +35,20 @@ class Raw implements IPlayer { public function getVideoData(data:VideoDataRequest, callback:(data:VideoData)->Void):Void { final url = data.url; final decodedUrl = url.urlDecode(); + + final optTitle = cutOptionalTitle(); var title = decodedUrl.substr(decodedUrl.lastIndexOf("/") + 1); final isNameMatched = matchName.match(title); - if (isNameMatched) title = matchName.matched(1); + if (optTitle != "") title = optTitle; + else if (isNameMatched) title = matchName.matched(1); else title = Lang.get("rawVideo"); + var isHls = false; - if (isNameMatched) { - isHls = matchName.matched(2).contains("m3u8"); - if (isHls && !isHlsLoaded) { - loadHlsPlugin(() -> getVideoData(data, callback)); - return; - } + if (isNameMatched) isHls = matchName.matched(2).contains("m3u8"); + else isHls = title.endsWith("m3u8"); + if (isHls && !isHlsLoaded) { + loadHlsPlugin(() -> getVideoData(data, callback)); + return; } final video = document.createVideoElement(); @@ -64,6 +68,13 @@ class Raw implements IPlayer { if (isHls) initHlsSource(video, url); } + function cutOptionalTitle():String { + final titleInput:InputElement = cast ge("#mediatitle"); + final optTitle = titleInput.value.trim(); + titleInput.value = ""; + return optTitle; + } + function loadHlsPlugin(callback:()->Void):Void { final url = "https://cdn.jsdelivr.net/npm/hls.js@latest"; JsApi.addScriptToHead(url, () -> { @@ -81,7 +92,7 @@ class Raw implements IPlayer { public function loadVideo(item:VideoItem):Void { final url = main.tryLocalIp(item.url); - final isHls = item.url.contains("m3u8"); + final isHls = item.url.contains("m3u8") || item.title.endsWith("m3u8"); if (isHls && !isHlsLoaded) { loadHlsPlugin(() -> loadVideo(item)); return; |
