Generate list of youtube links from song titles

I needed to get a list of youtube links from a list of song titles. Thanks to this reddit post I was able to get what I needed. I did have to update it to use yt which is a fork of the referenced mps-youtube package.

After installing yewtube per https://github.com/mps-youtube/yewtube#installation I was able to get what I wanted with this one-liner:

while read song; do echo $song; yt search "$song", i 1, q|grep -i link| awk -F ': ' '{ print $2 }'; done < playlist

The above command looks at a playlist which is only artist & song names, prints the song name to the console for reference, then uses yewtube to search youtube for that song name and select the first result, then grab the link and print it to the screen.

I had to double check that the correct version of the song was selected, but for the most part it did exactly what I needed!

2 thoughts on “Generate list of youtube links from song titles”

  1. im completely hopeless with technology haha, so excuse me if this is a dumb question; where is the playlist “stored” here? is there a text file that the command draws from to inform each search? or did you need to go one at a time?

    1. Great question! The very last word `playlist` is the name of a text file which contains song names. The less than sign before it is instructing the shell to take the contents of the `playlist` file and pass them to the rest of the commands, in this case a while loop which takes every line from that file and does a search on it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.