Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamidzr/bfb53f4bfb020bd224c27db5229ae05d to your computer and use it in GitHub Desktop.
Save hamidzr/bfb53f4bfb020bd224c27db5229ae05d 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
@hamidzr
Copy link
Author

hamidzr commented Apr 23, 2017

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