Changes
This commit is contained in:
@@ -55,18 +55,47 @@ export const MusicProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
const fetchStations = useCallback(async () => {
|
||||
if (hasFetched) return;
|
||||
try {
|
||||
const response = await fetch(
|
||||
'https://de1.api.radio-browser.info/json/stations/topclick/100'
|
||||
);
|
||||
if (!response.ok) throw new Error('Failed to fetch stations');
|
||||
const data: Station[] = await response.json();
|
||||
const validStations = data.filter(s => !failedStations.has(s.stationuuid));
|
||||
setStations(validStations);
|
||||
setHasFetched(true);
|
||||
} catch (err) {
|
||||
console.error('Error fetching stations:', err);
|
||||
|
||||
// Multiple radio-browser API servers for fallback
|
||||
const apiServers = [
|
||||
'https://de1.api.radio-browser.info',
|
||||
'https://de2.api.radio-browser.info',
|
||||
'https://nl1.api.radio-browser.info',
|
||||
'https://nl2.api.radio-browser.info',
|
||||
'https://at1.api.radio-browser.info',
|
||||
'https://fr1.api.radio-browser.info',
|
||||
'https://all.api.radio-browser.info',
|
||||
];
|
||||
|
||||
for (const server of apiServers) {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const response = await fetch(
|
||||
`${server}/json/stations/topclick/100`,
|
||||
{ signal: controller.signal }
|
||||
);
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (!response.ok) continue;
|
||||
|
||||
const data: Station[] = await response.json();
|
||||
const validStations = data.filter(s => !failedStations.has(s.stationuuid));
|
||||
|
||||
if (validStations.length > 0) {
|
||||
setStations(validStations);
|
||||
setHasFetched(true);
|
||||
console.log(`Fetched stations from ${server}`);
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(`Failed to fetch from ${server}:`, err);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
console.error('All radio API servers failed');
|
||||
}, [hasFetched, failedStations]);
|
||||
|
||||
const stopCurrentAudio = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user