57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
import youtube_dl
|
|
from waybackpy import WaybackMachineSaveAPI # upload to archive.org
|
|
import time
|
|
|
|
|
|
urls = [
|
|
"https://www.youtube.com/watch?v=R4h_yiDIuQE",
|
|
"https://www.youtube.com/watch?v=-G8ZI1Jq8xA",
|
|
"https://www.youtube.com/watch?v=8eYBcASQIQI",
|
|
"https://www.thingiverse.com/thing:5463267",
|
|
"https://www.youtube.com/watch?v=cJoUSHJcV4E&t=0s",
|
|
"https://www.youtube.com/watch?v=UbBYZZBREBA&t=0s",
|
|
"https://www.youtube.com/watch?v=bQQn_vET4ys",
|
|
"https://www.youtube.com/watch?v=6FqNctiO06E",
|
|
"https://www.youtube.com/watch?v=ImnuJgj8XJo",
|
|
"https://www.youtube.com/watch?v=4QZQtSqaC34",
|
|
"https://www.youtube.com/watch?v=cW4qIjPMGkQ",
|
|
"https://www.youtube.com/watch?v=QWsUGpKfP8A",
|
|
"https://www.youtube.com/watch?v=a0PwEwLG9No",
|
|
"https://www.youtube.com/watch?v=Hd3lnWVIIpo",
|
|
"https://www.youtube.com/watch?v=JNtdAp-BdzI",
|
|
"https://en.wikipedia.org/wiki/Viktor_Schauberger",
|
|
"https://de.wikipedia.org/wiki/Viktor_Schauberger",
|
|
]
|
|
def post_download_hook(ret_code):
|
|
# print(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]',
|
|
# 'outtmpl': f"{file_path}.%(ext)s", # basically the filename from the object, but with a custom extension depending on the download
|
|
'progress_hooks': [post_download_hook],
|
|
'updatetime': False
|
|
}
|
|
try:
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
ydl.download([url])
|
|
# article file name is updated in self.post_download_hook
|
|
except Exception as e:
|
|
print(f"Youtube download crashed: {e}")
|
|
|
|
|
|
# for url in urls:
|
|
# save_video(url)
|
|
|
|
for url in urls:
|
|
user_agent = "Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0" # needed?
|
|
wayback = WaybackMachineSaveAPI(url, user_agent)
|
|
archive_url = wayback.save()
|
|
print(archive_url)
|
|
time.sleep(20)
|