aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/Main.hx2
-rw-r--r--src/client/players/RawSubs.hx25
-rw-r--r--src/client/players/Youtube.hx2
-rw-r--r--src/server/HttpServer.hx6
4 files changed, 25 insertions, 10 deletions
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 {
diff --git a/src/server/HttpServer.hx b/src/server/HttpServer.hx
index 1198ca1..0edf4e3 100644
--- a/src/server/HttpServer.hx
+++ b/src/server/HttpServer.hx
@@ -74,7 +74,7 @@ class HttpServer {
}
if (url.startsWith("/proxy")) {
- if (!proxyUrl(req, res)) res.end('Cannot proxy ${req.url}');
+ if (!proxyUrl(req, res)) res.end('Proxy error: ${req.url}');
return;
}
@@ -167,7 +167,7 @@ class HttpServer {
if (url == null) return false;
final proxy2 = proxyRequest(url, req, res, proxyReq -> false);
if (proxy2 == null) {
- res.end('Proxy error for redirected $url');
+ res.end('Proxy error: multiple redirects for url $url');
return true;
}
req.pipe(proxy2, {end: true});
@@ -200,7 +200,7 @@ class HttpServer {
proxyReq.pipe(res, {end: true});
});
proxy.on("error", err -> {
- res.end('Proxy error for ${url.href}');
+ res.end('Proxy error: ${url.href}');
});
return proxy;
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage