Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.