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