From f874dcd3de368e7e512ab1c0defdd17bc3026ce5 Mon Sep 17 00:00:00 2001 From: RblSb Date: Tue, 25 Mar 2025 03:02:03 +0300 Subject: Initial cache support for raw videos m3u8 videos are cached without downloading segments, only m3u8 file is downloaded and segment links are updated to use synctube proxy, so you can add video to playlist as server, ignoring ip restrictions, and stream it to everyone --- src/server/Main.hx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/server/Main.hx') diff --git a/src/server/Main.hx b/src/server/Main.hx index 86e619e..d935157 100644 --- a/src/server/Main.hx +++ b/src/server/Main.hx @@ -22,6 +22,7 @@ import js.npm.ws.Server as WSServer; import js.npm.ws.WebSocket; import json2object.ErrorUtils; import json2object.JsonParser; +import server.cache.Cache; import sys.FileSystem; import sys.io.File; @@ -48,7 +49,7 @@ class Main { var wss:WSServer; final localIp:String; var globalIp:String; - final playersCacheSupport:Array = []; + final playersCacheSupport:Array = [RawType]; var port:Int; final userList:UserList; @@ -577,7 +578,7 @@ class Main { case Login: final name = data.login.clientName.trim(); final lcName = name.toLowerCase(); - if (badNickName(lcName)) { + if (isBadClientName(lcName)) { serverMessage(client, "usernameError"); send(client, {type: LoginError}); return; @@ -686,6 +687,11 @@ class Main { addVideo(); } else { switch item.playerType { + case RawType: + cache.cacheRawVideo(client, item.url, (name) -> { + item = item.withUrl(cache.getFileUrl(name)); + addVideo(); + }); case YoutubeType: cache.cacheYoutubeVideo(client, item.url, (name) -> { item = item.withUrl(cache.getFileUrl(name)); @@ -1065,7 +1071,7 @@ class Main { final matchHtmlChars = ~/[&^<>'"]/; final matchGuestName = ~/guest [0-9]+/; - public function badNickName(name:String):Bool { + public function isBadClientName(name:String):Bool { if (name.length > config.maxLoginLength) return true; if (name.length == 0) return true; if (matchHtmlChars.match(name)) return true; @@ -1147,4 +1153,8 @@ class Main { } return false; } + + public function hasPlaylistUrl(url:String):Bool { + return videoList.exists(item -> item.url == url); + } } -- cgit v1.2.3