diff --git a/TVEncoder.py b/TVEncoder.py index 7888a0c..f2142a5 100644 --- a/TVEncoder.py +++ b/TVEncoder.py @@ -28,25 +28,39 @@ def showhelp(): print 'TVEncoder.py -e -l - list the files that would be encoded' -def print_shows(shows, filemanager): +def print_shows(shows): """ Prints he details of the shows. """ + okshows = [] + noepisodes = [] + existingfiles = [] - existing = [] + for show in shows: + showstr = str(show) - for showdata in shows: - if filemanager.checkfileexists(showdata.outputfile): - existing.append(showdata) - else: - print showdata + errors = show.checkproblems() + if not errors: + okshows.append(showstr) + elif "NO_EPISODE" in errors: + noepisodes.append(showstr) + elif "FILE_EXISTS" in errors: + existingfiles.append(showstr) - if len(existing) > 0: - print colored("The following shows have existing output files that " - "need to be fixed before proceeding:\n", 'red') + for show in okshows: + print show - for showdata in existing: - print colored(showdata, 'red') + if noepisodes: + print colored("\nDetails of the episode could not be determined for " + "the following shows:", 'red') + for show in noepisodes: + print colored(show, 'red') + + if existingfiles: + print colored("\nThe following shows have a pre-existing " + "output file:", 'red') + for show in existingfiles: + print colored(show, 'red') def processarguments(options): @@ -93,12 +107,12 @@ def main(argv): if inputoptions.doencode: #Generate the list of files that would be encoded showdata = filemanager.getencodingfiles(inputoptions.readonly) - print_shows(showdata, filemanager) + print_shows(showdata) else: # Generate the list of files to process shows = filemanager.getfilestoprepare(inputoptions.numfiles) print "num results: {0}".format(len(shows)) - print_shows(shows, filemanager) + print_shows(shows) else: if inputoptions.doencode: #Encode the files and move them to their final destination diff --git a/libfilemanager.py b/libfilemanager.py index 439719b..413e2b5 100644 --- a/libfilemanager.py +++ b/libfilemanager.py @@ -28,6 +28,18 @@ class EncodeData: return "Show: {0}\nInput: {1}\nOutput: " \ "{2}\n".format(self.show, self.inputfile, self.outputfile) + def checkproblems(self): + """ + Check the EncodeData object for any potential problems. + """ + + errors = [] + + if os.path.exists(self.outputfile): + errors.append("FILE_EXISTS") + + return errors + class FileManager: """ diff --git a/libtvshow.py b/libtvshow.py index 55ae750..73903a9 100644 --- a/libtvshow.py +++ b/libtvshow.py @@ -5,6 +5,9 @@ Created on Sat Jul 6 20:26:22 2013 @author: shanef """ +import os +#from libfilemanager import FileManager + class TVShow(object): """ @@ -24,3 +27,17 @@ class TVShow(object): def __str__(self): return "Input: {0} -> Output: {1}".format(self.inputfile, self.outputfile) + + def checkproblems(self): + """ + Check the TVShow object for any potential problems. + """ + + errors = [] + if self.episode == "E00" or self.season == "S00" or not self.subtitle: + errors.append("NO_EPISODE") + + if os.path.exists(self.outputfile): + errors.append("FILE_EXISTS") + + return errors diff --git a/tests/libfilemanagertest.py b/tests/libfilemanagertest.py index 4c569e9..c986f73 100644 --- a/tests/libfilemanagertest.py +++ b/tests/libfilemanagertest.py @@ -19,7 +19,7 @@ class libfilemanagertest(unittest.TestCase): inputname = "test input" outputname = "test output" data = EncodeData(showname, inputname, outputname) - result = data.__str__() + result = str(data) expected = "Show: {0}\nInput: {1}\nOutput: " \ "{2}\n".format(showname, inputname, outputname) self.assertEqual(result, expected)