diff options
| author | RblSb <msrblsb@gmail.com> | 2021-08-20 15:08:35 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2021-08-20 15:08:35 +0300 |
| commit | 34f50a628249cccfd746d05a3ff1bfaaba0efd0b (patch) | |
| tree | 4e5c19ab69d1d905c763e46ee77feaa284d91447 /src/client/players | |
| parent | f2d28c726ba46f03716ed37667d0e94c60ad3459 (diff) | |
Fix subs for linux chrome
With trackEl.srclang = "en"
Diffstat (limited to 'src/client/players')
| -rw-r--r-- | src/client/players/RawSubs.hx | 25 | ||||
| -rw-r--r-- | src/client/players/Youtube.hx | 2 |
2 files changed, 21 insertions, 6 deletions
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 { |
