79 lines
No EOL
2.6 KiB
JavaScript
79 lines
No EOL
2.6 KiB
JavaScript
const MetaHandler = {
|
||
proxyPath: 'metadata.php',
|
||
updateInterval: 20000,
|
||
intervalId: null,
|
||
proxyActive: false,
|
||
|
||
async init() {
|
||
try {
|
||
const response = await fetch(this.proxyPath, { method: 'HEAD' });
|
||
this.proxyActive = response.ok;
|
||
} catch (e) {
|
||
this.proxyActive = false;
|
||
}
|
||
},
|
||
|
||
async fetchTitle(streamUrl) {
|
||
if (!this.proxyActive || !streamUrl) return;
|
||
try {
|
||
const res = await fetch(`${this.proxyPath}?url=${encodeURIComponent(streamUrl)}`);
|
||
const data = await res.json();
|
||
if (data && data.title) {
|
||
this.updateUI(data.title);
|
||
}
|
||
} catch (e) {
|
||
console.error("Metadaten-Fehler:", e);
|
||
}
|
||
},
|
||
|
||
updateUI(title) {
|
||
const stationDisplay = document.getElementById('current-station-name');
|
||
if (!stationDisplay) return;
|
||
|
||
let currentFullText = stationDisplay.textContent;
|
||
let stationNameOnly = currentFullText.replace('Es läuft: ', '').split(' – ')[0].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];
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (currentFullText.includes(' – ')) {
|
||
currentFullText = currentFullText.split(' – ')[0];
|
||
}
|
||
stationDisplay.textContent = `${currentFullText} – ${title}`;
|
||
},
|
||
|
||
start(streamUrl) {
|
||
this.stop();
|
||
// Wir rufen fetchTitle direkt auf, um die PHP-Verbindung zu testen
|
||
MetaHandler.fetchTitle(streamUrl);
|
||
|
||
this.intervalId = setInterval(() => {
|
||
MetaHandler.fetchTitle(streamUrl);
|
||
}, this.updateInterval);
|
||
},
|
||
|
||
stop() {
|
||
if (this.intervalId) {
|
||
clearInterval(this.intervalId);
|
||
this.intervalId = null;
|
||
}
|
||
const stationDisplay = document.getElementById('current-station-name');
|
||
if (stationDisplay && stationDisplay.textContent.includes(' – ')) {
|
||
stationDisplay.textContent = stationDisplay.textContent.split(' – ')[0];
|
||
}
|
||
}
|
||
};
|
||
|
||
// Global verfügbar machen
|
||
window.MetaHandler = MetaHandler;
|
||
MetaHandler.init(); |