Added basic option to specify alternative IA CDN servers within the settings panel.

This commit is contained in:
rainbow napkin 2025-09-06 09:08:07 -04:00
parent 08d2bf8bc9
commit e9c474eaf0
6 changed files with 98 additions and 5 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
node_modules/
log/
log/crash/*
package-lock.json
config.json
state.json

View file

@ -16,6 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<link rel="stylesheet" type="text/css" href="/css/panel/settings.css">
<div id="settings-panel">
<h2>Client Settings</h2>
<h4>Player Settings</h4>
<span id="settings-panel-youtube-source" class="settings-panel-setting">
<p>Youtube Player Type:</p>
<select>
@ -23,5 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<option value="embed">Official Embed</option>
</select>
</span>
<span id="settings-panel-ia-server" class="settings-panel-setting">
<p>Internet Archive CDN Server:</p>
<input placeholder="Source Default">
</span>
</div>
</div>

View file

@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
display: flex;
flex-direction: column;
gap: 1em;
align-items: center;
}
#settings-panel h2{
@ -24,10 +25,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
margin: 1em 0 0;
}
#settings-panel h4{
text-align: center;
margin: 0;
}
.settings-panel-setting{
display: flex;
flex-direction: row;
text-wrap: nowrap;
height: 1em;
align-items: center;
max-width: 30em;
width: 100%
}
.settings-panel-setting :is(input, select){
width: 1px;
flex: 1 1 auto;
}

View file

@ -166,6 +166,9 @@ class channel{
* @param {*} value - Value to set setting to
*/
processConfig(key, value){
//Unfortunately we can't scope constants to switch-cases so this is the best we got if we wanna re-use the name
let nowPlaying;
//Switch/case by config key
switch(key){
case 'ytPlayerType':
@ -205,18 +208,35 @@ class channel{
return;
}
//Get current video
const nowPlaying = this.player.mediaHandler.nowPlaying;
nowPlaying = this.player.mediaHandler.nowPlaying;
//If we're playing a youtube video
if(nowPlaying != null && nowPlaying.type == 'yt'){
//Restart the video
this.player.start({media: nowPlaying});
this.player.hardReload();
}
//Stop while we're ahead
return;
case 'IACDN':
//If the player or mediaHandler isn't loaded
if(this.player == null || this.player.mediaHandler == null){
//We're fuggin done here
return;
}
//Get current video
nowPlaying = this.player.mediaHandler.nowPlaying;
//If we're playing a video from Internet Archive
if(nowPlaying != null && nowPlaying.type == 'ia'){
//Hard reload the media, forcing media handler re-creation
this.player.hardReload();
}
return;
}
}
@ -224,7 +244,8 @@ class channel{
* Default channel config
*/
static defaultConfig = new Map([
["ytPlayerType","raw"]
["ytPlayerType","raw"],
["IACDN",""]
]);
}

View file

@ -32,8 +32,16 @@ class settingsPanel extends panelObj{
}
docSwitch(){
/**
* Youtube Source Selector
*/
this.youtubeSource = this.panelDocument.querySelector("#settings-panel-youtube-source select");
/**
* Internet Archive CDN Server Input
*/
this.IACDNInput = this.panelDocument.querySelector("#settings-panel-ia-server input");
this.renderSettings();
this.setupInput();
}
@ -43,6 +51,7 @@ class settingsPanel extends panelObj{
*/
setupInput(){
this.youtubeSource.addEventListener('change', this.updateYoutubeSource.bind(this));
this.IACDNInput.addEventListener('keydown', this.updateIACDN.bind(this));
}
/**
@ -50,6 +59,7 @@ class settingsPanel extends panelObj{
*/
renderSettings(){
this.youtubeSource.value = localStorage.getItem("ytPlayerType");
this.IACDNInput.value = localStorage.getItem("IACDN");
}
/**
@ -59,4 +69,15 @@ class settingsPanel extends panelObj{
localStorage.setItem("ytPlayerType", this.youtubeSource.value);
client.processConfig("ytPlayerType", this.youtubeSource.value);
}
/**
* Event handler for Internet Archive CDN Server input
* @param {Event} event - Event handed down by event listener
*/
updateIACDN(event){
if(event.key == "Enter"){
localStorage.setItem("IACDN", this.IACDNInput.value);
client.processConfig("IACDN", this.IACDNInput.value);
}
}
}

View file

@ -192,6 +192,18 @@ class player{
this.mediaHandler = new hlsDailymotionHandler(this.client, this, data.media);
//Otherwise, if we have a raw-file compatible source
}else if(data.media.type == 'ia' || data.media.type == 'raw' || data.media.type == 'yt' || data.media.type == 'dm'){
//If we're running a source from IA
if(data.media.type == 'ia'){
//Replace specified CDN with generic URL, in-case of hard reload
data.media.rawLink = data.media.rawLink.replace(/^https(.*)archive\.org(.*)items/g, "https://archive.org/download")
//If we have an IA source and a custom IA CDN Server set
if(data.media.type == 'ia' && localStorage.getItem("IACDN") != ""){
//Generate and set new link
data.media.rawLink = data.media.rawLink.replace("https://archive.org/download", `https://${localStorage.getItem("IACDN")}.archive.org/0/items`);
}
}
//Create a new raw file handler for it
this.mediaHandler = new rawFileHandler(client, this, data.media);
//Sync to time stamp
@ -244,6 +256,27 @@ class player{
}
}
/**
* Destroys and Re-Creates media handler
*/
hardReload(){
if(this.mediaHandler != null){
//Re-create data we'd get from server
const data = {
media: this.mediaHandler.nowPlaying,
timestamp: this.mediaHandler.getTimestamp()
}
//End current media handler
this.end();
console.log(data);
//Restart from last media handlers
this.start(data);
}
}
/**
* Handles End-Media Commands from the Server
*/