Friday, November 03, 2017

youtube_tools v2.0: Now with Playlist Management Support

Last month I finally got frustrated enough with YouTube's subscription management tools that I took matters into my own hands and wrote a command line tool to take over the job. Earlier this week I set my sights on a similar problem: playlist management.

I wanted a quick way to rename, delete and extract a YouTube playlist data. Extending my original youtube_tools wasn't that hard. And while I was at it, I added full support for paging.

Here's a few examples of the tool in action. Like most command line tools, uses are limited only by your imagination.

# Get a few playlists to work with
$ youtube_tools -a playlists | tail -5
PL755C43F40CCFC4A3:Songs To Make Shira Smile
PL1ED10A844DF6863C:Rock Music that Rocks
PL629D105C873357DE:Sweet Country Music
PL933A9F07113418D8:Funky Music
FLCsd3dwyF1qnzzmk7vrRbbQ:Favorites

# Rename one
$ youtube_tools -a playlist-rename \
   -i PL629D105C873357DE -n "Totally Sweet Country Music"
PL629D105C873357DE:Totally Sweet Country Music

# See how many entries are in a playlist
$ youtube_tools -a playlist -i PL629D105C873357DE | wc -l
26

# Any by Brooks & Dunn?
youtube_tools -a playlist -i PL629D105C873357DE | grep Brooks
UEw2MjlEMTA1Qzg3MzM1N0RFLjFEMzAyRkUyQjlEQzA3ODI=:nopBvlKfYgY:Brooks And Dunn Neon Moon
UEw2MjlEMTA1Qzg3MzM1N0RFLjFFNjE4RTg3MjUyNTNGOUE=:6gS6NucKt20:Brooks and Dunn - Play Something Country [ New Video + Lyrics + Tab + Download ]

# Generate a list of URLs to watch these videos
$ youtube_tools -a playlist -i PL629D105C873357DE | grep Brooks | 
    cut -d ':' -f 2 |
    while read x ; do echo "http://youtube.com/watch?v=$x";done
http://youtube.com/watch?v=nopBvlKfYgY
http://youtube.com/watch?v=6gS6NucKt20

# Print out the thumbnail images for each these videos
$ youtube_tools -a playlist -i PL629D105C873357DE -v 
  | jq -r '.items[] |  .snippet.thumbnails.high.url + ":" + .snippet.title '|
  grep Brooks
https://i.ytimg.com/vi/nopBvlKfYgY/hqdefault.jpg:Brooks And Dunn Neon Moon
https://i.ytimg.com/vi/6gS6NucKt20/hqdefault.jpg:Brooks and Dunn - Play Something Country [ New Video + Lyrics + Tab + Download ]

# Generate a trivial HTML page that contains all the videos
$echo "<html><body><h1>My Country Playlist</h1>"; 
 youtube_tools -a playlist -i PL629D105C873357DE | cut -d ':' -f 2 |
  while read x ; do
    echo "<iframe src='https://youtube.com/embed/$x' width='560' height='300'></iframe>";
  done;
  echo "</body></html>"
<html><body><h1>My Country Playlist</h1>
<iframe src='https://youtube.com/embed/q3zkkLckeyM' width='560' height='300'></iframe>
<iframe src='https://youtube.com/embed/IO7zCCJ2bXo' width='560' height='300'></iframe>
...

The source code for youtube_tools is found here. Feel free to grab it and hack away.

No comments:

Post a Comment