fix time generate m3u

This commit is contained in:
Filipinos 2025-07-27 08:47:55 +02:00
parent aa3622db2d
commit e96e4eb255
2 changed files with 32 additions and 16 deletions

View File

@ -110,11 +110,14 @@ document.addEventListener('DOMContentLoaded', () => {
if (!server) return; if (!server) return;
let m3uContent = '#EXTM3U\n'; let m3uContent = '#EXTM3U\n';
let hasErrors = false;
for (const libraryKey of selectedLibraries) { for (const libraryKey of selectedLibraries) {
try {
const libraryElement = m3uLibrariesContainer.querySelector(`#library-${libraryKey}`); const libraryElement = m3uLibrariesContainer.querySelector(`#library-${libraryKey}`);
const libraryType = libraryElement.getAttribute('data-type'); const libraryType = libraryElement.getAttribute('data-type');
const libraryTitle = libraryElement ? libraryElement.nextElementSibling.textContent.trim() : ''; const libraryTitle = libraryElement ? libraryElement.nextElementSibling.textContent.trim() : '';
const items = await fetchLibraryContents(server.accessToken, server.publicUrl, server.localUrl, libraryKey, libraryType); const items = await fetchLibraryContents(server.accessToken, server.publicUrl, server.localUrl, libraryKey, libraryType, 60000);
items.forEach(item => { items.forEach(item => {
const duration = item.duration ? Math.round(item.duration / 1000) : -1; const duration = item.duration ? Math.round(item.duration / 1000) : -1;
const groupTitle = item.seriesTitle && item.seasonNumber const groupTitle = item.seriesTitle && item.seasonNumber
@ -124,6 +127,15 @@ document.addEventListener('DOMContentLoaded', () => {
m3uContent += `#EXTINF:${duration} ${tvgLogo} ${groupTitle},${item.title}\n`; m3uContent += `#EXTINF:${duration} ${tvgLogo} ${groupTitle},${item.title}\n`;
m3uContent += `${item.url}\n`; m3uContent += `${item.url}\n`;
}); });
} catch (error) {
hasErrors = true;
console.error(`Error processing library ${libraryKey}:`, error);
showNotification(`Error processing library ${libraryKey}. Skipping.`, 'warning');
}
}
if (m3uContent.split('\n').length <= 2 && hasErrors) {
throw new Error("All selected libraries failed to process.");
} }
const blob = new Blob([m3uContent], { type: 'audio/x-mpegurl;charset=utf-8' }); const blob = new Blob([m3uContent], { type: 'audio/x-mpegurl;charset=utf-8' });
@ -136,7 +148,11 @@ document.addEventListener('DOMContentLoaded', () => {
document.body.removeChild(a); document.body.removeChild(a);
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
if (hasErrors) {
showNotification('M3U generated with some errors. Some libraries may be missing.', 'warning');
} else {
showNotification('M3U playlist downloaded successfully.', 'success'); showNotification('M3U playlist downloaded successfully.', 'success');
}
} catch (error) { } catch (error) {
console.error('Error generating M3U file:', error); console.error('Error generating M3U file:', error);
showNotification('Error generating M3U file.', 'error'); showNotification('Error generating M3U file.', 'error');

View File

@ -42,10 +42,10 @@ export async function fetchLibraries(accessToken, publicUrl, localUrl) {
})); }));
} }
export async function fetchLibraryContents(accessToken, publicUrl, localUrl, libraryKey, libraryType) { export async function fetchLibraryContents(accessToken, publicUrl, localUrl, libraryKey, libraryType, timeout = 7000) {
const endpoint = libraryType === 'show' ? 'allLeaves' : 'all'; const endpoint = libraryType === 'show' ? 'allLeaves' : 'all';
const url = `${localUrl || publicUrl}/library/sections/${libraryKey}/${endpoint}?X-Plex-Token=${accessToken}`; const url = `${localUrl || publicUrl}/library/sections/${libraryKey}/${endpoint}?X-Plex-Token=${accessToken}`;
const contentXml = await fetchSectionContent(url, new AbortController().signal); const contentXml = await fetchSectionContent(url, new AbortController().signal, timeout);
const items = []; const items = [];
const baseUrl = localUrl || publicUrl; const baseUrl = localUrl || publicUrl;