Skip to content

Instantly share code, notes, and snippets.

@FiloSottile
Created March 15, 2012 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save FiloSottile/2047687 to your computer and use it in GitHub Desktop.
Save FiloSottile/2047687 to your computer and use it in GitHub Desktop.
Download a youtube playlist using rg3/youtube-dl by @orschiro
import shutil
import os
import sys
import subprocess
import re
# Settings
root_folder = 'C:/Users/Robert/Videos/YouTube/Playlists/'
destination_regex = re.compile(r'^\[download\] Destination: (.*)$', re.M)
def download():
files = open('Playlists.txt').readlines()
for playlist in files:
p = playlist.split(';')
# Create the directory for the playlist if it does not exist yet
my_path = os.path.join(root_folder, p[0])
if not os.path.exists (my_path):
os.makedirs(my_path)
# Download every single video from the given playlist
download_videos = subprocess.Popen([sys.executable, 'youtube-dl.py', '-cit', p[1]],
stdout=subprocess.PIPE)
output = download_videos.communicate()[0]
# After downloading all videos move them into the destination folder
for video in destination_regex.findall(output):
shutil.move(video, my_path)
if __name__ == '__main__':
download()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment