Skip to content

Instantly share code, notes, and snippets.

@hiway
Created June 29, 2013 13:40
Show Gist options
  • Save hiway/5891133 to your computer and use it in GitHub Desktop.
Save hiway/5891133 to your computer and use it in GitHub Desktop.
You'll need to install lyricwiki and appscript before you can use this script.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from time import sleep
import lyricwiki
import appscript
it = appscript.app('iTunes')
def fetch_and_add_lyrics():
track = it.current_track()
if not track.lyrics():
lyrics = lyricwiki.get_lyrics(track.artist(), track.name())
if lyrics:
track.lyrics.set(lyrics)
print "UPDATED lyrics for ", track.name(), 'by', track.artist()
else:
track.lyrics.set("None")
print "Unable to get lyrics for ", track.name(), 'by', track.artist()
else:
print "Lyrics exist for ", track.name(), 'by', track.artist()
# Uncomment it.next_track() if you want to quickly go through current playlist
# and attempt to add lyrics for everything…
#it.next_track()
try:
while True:
if it.isrunning():
fetch_and_add_lyrics()
sleep(1)
except KeyboardInterrupt:
print "Bye!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment