As I mentioned in a previous post of mine, Radio + Me = ❤, I was doing a radio show for over 2 years. During those 2 years, I kept a blog on which I would post the playlist of each show, so that people could find the artist and title of a song they liked, and discover new artists and songs. Just putting the names up is an easy task, but I wanted something more. So I made a Python script that would automatically link the artist’s name to their Last.FM page, and the title to a search on YouTube for that song. That way, discovering more information about the artists, and listening to the song again was easy for the users, and easy for me to maintain.
from Tkinter import Tk stime = raw_input("Time: ") f = open("list.txt", "w") while stime != "": artist = raw_input("Artist: ") title = raw_input("Title: ") artist_y = str.replace(artist, "&", "%26") title_y = str.replace(title, "&", "%26") msg = stime + r' | <a href="http://last.fm/music/' + artist_y + r'">' + artist + r'</a> - <a href="http://www.youtube.com/results?search_query=' + artist_y + " " + title_y + r'&search_type=&aq=f">' + title + '</a><br />' f.write(msg + '\n') stime = raw_input("\nTime: ") f.close
The str.replace(…) commands are there because YouTube doesn’t like “&”or
in the URL, but uses “%26” to represent the ampersand, which works for Last.FM as well. If you try to use the artist and title variables in the URLs, you’ll see that YouTube stops at the first “&” character in the search query, and ignores the rest.
The result is saved in a “list.txt” file in the same folder as the script, and pasting it into a Blogger or WordPress blog post should give you a result like this.
P.S. This script is now in a GitHub repo I’ve created so that I can upload any small scripts that don’t need a repository of their own.