Created
October 17, 2010 18:52
-
-
Save gasi/631131 to your computer and use it in GitHub Desktop.
Add IMDb metadata to mp4 files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
import glob | |
import re | |
from imdb import IMDb | |
from imdb.helpers import sortedEpisodes | |
from subprocess import call | |
imdb = IMDb() | |
files = glob.glob('*.mp4') + glob.glob('*.m4v') | |
items = [] | |
exceptions = {'the big c': '1515193'} | |
for f in files: | |
match = re.search(r'(.*)s(\d+)e(\d+).*', f.replace('_', '.').lower()) | |
item = {'series_title': match.group(1).replace('.', ' ').strip(), | |
'season': int(match.group(2)), | |
'episode': int(match.group(3))} | |
items.append(item) | |
# Exceptions | |
series_title = item['series_title'].lower() | |
if series_title in exceptions: | |
item['id'] = exceptions[series_title] | |
# IMDb lookup | |
if 'id' in item: | |
movie = imdb.get_movie(item['id']) | |
else: | |
movie = imdb.search_movie(item['series_title'])[0] | |
imdb.update(movie, 'episodes') | |
e = movie['episodes'][item['season']][item['episode']] | |
info = {'file': f, | |
'series_title': e['series title'], | |
'title': e['title'], | |
'season': int(e['season']), | |
'episode': int(e['episode']), | |
'year': int(e['year']), | |
'plot': e['plot'] if e.has_key('plot') else ''} | |
print "%(series_title)s - %(title)s (%(year)d)\n\n%(plot)s\n\n---\n"%info | |
call(['./AtomicParsley', | |
info['file'], | |
'--artist', '%(series_title)s'%info, | |
'--albumArtist', '%(series_title)s'%info, | |
'--title', '%(title)s'%info, | |
'--album', '%(series_title)s, Season %(season)d'%info, | |
'--tracknum', '%(episode)d'%info, | |
'--disknum', '1/1', | |
'--year', '%(year)d'%info, | |
'--description', '%(plot)s'%info, | |
'--genre', '', | |
'--stik', 'TV Show', | |
'--TVShowName', '%(series_title)s'%info, | |
'--TVEpisode', 'S%(season)dE%(episode)d'%info, | |
'--TVSeason', '%(season)d'%info, | |
'--TVEpisodeNum', '%(episode)d'%info]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment