Created
May 7, 2012 23:52
-
-
Save amberj/2631500 to your computer and use it in GitHub Desktop.
This (bash) script takes a youtube playlist URL as argument and outputs title and URL of each video (in playlist) in reverse order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# File: rev-youtube-playlist-urls.sh | |
# Description: This (bash) script takes a youtube playlist URL as argument and outputs title and URL of each video (in playlist) in reverse order (i.e. starting from last video in playlist) | |
# Author: Amber Jain | |
# Check if "only one" argument (playlist_url) passed as input: | |
if [ "$#" -lt "1" ] | |
then | |
echo "Invalid! You must pass playlist_url as argument" | |
exit | |
elif [ "$#" -ge "2" ] | |
then | |
echo "Invalid! You must pass only one argument (playlist_url) as input" | |
exit | |
else | |
echo "Processing..." | |
fi | |
# Let us generate titles of videos in playlist in 'titles' file | |
youtube-dl -e "$1" > /tmp/titles | |
# Let us generate urls of videos in playlist in 'urls' file | |
youtube-dl -o "http://www.youtube.com/watch?v=%(id)s" --get-filename "$1" > /tmp/urls | |
# Print file 'titles' in reverse | |
tac /tmp/titles > /tmp/reverse_titles | |
# Print file 'urls' in reverse | |
tac /tmp/urls > /tmp/reverse_urls | |
# merge lines of files 'reverse_titles' and 'reverse_urls' | |
paste -d '\n' /tmp/reverse_titles /tmp/reverse_urls | |
# Let's cleanup temporary files | |
rm /tmp/titles | |
rm /tmp/urls | |
rm /tmp/reverse_titles | |
rm /tmp/reverse_urls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or just:
youtube-dl -j <PLAYLIST_URL> | jq '(.webpage_url, .title)' | tac