Archive
Check downloaded movies on imdb.com
Recently, I downloaded a nice pack of horror movies. The pack contained more than a hundred movies :) I wanted to see their IMDB ratings to decide which ones to watch, but typing their titles in the browser would be too much work. Could it be automated?
Solution
Each movie was located in a subdirectory. Here is an extract:
... Subspecies.1991.DVDRip.XviD-NoGrp Terror.Train.1980.DVDRIP.XVID-NoGrp The.Changeling.1980.DVDRip-KooKoo The.Creature.Walks.Among.Us.1956.DVDRip-KooKoo The.Hills.Have.Eyes.1977.DVDRip-KooKoo The.Howling.Special.Edition.1981.XviD.6ch-AC3-FTL The.Monster.Club.1980.DVDRip.DivX-UTOPiA ...
Fortunately, the directories were named in a consistent way: title of the movie (words separated with a dot), year, extra info. Thus, extracting titles was very easy. Idea: collect the titles in a list and open them in Firefox on imdb.com, each in a new tab.
First, I redirected the directory list in a file. It was easier to work with a text file than doing globbing:
ls >a.txt
And finally, here is the script:
#!/usr/bin/env python
import re
import urllib
import webbrowser
base = 'http://www.imdb.com/find?s=all'
firefox = webbrowser.get('firefox')
f1 = open('a.txt', 'r')
for line in f1:
line = line.rstrip('\n')
if line.startswith('#'):
continue
# else
result = re.search(r'(.*)\.\d{4}\..*', line)
if result:
address = result.group(1).replace('.', ' ')
url = "%s&q=%s" % ( base, urllib.quote(address) )
print url
firefox.open_new_tab(url)
#webbrowser.open_new_tab(url) # try this if the line above doesn't work
f1.close()
Achtung! Don’t try it with a huge list, otherwise your system will die :) Firefox won’t handle too many open tabs… Try to open around ten titles at a time. In the input file (a.txt) you can comment lines by adding a leading ‘#‘ sign, thus those lines will be discarded by the script.
