Skip to content

Instantly share code, notes, and snippets.

@ShannonScott
Last active July 25, 2019 16:42
Show Gist options
  • Save ShannonScott/85f56c7a447d2edab40b1253f8ae9ab2 to your computer and use it in GitHub Desktop.
Save ShannonScott/85f56c7a447d2edab40b1253f8ae9ab2 to your computer and use it in GitHub Desktop.
[Youtube Playlist List Download] Download a YouTube playlist a a list of URLs. #youtube
# Get a YouTube playlist as a list of URLs
#
# Assumes `youtube-dl` is installed
#
# python3 youtube_list.py
import sys
import json
from subprocess import check_output
output = check_output(['youtube-dl', '-j', '--flat-playlist', sys.argv[1]])
for entry in output.decode('utf-8').split('\n'):
if entry == '':
continue
data = json.loads(entry)
#print('{} - https://youtu.be/{}'.format(data['title'], data['id']))
print('https://youtu.be/{:14} {}'.format(data['id'], data['title']))
@ShannonScott
Copy link
Author

ShannonScott commented Jul 15, 2019

Original Bash Version

youtube-dl -j --flat-playlist $1 | jq -r "[.id, .title] | @tsv" | awk -v FS="," '{printf "https://youtu.be/%s\t%s%s",$1,$2, ORS}'

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment