diff --git a/main.py b/main.py index 44e6d2c..27a9e81 100644 --- a/main.py +++ b/main.py @@ -259,6 +259,36 @@ async def download_anime_episode( return {"task_id": task.id, "task": task} +@app.post("/api/anime/download-season") +async def download_anime_season( + url: str, + background_tasks: BackgroundTasks, + lang: str = "vostfr" +): + """Download all episodes of an anime season""" + from app.downloaders import get_downloader + + downloader = get_downloader(url) + episodes = await downloader.get_episodes(url, lang) + + if not episodes: + raise HTTPException(status_code=404, detail="No episodes found") + + # Create download tasks for all episodes + task_ids = [] + for episode in episodes: + request = DownloadRequest(url=episode['url']) + task = download_manager.create_task(request) + task_ids.append(task.id) + background_tasks.add_task(download_manager.start_download, task.id) + + return { + "message": f"Started downloading {len(task_ids)} episodes", + "task_ids": task_ids, + "total_episodes": len(episodes) + } + + # Video Streaming endpoints @app.get("/video/{task_id}") async def stream_video(task_id: str, request: Request): diff --git a/templates/index.html b/templates/index.html index 59ab38f..c835702 100644 --- a/templates/index.html +++ b/templates/index.html @@ -645,6 +645,12 @@ Télécharger + `; @@ -690,15 +696,9 @@ selectElement.appendChild(option); }); - // Show download button when episode is selected - selectElement.onchange = () => { - const actionsDiv = document.getElementById(actionsId); - if (selectElement.value) { - actionsDiv.style.display = 'flex'; - } else { - actionsDiv.style.display = 'none'; - } - }; + // Show download buttons immediately (season button is always useful) + const actionsDiv = document.getElementById(actionsId); + actionsDiv.style.display = 'flex'; // Store the selected episode URL for download selectElement.dataset.animeUrl = url; @@ -754,6 +754,32 @@ } } + async function downloadEntireSeason(encodedUrl, lang) { + const url = decodeURIComponent(encodedUrl); + + if (!confirm(`⚠️ Attention: Vous allez télécharger toute la saison. Cela peut prendre du temps et utiliser beaucoup d'espace disque.\n\nVoulez-vous continuer ?`)) { + return; + } + + try { + const response = await fetch(`${API_BASE}/anime/download-season?url=${encodeURIComponent(url)}&lang=${lang}`, { + method: 'POST' + }); + + if (response.ok) { + const data = await response.json(); + loadDownloads(); + alert(`✅ ${data.message}\n\n${data.total_episodes} épisodes ont été ajoutés à la file de téléchargement!`); + } else { + const error = await response.json(); + alert(`Erreur: ${error.detail || 'Impossible de démarrer le téléchargement de la saison'}`); + } + } catch (error) { + console.error('Error:', error); + alert('Erreur lors du démarrage du téléchargement de la saison'); + } + } + async function getProvidersInfo() { if (!searchResultsCache.providers) { const response = await fetch(`${API_BASE}/providers`);