Skip to content

Instantly share code, notes, and snippets.

@amberj
Created May 7, 2012 23:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save amberj/2631500 to your computer and use it in GitHub Desktop.
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
#!/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
@zouhair
Copy link

zouhair commented Jan 12, 2022

Or just:

youtube-dl -j <PLAYLIST_URL> | jq '(.webpage_url, .title)' | tac

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