Update meta-handler.js
This commit is contained in:
parent
a81aef336c
commit
81cfac693a
1 changed files with 35 additions and 23 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* meta-handler.js
|
||||||
|
* Verwaltet das Abrufen und Anzeigen von Stream-Metadaten (Songtitel)
|
||||||
|
*/
|
||||||
|
|
||||||
const MetaHandler = {
|
const MetaHandler = {
|
||||||
proxyPath: 'metadata.php',
|
proxyPath: 'metadata.php',
|
||||||
updateInterval: 20000,
|
updateInterval: 20000,
|
||||||
|
|
@ -30,35 +35,36 @@ const MetaHandler = {
|
||||||
const stationDisplay = document.getElementById('current-station-name');
|
const stationDisplay = document.getElementById('current-station-name');
|
||||||
if (!stationDisplay) return;
|
if (!stationDisplay) return;
|
||||||
|
|
||||||
let currentFullText = stationDisplay.textContent;
|
// 1. Alles vor dem Titel extrahieren (enthält das Sender-Icon + Name)
|
||||||
let stationNameOnly = currentFullText.replace('Es läuft: ', '').split(' – ')[0].trim();
|
let currentContent = stationDisplay.innerHTML;
|
||||||
|
// Wir isolieren den Sender-Teil, indem wir alles nach dem Music-Icon oder Trenner-Span abschneiden
|
||||||
|
let stationPart = currentContent.split(' <span')[0].split(' <i class="fa-solid fa-music"')[0].trim();
|
||||||
|
|
||||||
|
// 2. Dubletten-Check (Text ohne Icons vergleichen)
|
||||||
|
const tempDiv = document.createElement("div");
|
||||||
|
tempDiv.innerHTML = stationPart;
|
||||||
|
const stationNameOnly = tempDiv.textContent.trim();
|
||||||
|
|
||||||
const cleanTitle = title.toLowerCase();
|
const cleanTitle = title.toLowerCase();
|
||||||
const cleanStation = stationNameOnly.toLowerCase();
|
const cleanStation = stationNameOnly.toLowerCase();
|
||||||
|
|
||||||
const isDuplicate = cleanTitle === cleanStation || cleanTitle.includes(cleanStation) || cleanStation.includes(cleanTitle);
|
// Filter für Dubletten und Systemmeldungen
|
||||||
const isSpam = title.includes('0848') || title.includes('.ch') || title.includes('@') || title.includes('Im Auftrag der SRG');
|
if (cleanTitle === cleanStation || cleanTitle.includes(cleanStation) || title.includes('0848')) {
|
||||||
|
stationDisplay.innerHTML = stationPart; // Nur Sender anzeigen
|
||||||
if (isDuplicate || isSpam) {
|
|
||||||
if (currentFullText.includes(' – ')) {
|
|
||||||
stationDisplay.textContent = currentFullText.split(' – ')[0];
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentFullText.includes(' – ')) {
|
// 3. Anzeige OHNE Bindestrich zusammenbauen (mit Abstandshaltern)
|
||||||
currentFullText = currentFullText.split(' – ')[0];
|
stationDisplay.innerHTML = `${stationPart} <i class="fa-solid fa-music"></i> ${title}`;
|
||||||
}
|
|
||||||
stationDisplay.textContent = `${currentFullText} – ${title}`;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
start(streamUrl) {
|
start(streamUrl) {
|
||||||
this.stop();
|
this.stop();
|
||||||
// Wir rufen fetchTitle direkt auf, um die PHP-Verbindung zu testen
|
// Erster Aufruf sofort
|
||||||
MetaHandler.fetchTitle(streamUrl);
|
this.fetchTitle(streamUrl);
|
||||||
|
|
||||||
this.intervalId = setInterval(() => {
|
this.intervalId = setInterval(() => {
|
||||||
MetaHandler.fetchTitle(streamUrl);
|
this.fetchTitle(streamUrl);
|
||||||
}, this.updateInterval);
|
}, this.updateInterval);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -67,9 +73,15 @@ const MetaHandler = {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
this.intervalId = null;
|
this.intervalId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stationDisplay = document.getElementById('current-station-name');
|
const stationDisplay = document.getElementById('current-station-name');
|
||||||
if (stationDisplay && stationDisplay.textContent.includes(' – ')) {
|
if (stationDisplay) {
|
||||||
stationDisplay.textContent = stationDisplay.textContent.split(' – ')[0];
|
// Entfernt alles ab dem Musik-Icon oder dem alten Bindestrich
|
||||||
|
if (stationDisplay.innerHTML.includes('<i class="fa-solid fa-music"')) {
|
||||||
|
stationDisplay.innerHTML = stationDisplay.innerHTML.split(' <i class="fa-solid fa-music"')[0];
|
||||||
|
} else if (stationDisplay.innerHTML.includes(' – ')) {
|
||||||
|
stationDisplay.innerHTML = stationDisplay.innerHTML.split(' – ')[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue