Neo2902 commited on
Commit ·
aa6d22a
1
Parent(s): b15fddc
Projet complet avec chunking, extract_playlist et youtube_search
Browse files
app.py
CHANGED
|
@@ -45,8 +45,18 @@ async def extract(request: Request):
|
|
| 45 |
return JSONResponse(status_code=400, content={"message": "Playlist URL manquante"})
|
| 46 |
try:
|
| 47 |
songs = await extract_playlist_playwright.extract_playlist(playlist_url)
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
return JSONResponse(status_code=500, content={"message": f"Erreur extraction : {str(e)}"})
|
| 52 |
|
|
|
|
| 45 |
return JSONResponse(status_code=400, content={"message": "Playlist URL manquante"})
|
| 46 |
try:
|
| 47 |
songs = await extract_playlist_playwright.extract_playlist(playlist_url)
|
| 48 |
+
batches = list(chunking.chunk_list(songs, 10))
|
| 49 |
+
|
| 50 |
+
final_results = []
|
| 51 |
+
for batch in batches:
|
| 52 |
+
tasks = [youtube_search.search_youtube(song['title'], song['artist']) for song in batch]
|
| 53 |
+
results = await asyncio.gather(*tasks)
|
| 54 |
+
final_results.extend(results)
|
| 55 |
+
|
| 56 |
+
return {
|
| 57 |
+
"message": f"{len(songs)} morceaux extraits et enrichis en {len(batches)} paquets.",
|
| 58 |
+
"playlist": final_results
|
| 59 |
+
}
|
| 60 |
except Exception as e:
|
| 61 |
return JSONResponse(status_code=500, content={"message": f"Erreur extraction : {str(e)}"})
|
| 62 |
|