Last active 1440820570

Script to rename daily show episodes to "<show name> sXXeXX"

Revision 35c9392c6fc43d29ebd9f283ff1b9cae06a7c320

showprocess.py Raw
1import os
2import requests
3import XML2Dict # The PyPI installer doesn't work; get this from http://blha303.com.au/XML2Dict.zip
4from sys import argv
5
6apikey = argv[1] # Get your API key from http://www.thetvdb.com/wiki/index.php?title=Programmers_API
7ids = {"The.Daily.Show": "71256", "The.Colbert.Report": "79274", "Craig.Ferguson": "73387"}
8eplookupurl = "http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=%s&seriesid=%s&airdate=%s"
9srslookupurl = "http://thetvdb.com/data/series/%s/en.xml"
10xml = XML2Dict.encoder.XML2Dict()
11continuing = False
12for filename in os.listdir('.'):
13 for k,v in ids.items():
14 if k in filename:
15 airdate = "-".join(filename.split(".")[len(k.split(".")):len(k.split("."))+3])
16 print "[%s] Processing %s" % (k, filename)
17 data = xml.parse(requests.get(eplookupurl % (apikey, v, airdate)).text)
18 data["Data"]["Episode"]["SeriesName"] = xml.parse(requests.get(srslookupurl % v).text)["Data"]["Series"]["SeriesName"]
19 out = "{SeriesName} s{SeasonNumber}e{EpisodeNumber}.".format(**data["Data"]["Episode"]) + filename.split(".")[-1]
20 os.rename(filename, out)
21 print "[%s] Renamed to %s" % (k, out)
22 continuing = True
23 continue
24 if continuing:
25 continuing = False
26 continue
27 print "Skipping " + filename