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 = {
|
||||
proxyPath: 'metadata.php',
|
||||
updateInterval: 20000,
|
||||
|
|
@ -30,35 +35,36 @@ const MetaHandler = {
|
|||
const stationDisplay = document.getElementById('current-station-name');
|
||||
if (!stationDisplay) return;
|
||||
|
||||
let currentFullText = stationDisplay.textContent;
|
||||
let stationNameOnly = currentFullText.replace('Es läuft: ', '').split(' – ')[0].trim();
|
||||
// 1. Alles vor dem Titel extrahieren (enthält das Sender-Icon + Name)
|
||||
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 cleanStation = stationNameOnly.toLowerCase();
|
||||
|
||||
const isDuplicate = cleanTitle === cleanStation || cleanTitle.includes(cleanStation) || cleanStation.includes(cleanTitle);
|
||||
const isSpam = title.includes('0848') || title.includes('.ch') || title.includes('@') || title.includes('Im Auftrag der SRG');
|
||||
|
||||
if (isDuplicate || isSpam) {
|
||||
if (currentFullText.includes(' – ')) {
|
||||
stationDisplay.textContent = currentFullText.split(' – ')[0];
|
||||
}
|
||||
// Filter für Dubletten und Systemmeldungen
|
||||
if (cleanTitle === cleanStation || cleanTitle.includes(cleanStation) || title.includes('0848')) {
|
||||
stationDisplay.innerHTML = stationPart; // Nur Sender anzeigen
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentFullText.includes(' – ')) {
|
||||
currentFullText = currentFullText.split(' – ')[0];
|
||||
}
|
||||
stationDisplay.textContent = `${currentFullText} – ${title}`;
|
||||
// 3. Anzeige OHNE Bindestrich zusammenbauen (mit Abstandshaltern)
|
||||
stationDisplay.innerHTML = `${stationPart} <i class="fa-solid fa-music"></i> ${title}`;
|
||||
},
|
||||
|
||||
start(streamUrl) {
|
||||
this.stop();
|
||||
// Wir rufen fetchTitle direkt auf, um die PHP-Verbindung zu testen
|
||||
MetaHandler.fetchTitle(streamUrl);
|
||||
// Erster Aufruf sofort
|
||||
this.fetchTitle(streamUrl);
|
||||
|
||||
this.intervalId = setInterval(() => {
|
||||
MetaHandler.fetchTitle(streamUrl);
|
||||
this.fetchTitle(streamUrl);
|
||||
}, this.updateInterval);
|
||||
},
|
||||
|
||||
|
|
@ -67,9 +73,15 @@ const MetaHandler = {
|
|||
clearInterval(this.intervalId);
|
||||
this.intervalId = null;
|
||||
}
|
||||
|
||||
const stationDisplay = document.getElementById('current-station-name');
|
||||
if (stationDisplay && stationDisplay.textContent.includes(' – ')) {
|
||||
stationDisplay.textContent = stationDisplay.textContent.split(' – ')[0];
|
||||
if (stationDisplay) {
|
||||
// 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