Skip to content

Instantly share code, notes, and snippets.

@neoromantique
Created November 24, 2020 20:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoromantique/8513959eb8d12454faae570dce542a2d to your computer and use it in GitHub Desktop.
Save neoromantique/8513959eb8d12454faae570dce542a2d to your computer and use it in GitHub Desktop.
youtube_archiver.py
# Tiny Youtube Archival Helper Script
# David Aizenberg 2020
from __future__ import unicode_literals
import youtube_dl
storagePrefix = '/home/david/NAS/Videos/YouTube/'
downloadArchive = '/home/david/.youtube-dl-archive'
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print(f"{bcolors.OKCYAN}Done downloading: {bcolors.ENDC} {d['filename']}. Converting/Merging")
# title, url, exclude string
channels = [
['PostModernJukebox', 'https://www.youtube.com/channel/UCORIeT1hk6tYBuntEXsguLg', ''],
['TheScienceElf', 'https://www.youtube.com/channel/UCCrnCItH17W-64FDzjwOi5w', ''],
['EngineerGuy', 'https://www.youtube.com/user/engineerguyvideo', ''],
['TomScott', 'https://www.youtube.com/user/enyay', ''],
['TechnologyConnections','https://www.youtube.com/channel/UCy0tKL1T7wFoYcxCe0xjN6Q', ''],
['AdamSavageTested', 'https://www.youtube.com/user/testedcom/', ''],
['Kurzgesagt', 'https://www.youtube.com/user/Kurzgesagt', ''],
['MaxKats', 'https://www.youtube.com/c/maxkatz1', 'NEWS'],
['LexFridman', 'https://www.youtube.com/c/lexfridman', ''],
['LukeSmith', 'https://www.youtube.com/channel/UC2eYFnH61tmytImy1mTYvhA', 'Livestream']
]
for idx,channel in enumerate(channels):
print(f"Channel: {bcolors.BOLD}{idx + 1}/{len(channels)}{bcolors.ENDC}")
print(f"{bcolors.OKGREEN} Hooray!, I'm downloading {channel[0]}! {bcolors.ENDC}")
ydl_opts = {
'format': '(bestvideo[width>=360]/bestvideo)+bestaudio/best',
'outtmpl': storagePrefix + channel[0] + '/%(title)s.%(ext)s',
'logger': MyLogger(),
'download_archive': downloadArchive,
'ignoreerrors': 'true',
'rejecttitle': channel[2],
'merge_output_format': 'mkv',
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([channel[1]])
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment