Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -392,6 +392,7 @@ class AudioProcessor:
|
|
| 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': [{
|
|
@@ -403,7 +404,15 @@ class VideoProcessor:
|
|
| 403 |
}
|
| 404 |
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
|
|
|
|
| 407 |
def extract_video_id(self, url: str) -> str:
|
| 408 |
try:
|
| 409 |
parsed_url = urlparse(url)
|
|
@@ -427,7 +436,7 @@ class VideoProcessor:
|
|
| 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,6 +462,25 @@ class VideoProcessor:
|
|
| 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)}")
|
|
@@ -843,6 +871,7 @@ def handle_youtube_input():
|
|
| 843 |
if transcription:
|
| 844 |
process_and_display_results(None, None, transcription)
|
| 845 |
else:
|
|
|
|
| 846 |
audio_path = video_processor.download_youtube_audio(youtube_url)
|
| 847 |
process_and_display_results(audio_path)
|
| 848 |
|
|
|
|
| 392 |
class VideoProcessor:
|
| 393 |
def __init__(self):
|
| 394 |
self.supported_formats = ['.mp4', '.avi', '.mov', '.mkv']
|
| 395 |
+
self.cookie_file_path = "cookies.txt" # Chemin du fichier cookies
|
| 396 |
self.ydl_opts = {
|
| 397 |
'format': 'bestaudio/best',
|
| 398 |
'postprocessors': [{
|
|
|
|
| 404 |
}
|
| 405 |
|
| 406 |
|
| 407 |
+
def load_cookies(self):
|
| 408 |
+
"""Charge les cookies depuis Hugging Face et les enregistre localement."""
|
| 409 |
+
dataset = load_dataset("Adjoumani/YoutubeCookiesDataset")
|
| 410 |
+
cookies = dataset["train"]["cookies"][0]
|
| 411 |
+
with open(self.cookie_file_path, "w") as f:
|
| 412 |
+
f.write(cookies)
|
| 413 |
+
print(f"Cookies enregistrés dans {self.cookie_file_path}")
|
| 414 |
|
| 415 |
+
|
| 416 |
def extract_video_id(self, url: str) -> str:
|
| 417 |
try:
|
| 418 |
parsed_url = urlparse(url)
|
|
|
|
| 436 |
ydl.download([url])
|
| 437 |
return 'temp_audio.mp3' """
|
| 438 |
|
| 439 |
+
"""def download_youtube_audio(self, url: str) -> str:
|
| 440 |
try:
|
| 441 |
# Fichier cookies
|
| 442 |
cookie_file_path = "cookies.txt"
|
|
|
|
| 462 |
if not os.path.exists(audio_path):
|
| 463 |
raise FileNotFoundError(f"Le fichier {audio_path} n'a pas été généré.")
|
| 464 |
|
| 465 |
+
return audio_path
|
| 466 |
+
except Exception as e:
|
| 467 |
+
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")"""
|
| 468 |
+
|
| 469 |
+
def download_youtube_audio(self, url: str) -> str:
|
| 470 |
+
try:
|
| 471 |
+
# Ajoutez le fichier cookies dans les options
|
| 472 |
+
ydl_opts = self.ydl_opts.copy()
|
| 473 |
+
ydl_opts['cookiefile'] = self.cookie_file_path
|
| 474 |
+
|
| 475 |
+
# Téléchargement
|
| 476 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 477 |
+
ydl.download([url])
|
| 478 |
+
|
| 479 |
+
# Vérifier si le fichier audio existe
|
| 480 |
+
audio_path = 'temp_audio.mp3'
|
| 481 |
+
if not os.path.exists(audio_path):
|
| 482 |
+
raise FileNotFoundError(f"Le fichier {audio_path} n'a pas été généré.")
|
| 483 |
+
|
| 484 |
return audio_path
|
| 485 |
except Exception as e:
|
| 486 |
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")
|
|
|
|
| 871 |
if transcription:
|
| 872 |
process_and_display_results(None, None, transcription)
|
| 873 |
else:
|
| 874 |
+
video_processor.load_cookies()
|
| 875 |
audio_path = video_processor.download_youtube_audio(youtube_url)
|
| 876 |
process_and_display_results(audio_path)
|
| 877 |
|