Spaces:
Sleeping
Sleeping
Keys commited on
Commit ·
a112445
1
Parent(s): af4e608
Added Cookies to make it smoother
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import os
|
|
| 2 |
import tempfile
|
| 3 |
import logging
|
| 4 |
import re
|
|
|
|
|
|
|
| 5 |
import zipfile
|
| 6 |
import smtplib
|
| 7 |
from email.mime.text import MIMEText
|
|
@@ -75,9 +77,14 @@ def download_single_audio(url, index, download_path):
|
|
| 75 |
}],
|
| 76 |
'retries': 3,
|
| 77 |
'fragment_retries': 3,
|
| 78 |
-
'cookies': './cookies.txt', #
|
| 79 |
}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
max_attempts = 3
|
| 82 |
for attempt in range(max_attempts):
|
| 83 |
try:
|
|
@@ -92,16 +99,15 @@ def download_single_audio(url, index, download_path):
|
|
| 92 |
except Exception as e:
|
| 93 |
logging.error(f"Error downloading audio (attempt {attempt + 1}/{max_attempts}): {e}")
|
| 94 |
if "Sign in to confirm you're not a bot" in str(e):
|
| 95 |
-
sleep_time = random.uniform(5,
|
| 96 |
logging.info(f"Detected anti-bot measure. Waiting for {sleep_time:.2f} seconds before retrying...")
|
| 97 |
-
time.sleep(sleep_time)
|
| 98 |
else:
|
| 99 |
return None
|
| 100 |
|
| 101 |
logging.error(f"Failed to download audio after {max_attempts} attempts: {url}")
|
| 102 |
return None
|
| 103 |
|
| 104 |
-
|
| 105 |
# Function to download all audio files in parallel
|
| 106 |
def download_all_audio(video_urls, download_path):
|
| 107 |
downloaded_files = []
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import logging
|
| 4 |
import re
|
| 5 |
+
import random
|
| 6 |
+
import time
|
| 7 |
import zipfile
|
| 8 |
import smtplib
|
| 9 |
from email.mime.text import MIMEText
|
|
|
|
| 77 |
}],
|
| 78 |
'retries': 3,
|
| 79 |
'fragment_retries': 3,
|
| 80 |
+
'cookies': './cookies.txt', # Path to your cookies file
|
| 81 |
}
|
| 82 |
|
| 83 |
+
# Ensure the cookies file exists
|
| 84 |
+
if not os.path.exists(ydl_opts['cookies']):
|
| 85 |
+
logging.error("Cookies file not found. Please ensure './cookies.txt' exists and is valid.")
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
max_attempts = 3
|
| 89 |
for attempt in range(max_attempts):
|
| 90 |
try:
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
logging.error(f"Error downloading audio (attempt {attempt + 1}/{max_attempts}): {e}")
|
| 101 |
if "Sign in to confirm you're not a bot" in str(e):
|
| 102 |
+
sleep_time = random.uniform(5, 15)
|
| 103 |
logging.info(f"Detected anti-bot measure. Waiting for {sleep_time:.2f} seconds before retrying...")
|
| 104 |
+
time.sleep(sleep_time) # Introduce wait time before retrying
|
| 105 |
else:
|
| 106 |
return None
|
| 107 |
|
| 108 |
logging.error(f"Failed to download audio after {max_attempts} attempts: {url}")
|
| 109 |
return None
|
| 110 |
|
|
|
|
| 111 |
# Function to download all audio files in parallel
|
| 112 |
def download_all_audio(video_urls, download_path):
|
| 113 |
downloaded_files = []
|