Skip to content

Commit

Permalink
Raw youtube fallback for unavailable videos
Browse files Browse the repository at this point in the history
Also:
- fix `tryLocalIp` replacement (NAT workaround)
- improve proxy headers a bit
- use json2object fork for better generated diffs
  • Loading branch information
RblSb committed Apr 28, 2024
1 parent 8679f8e commit 9d844bb
Show file tree
Hide file tree
Showing 13 changed files with 1,537 additions and 488 deletions.
13 changes: 7 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
"res/client.js": true
},
"[haxe]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
}
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
"editor.codeActionsOnSave": {
"source.sortImports": "explicit",
"source.fixAll": "explicit"
},
"[html]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "vscode.html-language-features"
},
"[css]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "HookyQR.beautify"
"editor.defaultFormatter": "vscode.css-language-features"
},
}
3 changes: 2 additions & 1 deletion build-server.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--library hxnodejs
--library hxnodejs-ws
--library json2object
--library json2object:git:https://github.com/RblSb/json2object.git
-D junsafe_compiler_cache
# Client libs for completion
--library youtubeIFramePlayer:git:https://github.com/okawa-h/youtubeIFramePlayer-externs.git
--library hls.js-extern:git:https://github.com/grosmar/hls.js-haxe-extern.git
Expand Down
1,532 changes: 1,114 additions & 418 deletions build/server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hxformat.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"methodChain": {
"rules": []
},
}
},
"emptyLines": {
"beforeDocCommentEmptyLines": "ignore",
Expand Down
115 changes: 89 additions & 26 deletions res/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Types.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package;

import Client.ClientData;
import utils.YoutubeUtils.YouTubeVideoInfo;

typedef VideoDataRequest = {
url:String,
Expand Down Expand Up @@ -204,6 +205,10 @@ typedef WsEvent = {
},
?dump:{
data:String
},
?getYoutubeVideoInfo:{
url:String,
?response:YouTubeVideoInfo
}
}

Expand Down Expand Up @@ -242,4 +247,5 @@ enum abstract WsEventType(String) {
var UpdatePlaylist;
var TogglePlaylistLock;
var Dump;
var GetYoutubeVideoInfo;
}
12 changes: 11 additions & 1 deletion src/client/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import js.html.Event;
import js.html.InputElement;
import js.html.KeyboardEvent;
import js.html.MouseEvent;
import js.html.URL;
import js.html.VideoElement;
import js.html.WebSocket;

Expand Down Expand Up @@ -387,7 +388,13 @@ class Main {

public function tryLocalIp(url:String):String {
if (host == globalIp) return url;
return url.replace(globalIp, host);
try {
final url = new URL(url);
url.hostname = url.hostname.replace(globalIp, host);
return '$url';
} catch (e) {
return url;
}
}

function onMessage(e):Void {
Expand Down Expand Up @@ -557,6 +564,9 @@ class Main {

case Dump:
Utils.saveFile("dump.json", ApplicationJson, data.dump.data);

case GetYoutubeVideoInfo:
// handled by event listeners like `JsApi.once`
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/client/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class Player {
setItemElementType(el, videoList.getItem(pos).isTemp);
}

public function getCurrentItem():VideoItem {
return videoList.currentItem;
}

function setPlayer(newPlayer:IPlayer):Void {
if (player != newPlayer) {
if (player != null) {
Expand Down
Loading

0 comments on commit 9d844bb

Please sign in to comment.