34 lines
825 B
Python
34 lines
825 B
Python
"""
|
|
Saves youtube videos specified in 'batch_urls.txt' to the local folder. (to be copied manually)
|
|
"""
|
|
import youtube_dl
|
|
|
|
urls = []
|
|
with open ("batch_urls.txt", "r") as f:
|
|
urls = f.readlines()
|
|
|
|
|
|
def post_download_hook(ret_code):
|
|
if ret_code['status'] == 'finished':
|
|
file_loc = ret_code["filename"]
|
|
print(file_loc)
|
|
|
|
|
|
def save_video(url):
|
|
"""Saves video accoring to url and save path"""
|
|
ydl_opts = {
|
|
'format': 'best[height<=720]',
|
|
'progress_hooks': [post_download_hook],
|
|
'updatetime': False
|
|
}
|
|
try:
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
ydl.download([url])
|
|
except Exception as e:
|
|
print(f"Youtube download crashed: {e}")
|
|
|
|
|
|
for i, url in enumerate(urls):
|
|
print(f"Downloading video {i+1} / {len(urls)}")
|
|
save_video(url)
|