Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -386,15 +386,12 @@ class AudioProcessor:
|
|
386 |
return self._combine_summaries(summaries)
|
387 |
raise e"""
|
388 |
|
389 |
-
|
390 |
-
from typing import Optional
|
391 |
-
import subprocess
|
392 |
|
393 |
|
394 |
class VideoProcessor:
|
395 |
def __init__(self):
|
396 |
self.supported_formats = ['.mp4', '.avi', '.mov', '.mkv']
|
397 |
-
self.cookie_file_path = "cookies.txt" # Fichier cookies utilisé par yt-dlp
|
398 |
self.ydl_opts = {
|
399 |
'format': 'bestaudio/best',
|
400 |
'postprocessors': [{
|
@@ -402,8 +399,7 @@ class VideoProcessor:
|
|
402 |
'preferredcodec': 'mp3',
|
403 |
'preferredquality': '192',
|
404 |
}],
|
405 |
-
'outtmpl': 'temp_audio.%(ext)s'
|
406 |
-
'cookiefile': self.cookie_file_path # Ajout des cookies ici
|
407 |
}
|
408 |
|
409 |
|
@@ -431,7 +427,7 @@ class VideoProcessor:
|
|
431 |
ydl.download([url])
|
432 |
return 'temp_audio.mp3' """
|
433 |
|
434 |
-
|
435 |
try:
|
436 |
# Fichier cookies
|
437 |
cookie_file_path = "cookies.txt"
|
@@ -457,42 +453,6 @@ class VideoProcessor:
|
|
457 |
if not os.path.exists(audio_path):
|
458 |
raise FileNotFoundError(f"Le fichier {audio_path} n'a pas été généré.")
|
459 |
|
460 |
-
return audio_path
|
461 |
-
except Exception as e:
|
462 |
-
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")"""
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
def update_cookies(self):
|
469 |
-
"""
|
470 |
-
Met à jour les cookies en les récupérant dynamiquement depuis le navigateur ou une commande yt-dlp.
|
471 |
-
"""
|
472 |
-
try:
|
473 |
-
# Exécuter une commande yt-dlp pour récupérer les cookies du navigateur
|
474 |
-
subprocess.run(
|
475 |
-
["yt-dlp", "--cookies-from-browser", "chrome", "--dump-cookies", self.cookie_file_path],
|
476 |
-
check=True
|
477 |
-
)
|
478 |
-
print(f"Cookies mis à jour et enregistrés dans {self.cookie_file_path}.")
|
479 |
-
except Exception as e:
|
480 |
-
raise RuntimeError(f"Erreur lors de la mise à jour des cookies : {str(e)}")
|
481 |
-
|
482 |
-
def download_youtube_audio(self, url: str) -> str:
|
483 |
-
try:
|
484 |
-
# Mettre à jour les cookies avant chaque téléchargement
|
485 |
-
self.update_cookies()
|
486 |
-
|
487 |
-
# Téléchargement avec yt-dlp
|
488 |
-
with yt_dlp.YoutubeDL(self.ydl_opts) as ydl:
|
489 |
-
ydl.download([url])
|
490 |
-
|
491 |
-
# Vérifier si le fichier audio existe
|
492 |
-
audio_path = 'temp_audio.mp3'
|
493 |
-
if not os.path.exists(audio_path):
|
494 |
-
raise FileNotFoundError(f"Le fichier {audio_path} n'a pas été généré.")
|
495 |
-
|
496 |
return audio_path
|
497 |
except Exception as e:
|
498 |
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")
|
|
|
386 |
return self._combine_summaries(summaries)
|
387 |
raise e"""
|
388 |
|
389 |
+
|
|
|
|
|
390 |
|
391 |
|
392 |
class VideoProcessor:
|
393 |
def __init__(self):
|
394 |
self.supported_formats = ['.mp4', '.avi', '.mov', '.mkv']
|
|
|
395 |
self.ydl_opts = {
|
396 |
'format': 'bestaudio/best',
|
397 |
'postprocessors': [{
|
|
|
399 |
'preferredcodec': 'mp3',
|
400 |
'preferredquality': '192',
|
401 |
}],
|
402 |
+
'outtmpl': 'temp_audio.%(ext)s'
|
|
|
403 |
}
|
404 |
|
405 |
|
|
|
427 |
ydl.download([url])
|
428 |
return 'temp_audio.mp3' """
|
429 |
|
430 |
+
def download_youtube_audio(self, url: str) -> str:
|
431 |
try:
|
432 |
# Fichier cookies
|
433 |
cookie_file_path = "cookies.txt"
|
|
|
453 |
if not os.path.exists(audio_path):
|
454 |
raise FileNotFoundError(f"Le fichier {audio_path} n'a pas été généré.")
|
455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
return audio_path
|
457 |
except Exception as e:
|
458 |
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")
|