From 34f50a628249cccfd746d05a3ff1bfaaba0efd0b Mon Sep 17 00:00:00 2001 From: RblSb Date: Fri, 20 Aug 2021 15:08:35 +0300 Subject: Fix subs for linux chrome With trackEl.srclang = "en" --- src/client/Main.hx | 2 +- src/client/players/RawSubs.hx | 25 ++++++++++++++++++++----- src/client/players/Youtube.hx | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src/client') diff --git a/src/client/Main.hx b/src/client/Main.hx index 28fefe8..bfbe97e 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -692,7 +692,7 @@ class Main { ws.send(Json.stringify(data)); } - public function serverMessage(type:Int, ?text:String, isText = true):Void { + public static function serverMessage(type:Int, ?text:String, isText = true):Void { final msgBuf = ge("#messagebuffer"); final div = document.createDivElement(); final time = Date.now().toString().split(" ")[1]; diff --git a/src/client/players/RawSubs.hx b/src/client/players/RawSubs.hx index aa77bf8..eede788 100644 --- a/src/client/players/RawSubs.hx +++ b/src/client/players/RawSubs.hx @@ -5,6 +5,7 @@ import haxe.crypto.Base64; import haxe.io.Bytes; import js.Browser.document; import js.Browser.window; +import js.Browser; import js.html.VideoElement; using StringTools; @@ -24,6 +25,8 @@ class RawSubs { if (JsApi.hasSubtitleSupport(ext)) return; var url = encodeURI(item.subs); if (!url.startsWith("/")) { + final protocol = Browser.location.protocol; + if (!url.startsWith("http")) url = '$protocol//$url'; url = '/proxy?url=$url'; } @@ -42,6 +45,7 @@ class RawSubs { window.fetch(url).then(response -> { return response.text(); }).then(text -> { + if (isProxyError(text)) return; final subs:Array<{ counter:String, time:String, @@ -76,6 +80,7 @@ class RawSubs { window.fetch(url).then(response -> { return response.text(); }).then(text -> { + if (isProxyError(text)) return; final subs:Array<{ counter:Int, start:String, @@ -142,7 +147,6 @@ class RawSubs { data += '${sub.start} --> ${sub.end}\n'; data += '${sub.text}\n\n'; } - // trace(data); final textBase64 = "data:text/plain;base64,"; final url = textBase64 + Base64.encode(Bytes.ofString(data)); onParsed(video, "ASS subtitles", url); @@ -173,19 +177,30 @@ class RawSubs { } static function parseVtt(video:VideoElement, url:String):Void { - window.fetch(url).then(response -> response.text()).then(data -> { + window.fetch(url).then(response -> response.text()).then(text -> { + if (isProxyError(text)) return; final textBase64 = "data:text/plain;base64,"; - final url = textBase64 + Base64.encode(Bytes.ofString(data)); + final url = textBase64 + Base64.encode(Bytes.ofString(text)); onParsed(video, "VTT subtitles", url); }); } + static function isProxyError(text:String):Bool { + if (text.startsWith("Proxy error:")) { + Main.serverMessage(4, 'Failed to add subs: proxy error'); + trace('Failed to add subs: $text'); + return true; + } + return false; + } + static function onParsed(video:VideoElement, name:String, dataUrl:String) { final trackEl = document.createTrackElement(); + trackEl.kind = "captions"; trackEl.label = name; - trackEl.kind = "subtitles"; + trackEl.srclang = "en"; trackEl.src = dataUrl; - trackEl.default_ = true; + // trackEl.default_ = true; video.appendChild(trackEl); final track = trackEl.track; track.mode = SHOWING; diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx index d4db8ed..23b2439 100644 --- a/src/client/players/Youtube.hx +++ b/src/client/players/Youtube.hx @@ -171,7 +171,7 @@ class Youtube implements IPlayer { function youtubeApiError(error:Dynamic):Void { final code:Int = error.code; final msg:String = error.message; - main.serverMessage(4, 'Error $code: $msg', false); + Main.serverMessage(4, 'Error $code: $msg', false); } function getRemoteDataFallback(url:String, callback:(data:VideoData) -> Void):Void { -- cgit v1.2.3