Maximo Fernandez
commited on
Commit
·
85c53a9
1
Parent(s):
ad33eea
Create coockies file
Browse files- download.py +14 -0
download.py
CHANGED
|
@@ -66,8 +66,19 @@ def download_twitch(url, type):
|
|
| 66 |
os.system(f'ffmpeg -i {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format} -c:a libmp3lame -b:a 192k -stats -loglevel warning {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}')
|
| 67 |
os.system(f'rm {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format}')
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
def download_youtube_video(url):
|
| 70 |
try:
|
|
|
|
| 71 |
# Config options
|
| 72 |
ydl_options = {
|
| 73 |
"outtmpl": f"{VIDEO_FOLDER}/{DOWNLOAD_VIDEO_NAME}.{DOWNLOAD_VIDEO_FORMAT}",
|
|
@@ -76,6 +87,7 @@ def download_youtube_video(url):
|
|
| 76 |
"force_ipv4": True,
|
| 77 |
"no_check_certificates": True,
|
| 78 |
"geo_bypass": True,
|
|
|
|
| 79 |
}
|
| 80 |
# Download video
|
| 81 |
with yt_dlp.YoutubeDL(ydl_options) as ydl:
|
|
@@ -85,6 +97,7 @@ def download_youtube_video(url):
|
|
| 85 |
|
| 86 |
def download_youtube_audio(url):
|
| 87 |
try:
|
|
|
|
| 88 |
# Config options
|
| 89 |
ydl_options = {
|
| 90 |
"outtmpl": f"{AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}",
|
|
@@ -93,6 +106,7 @@ def download_youtube_audio(url):
|
|
| 93 |
"force_ipv4": True,
|
| 94 |
"no_check_certificates": True,
|
| 95 |
"geo_bypass": True,
|
|
|
|
| 96 |
}
|
| 97 |
# Download audio
|
| 98 |
with yt_dlp.YoutubeDL(ydl_options) as ydl:
|
|
|
|
| 66 |
os.system(f'ffmpeg -i {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format} -c:a libmp3lame -b:a 192k -stats -loglevel warning {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}')
|
| 67 |
os.system(f'rm {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format}')
|
| 68 |
|
| 69 |
+
def create_minimal_cookies():
|
| 70 |
+
cookies_content = """# Netscape HTTP Cookie File
|
| 71 |
+
# https://www.youtube.com/
|
| 72 |
+
.youtube.com TRUE / FALSE 1735689600 CONSENT YES+cb
|
| 73 |
+
.youtube.com TRUE / FALSE 1735689600 VISITOR_INFO1_LIVE random_string
|
| 74 |
+
"""
|
| 75 |
+
with open('youtube_cookies.txt', 'w') as f:
|
| 76 |
+
f.write(cookies_content)
|
| 77 |
+
return 'youtube_cookies.txt'
|
| 78 |
+
|
| 79 |
def download_youtube_video(url):
|
| 80 |
try:
|
| 81 |
+
cookies_file = create_minimal_cookies()
|
| 82 |
# Config options
|
| 83 |
ydl_options = {
|
| 84 |
"outtmpl": f"{VIDEO_FOLDER}/{DOWNLOAD_VIDEO_NAME}.{DOWNLOAD_VIDEO_FORMAT}",
|
|
|
|
| 87 |
"force_ipv4": True,
|
| 88 |
"no_check_certificates": True,
|
| 89 |
"geo_bypass": True,
|
| 90 |
+
"cookiefile": cookies_file
|
| 91 |
}
|
| 92 |
# Download video
|
| 93 |
with yt_dlp.YoutubeDL(ydl_options) as ydl:
|
|
|
|
| 97 |
|
| 98 |
def download_youtube_audio(url):
|
| 99 |
try:
|
| 100 |
+
cookies_file = create_minimal_cookies()
|
| 101 |
# Config options
|
| 102 |
ydl_options = {
|
| 103 |
"outtmpl": f"{AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}",
|
|
|
|
| 106 |
"force_ipv4": True,
|
| 107 |
"no_check_certificates": True,
|
| 108 |
"geo_bypass": True,
|
| 109 |
+
"cookiefile": cookies_file
|
| 110 |
}
|
| 111 |
# Download audio
|
| 112 |
with yt_dlp.YoutubeDL(ydl_options) as ydl:
|