showprocess.py
· 889 B · Python
Raw
import os
import requests
from XML2Dict import encoder
from sys import argv
apikey = argv[1] # Get your API key from http://www.thetvdb.com/wiki/index.php?title=Programmers_API
dsid = "71256"
crid = "79274"
apiurl = "http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=%s&seriesid=%s&airdate=%s"
xml = encoder.XML2Dict()
for filename in os.listdir('.'):
if ".py" in filename or filename == "XML2Dict":
continue
airdate = "-".join(filename.split(".")[3:6])
if "The.Colbert.Report" in filename:
data = xml.parse(requests.get(apiurl % (apikey, crid, airdate)).text)
os.rename(filename, "The Colbert Report s{SeasonNumber}e{EpisodeNumber}.mp4".format(**data["Data"]["Episode"]))
else:
data = xml.parse(requests.get(apiurl % (apikey, dsid, airdate)).text)
os.rename(filename, "The Daily Show s{SeasonNumber}e{EpisodeNumber}.mp4".format(**data["Data"]["Episode"]))
| 1 | import os |
| 2 | import requests |
| 3 | from XML2Dict import encoder |
| 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 | dsid = "71256" |
| 8 | crid = "79274" |
| 9 | apiurl = "http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=%s&seriesid=%s&airdate=%s" |
| 10 | xml = encoder.XML2Dict() |
| 11 | for filename in os.listdir('.'): |
| 12 | if ".py" in filename or filename == "XML2Dict": |
| 13 | continue |
| 14 | airdate = "-".join(filename.split(".")[3:6]) |
| 15 | if "The.Colbert.Report" in filename: |
| 16 | data = xml.parse(requests.get(apiurl % (apikey, crid, airdate)).text) |
| 17 | os.rename(filename, "The Colbert Report s{SeasonNumber}e{EpisodeNumber}.mp4".format(**data["Data"]["Episode"])) |
| 18 | else: |
| 19 | data = xml.parse(requests.get(apiurl % (apikey, dsid, airdate)).text) |
| 20 | os.rename(filename, "The Daily Show s{SeasonNumber}e{EpisodeNumber}.mp4".format(**data["Data"]["Episode"])) |