Added checks for potential problems when listing files
This commit is contained in:
42
TVEncoder.py
42
TVEncoder.py
@@ -28,25 +28,39 @@ def showhelp():
|
|||||||
print 'TVEncoder.py -e -l - list the files that would be encoded'
|
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.
|
Prints he details of the shows.
|
||||||
"""
|
"""
|
||||||
|
okshows = []
|
||||||
|
noepisodes = []
|
||||||
|
existingfiles = []
|
||||||
|
|
||||||
existing = []
|
for show in shows:
|
||||||
|
showstr = str(show)
|
||||||
|
|
||||||
for showdata in shows:
|
errors = show.checkproblems()
|
||||||
if filemanager.checkfileexists(showdata.outputfile):
|
if not errors:
|
||||||
existing.append(showdata)
|
okshows.append(showstr)
|
||||||
else:
|
elif "NO_EPISODE" in errors:
|
||||||
print showdata
|
noepisodes.append(showstr)
|
||||||
|
elif "FILE_EXISTS" in errors:
|
||||||
|
existingfiles.append(showstr)
|
||||||
|
|
||||||
if len(existing) > 0:
|
for show in okshows:
|
||||||
print colored("The following shows have existing output files that "
|
print show
|
||||||
"need to be fixed before proceeding:\n", 'red')
|
|
||||||
|
|
||||||
for showdata in existing:
|
if noepisodes:
|
||||||
print colored(showdata, 'red')
|
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):
|
def processarguments(options):
|
||||||
@@ -93,12 +107,12 @@ def main(argv):
|
|||||||
if inputoptions.doencode:
|
if inputoptions.doencode:
|
||||||
#Generate the list of files that would be encoded
|
#Generate the list of files that would be encoded
|
||||||
showdata = filemanager.getencodingfiles(inputoptions.readonly)
|
showdata = filemanager.getencodingfiles(inputoptions.readonly)
|
||||||
print_shows(showdata, filemanager)
|
print_shows(showdata)
|
||||||
else:
|
else:
|
||||||
# Generate the list of files to process
|
# Generate the list of files to process
|
||||||
shows = filemanager.getfilestoprepare(inputoptions.numfiles)
|
shows = filemanager.getfilestoprepare(inputoptions.numfiles)
|
||||||
print "num results: {0}".format(len(shows))
|
print "num results: {0}".format(len(shows))
|
||||||
print_shows(shows, filemanager)
|
print_shows(shows)
|
||||||
else:
|
else:
|
||||||
if inputoptions.doencode:
|
if inputoptions.doencode:
|
||||||
#Encode the files and move them to their final destination
|
#Encode the files and move them to their final destination
|
||||||
|
|||||||
@@ -28,6 +28,18 @@ class EncodeData:
|
|||||||
return "Show: {0}\nInput: {1}\nOutput: " \
|
return "Show: {0}\nInput: {1}\nOutput: " \
|
||||||
"{2}\n".format(self.show, self.inputfile, self.outputfile)
|
"{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:
|
class FileManager:
|
||||||
"""
|
"""
|
||||||
|
|||||||
17
libtvshow.py
17
libtvshow.py
@@ -5,6 +5,9 @@ Created on Sat Jul 6 20:26:22 2013
|
|||||||
@author: shanef
|
@author: shanef
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
#from libfilemanager import FileManager
|
||||||
|
|
||||||
|
|
||||||
class TVShow(object):
|
class TVShow(object):
|
||||||
"""
|
"""
|
||||||
@@ -24,3 +27,17 @@ class TVShow(object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Input: {0} -> Output: {1}".format(self.inputfile,
|
return "Input: {0} -> Output: {1}".format(self.inputfile,
|
||||||
self.outputfile)
|
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
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class libfilemanagertest(unittest.TestCase):
|
|||||||
inputname = "test input"
|
inputname = "test input"
|
||||||
outputname = "test output"
|
outputname = "test output"
|
||||||
data = EncodeData(showname, inputname, outputname)
|
data = EncodeData(showname, inputname, outputname)
|
||||||
result = data.__str__()
|
result = str(data)
|
||||||
expected = "Show: {0}\nInput: {1}\nOutput: " \
|
expected = "Show: {0}\nInput: {1}\nOutput: " \
|
||||||
"{2}\n".format(showname, inputname, outputname)
|
"{2}\n".format(showname, inputname, outputname)
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user