Steven Smith revised this gist . Go to revision
1 file changed, 9 insertions
showprocess.py
| @@ -7,18 +7,27 @@ apikey = argv[1] # Get your API key from http://www.thetvdb.com/wiki/index.php?t | |||
| 7 | 7 | ids = {"The.Daily.Show": "71256", "The.Colbert.Report": "79274", "Craig.Ferguson": "73387"} | |
| 8 | 8 | eplookupurl = "http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=%s&seriesid=%s&airdate=%s" | |
| 9 | 9 | srslookupurl = "http://thetvdb.com/data/series/%s/en.xml" | |
| 10 | + | # I hate working with XML, so let's make them dicts. | |
| 10 | 11 | xml = XML2Dict.encoder.XML2Dict() | |
| 11 | 12 | continuing = False | |
| 13 | + | # iterate over files in current directory | |
| 12 | 14 | for filename in os.listdir('.'): | |
| 15 | + | # iterate over list of shows to process, above | |
| 13 | 16 | for k,v in ids.items(): | |
| 17 | + | # If filename contains one of the keys from the list | |
| 14 | 18 | if k in filename: | |
| 19 | + | # Get the airdate from the filename | |
| 15 | 20 | airdate = "-".join(filename.split(".")[len(k.split(".")):len(k.split("."))+3]) | |
| 16 | 21 | print "[%s] Processing %s" % (k, filename) | |
| 22 | + | # Get episode data from thetvdb | |
| 17 | 23 | data = xml.parse(requests.get(eplookupurl % (apikey, v, airdate)).text) | |
| 24 | + | # Get show data from thetvdb, to get the proper series name | |
| 18 | 25 | data["Data"]["Episode"]["SeriesName"] = xml.parse(requests.get(srslookupurl % v).text)["Data"]["Series"]["SeriesName"] | |
| 19 | 26 | out = "{SeriesName} s{SeasonNumber}e{EpisodeNumber}.".format(**data["Data"]["Episode"]) + filename.split(".")[-1] | |
| 27 | + | # Rename file | |
| 20 | 28 | os.rename(filename, out) | |
| 21 | 29 | print "[%s] Renamed to %s" % (k, out) | |
| 30 | + | # Continue for both for loops, because we've already identified the show. | |
| 22 | 31 | continuing = True | |
| 23 | 32 | continue | |
| 24 | 33 | if continuing: | |
Steven Smith revised this gist . Go to revision
1 file changed, 1 insertion, 1 deletion
showprocess.py
| @@ -6,7 +6,7 @@ from sys import argv | |||
| 6 | 6 | apikey = argv[1] # Get your API key from http://www.thetvdb.com/wiki/index.php?title=Programmers_API | |
| 7 | 7 | ids = {"The.Daily.Show": "71256", "The.Colbert.Report": "79274", "Craig.Ferguson": "73387"} | |
| 8 | 8 | eplookupurl = "http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=%s&seriesid=%s&airdate=%s" | |
| 9 | - | srslookupurl = "http://thetvdb.com/data/series/%s/" | |
| 9 | + | srslookupurl = "http://thetvdb.com/data/series/%s/en.xml" | |
| 10 | 10 | xml = XML2Dict.encoder.XML2Dict() | |
| 11 | 11 | continuing = False | |
| 12 | 12 | for filename in os.listdir('.'): | |
Steven Smith revised this gist . Go to revision
1 file changed, 1 deletion
showprocess.py
| @@ -1,4 +1,3 @@ | |||
| 1 | - | # This latest edit is untested, I'm waiting on new episodes | |
| 2 | 1 | import os | |
| 3 | 2 | import requests | |
| 4 | 3 | import XML2Dict # The PyPI installer doesn't work; get this from http://blha303.com.au/XML2Dict.zip | |
Steven Smith revised this gist . Go to revision
1 file changed, 1 insertion, 1 deletion
showprocess.py
| @@ -13,7 +13,7 @@ continuing = False | |||
| 13 | 13 | for filename in os.listdir('.'): | |
| 14 | 14 | for k,v in ids.items(): | |
| 15 | 15 | if k in filename: | |
| 16 | - | airdate = "-".join(filename.split(".")[len(k.split(".")):len(k.split("."))+3] | |
| 16 | + | airdate = "-".join(filename.split(".")[len(k.split(".")):len(k.split("."))+3]) | |
| 17 | 17 | print "[%s] Processing %s" % (k, filename) | |
| 18 | 18 | data = xml.parse(requests.get(eplookupurl % (apikey, v, airdate)).text) | |
| 19 | 19 | data["Data"]["Episode"]["SeriesName"] = xml.parse(requests.get(srslookupurl % v).text)["Data"]["Series"]["SeriesName"] | |
Steven Smith revised this gist . Go to revision
1 file changed, 21 insertions, 13 deletions
showprocess.py
| @@ -1,20 +1,28 @@ | |||
| 1 | + | # This latest edit is untested, I'm waiting on new episodes | |
| 1 | 2 | import os | |
| 2 | 3 | import requests | |
| 3 | - | from XML2Dict import encoder # The PyPI installer doesn't work; get this from http://blha303.com.au/XML2Dict.zip | |
| 4 | + | import XML2Dict # The PyPI installer doesn't work; get this from http://blha303.com.au/XML2Dict.zip | |
| 4 | 5 | from sys import argv | |
| 5 | 6 | ||
| 6 | 7 | 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() | |
| 8 | + | ids = {"The.Daily.Show": "71256", "The.Colbert.Report": "79274", "Craig.Ferguson": "73387"} | |
| 9 | + | eplookupurl = "http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey=%s&seriesid=%s&airdate=%s" | |
| 10 | + | srslookupurl = "http://thetvdb.com/data/series/%s/" | |
| 11 | + | xml = XML2Dict.encoder.XML2Dict() | |
| 12 | + | continuing = False | |
| 11 | 13 | for filename in os.listdir('.'): | |
| 12 | - | if ".py" in filename or filename == "XML2Dict": | |
| 14 | + | for k,v in ids.items(): | |
| 15 | + | if k in filename: | |
| 16 | + | airdate = "-".join(filename.split(".")[len(k.split(".")):len(k.split("."))+3] | |
| 17 | + | print "[%s] Processing %s" % (k, filename) | |
| 18 | + | data = xml.parse(requests.get(eplookupurl % (apikey, v, airdate)).text) | |
| 19 | + | data["Data"]["Episode"]["SeriesName"] = xml.parse(requests.get(srslookupurl % v).text)["Data"]["Series"]["SeriesName"] | |
| 20 | + | out = "{SeriesName} s{SeasonNumber}e{EpisodeNumber}.".format(**data["Data"]["Episode"]) + filename.split(".")[-1] | |
| 21 | + | os.rename(filename, out) | |
| 22 | + | print "[%s] Renamed to %s" % (k, out) | |
| 23 | + | continuing = True | |
| 24 | + | continue | |
| 25 | + | if continuing: | |
| 26 | + | continuing = False | |
| 13 | 27 | 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"])) | |
| 28 | + | print "Skipping " + filename | |
Steven Smith revised this gist . Go to revision
1 file changed, 1 insertion, 1 deletion
showprocess.py
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | import os | |
| 2 | 2 | import requests | |
| 3 | - | from XML2Dict import encoder | |
| 3 | + | from XML2Dict import encoder # The PyPI installer doesn't work; get this from http://blha303.com.au/XML2Dict.zip | |
| 4 | 4 | from sys import argv | |
| 5 | 5 | ||
| 6 | 6 | apikey = argv[1] # Get your API key from http://www.thetvdb.com/wiki/index.php?title=Programmers_API | |
Steven Smith revised this gist . Go to revision
1 file changed, 20 insertions
showprocess.py(file created)
| @@ -0,0 +1,20 @@ | |||
| 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"])) | |