aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2023-06-21 20:15:52 +0300
committerRblSb <msrblsb@gmail.com>2023-06-21 20:51:11 +0300
commit452ac109e0a1309ff0e7212de271b2b6d3641353 (patch)
tree492f0afbc1f025fc73607374fc897f2f96074c67
parentc476a16ad982e778580d74b8e4120ed29118129a (diff)
Skip proxy for local subs
-rw-r--r--res/client.js38
-rw-r--r--src/client/players/Raw.hx25
-rw-r--r--src/client/players/RawSubs.hx8
3 files changed, 61 insertions, 10 deletions
diff --git a/res/client.js b/res/client.js
index 830c25c..7c2b695 100644
--- a/res/client.js
+++ b/res/client.js
@@ -3111,7 +3111,35 @@ client_players_Raw.prototype = {
this.initHlsSource(this.video,url);
}
this.restartControlsHider();
- client_players_RawSubs.loadSubs(item,this.video);
+ var subsUrl;
+ var tmp = item.subs;
+ if(tmp != null) {
+ subsUrl = tmp;
+ } else {
+ return;
+ }
+ if(subsUrl.length == 0) {
+ return;
+ }
+ if(StringTools.startsWith(subsUrl,"/")) {
+ client_players_RawSubs.loadSubs(subsUrl,this.video);
+ return;
+ }
+ if(!StringTools.startsWith(subsUrl,"http")) {
+ var protocol = $global.location.protocol;
+ subsUrl = "" + protocol + "//" + subsUrl;
+ }
+ var subsUri;
+ try {
+ subsUri = new URL(subsUrl);
+ } catch( _g ) {
+ client_Main.serverMessage("Failed to add subs: bad url (" + subsUrl + ")");
+ return;
+ }
+ if(subsUri.hostname == this.main.host || subsUri.hostname == this.main.globalIp) {
+ subsUrl = subsUri.pathname;
+ }
+ client_players_RawSubs.loadSubs(subsUrl,this.video);
}
,restartControlsHider: function() {
var _gthis = this;
@@ -3180,15 +3208,15 @@ client_players_Raw.prototype = {
};
var client_players_RawSubs = function() { };
client_players_RawSubs.__name__ = true;
-client_players_RawSubs.loadSubs = function(item,video) {
- if(item.subs == null || item.subs.length == 0) {
+client_players_RawSubs.loadSubs = function(subsUrl,video) {
+ if(subsUrl == null || subsUrl.length == 0) {
return;
}
- var ext = PathTools.urlExtension(item.subs);
+ var ext = PathTools.urlExtension(subsUrl);
if(client_JsApi.hasSubtitleSupport(ext)) {
return;
}
- var url = encodeURI(item.subs);
+ var url = encodeURI(subsUrl);
if(!StringTools.startsWith(url,"/")) {
var protocol = $global.location.protocol;
if(!StringTools.startsWith(url,"http")) {
diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx
index dc3aed5..08025eb 100644
--- a/src/client/players/Raw.hx
+++ b/src/client/players/Raw.hx
@@ -6,9 +6,11 @@ import Types.VideoItem;
import client.Main.ge;
import haxe.Timer;
import js.Browser.document;
+import js.Browser;
import js.hlsjs.Hls;
import js.html.Element;
import js.html.InputElement;
+import js.html.URL;
import js.html.VideoElement;
using StringTools;
@@ -119,7 +121,28 @@ class Raw implements IPlayer {
}
if (isHls) initHlsSource(video, url);
restartControlsHider();
- RawSubs.loadSubs(item, video);
+
+ var subsUrl = item.subs ?? return;
+ if (subsUrl.length == 0) return;
+ if (subsUrl.startsWith("/")) {
+ RawSubs.loadSubs(subsUrl, video);
+ return;
+ }
+ if (!subsUrl.startsWith("http")) {
+ final protocol = Browser.location.protocol;
+ subsUrl = '$protocol//$subsUrl';
+ }
+ final subsUri = try {
+ new URL(subsUrl);
+ } catch (e) {
+ Main.serverMessage('Failed to add subs: bad url ($subsUrl)');
+ return;
+ }
+ // make local url as relative path to skip proxy
+ if (subsUri.hostname == main.host || subsUri.hostname == main.globalIp) {
+ subsUrl = subsUri.pathname;
+ }
+ RawSubs.loadSubs(subsUrl, video);
}
function restartControlsHider():Void {
diff --git a/src/client/players/RawSubs.hx b/src/client/players/RawSubs.hx
index 09b21d1..d7e32e2 100644
--- a/src/client/players/RawSubs.hx
+++ b/src/client/players/RawSubs.hx
@@ -18,12 +18,12 @@ private typedef Duration = {
}
class RawSubs {
- public static function loadSubs(item:VideoItem, video:VideoElement):Void {
- if (item.subs == null || item.subs.length == 0) return;
- final ext = PathTools.urlExtension(item.subs);
+ public static function loadSubs(subsUrl:String, video:VideoElement):Void {
+ if (subsUrl == null || subsUrl.length == 0) return;
+ final ext = PathTools.urlExtension(subsUrl);
// do not load subs if there is custom plugin
if (JsApi.hasSubtitleSupport(ext)) return;
- var url = encodeURI(item.subs);
+ var url = encodeURI(subsUrl);
if (!url.startsWith("/")) {
final protocol = Browser.location.protocol;
if (!url.startsWith("http")) url = '$protocol//$url';
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage