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,20 +110,32 @@ 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) {
const libraryElement = m3uLibrariesContainer.querySelector(`#library-${libraryKey}`); try {
const libraryType = libraryElement.getAttribute('data-type'); const libraryElement = m3uLibrariesContainer.querySelector(`#library-${libraryKey}`);
const libraryTitle = libraryElement ? libraryElement.nextElementSibling.textContent.trim() : ''; const libraryType = libraryElement.getAttribute('data-type');
const items = await fetchLibraryContents(server.accessToken, server.publicUrl, server.localUrl, libraryKey, libraryType); const libraryTitle = libraryElement ? libraryElement.nextElementSibling.textContent.trim() : '';
items.forEach(item => { const items = await fetchLibraryContents(server.accessToken, server.publicUrl, server.localUrl, libraryKey, libraryType, 60000);
const duration = item.duration ? Math.round(item.duration / 1000) : -1; items.forEach(item => {
const groupTitle = item.seriesTitle && item.seasonNumber const duration = item.duration ? Math.round(item.duration / 1000) : -1;
? `group-title="${item.seriesTitle} - Season ${item.seasonNumber}"` const groupTitle = item.seriesTitle && item.seasonNumber
: `group-title="${libraryTitle}"`; ? `group-title="${item.seriesTitle} - Season ${item.seasonNumber}"`
const tvgLogo = item.thumb ? `tvg-logo="${item.thumb}"` : ''; : `group-title="${libraryTitle}"`;
m3uContent += `#EXTINF:${duration} ${tvgLogo} ${groupTitle},${item.title}\n`; const tvgLogo = item.thumb ? `tvg-logo="${item.thumb}"` : '';
m3uContent += `${item.url}\n`; m3uContent += `#EXTINF:${duration} ${tvgLogo} ${groupTitle},${item.title}\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);
showNotification('M3U playlist downloaded successfully.', 'success'); if (hasErrors) {
showNotification('M3U generated with some errors. Some libraries may be missing.', 'warning');
} else {
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;