import { showNotification, _ } from './utils.js'; export async function generateAndDownloadSingleM3U(mediaItem) { try { if (!mediaItem || !mediaItem.streamUrl || !mediaItem.title) { showNotification(_('invalidMediaItemForM3U'), 'error'); return; } const duration = mediaItem.duration ? Math.round(mediaItem.duration / 1000) : -1; const tvgLogo = mediaItem.thumb ? `tvg-logo="${mediaItem.thumb}"` : ''; const groupTitle = mediaItem.seriesTitle && mediaItem.seasonNumber ? `group-title="${mediaItem.seriesTitle} - Season ${mediaItem.seasonNumber}"` : `group-title="${mediaItem.title}'`; // Fallback to title for group-title let m3uContent = '#EXTM3U\n'; m3uContent += `#EXTINF:${duration} ${tvgLogo} ${groupTitle},${mediaItem.title}\n`; m3uContent += `${mediaItem.streamUrl}\n`; const blob = new Blob([m3uContent], { type: 'audio/x-mpegurl;charset=utf-8' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${mediaItem.title}.m3u`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); showNotification(_('m3uDownloadedSuccess'), 'success'); } catch (error) { console.error(_('errorGeneratingM3uFile'), error); showNotification(_('errorGeneratingM3uFile'), 'error'); } }