Added a check to search the output directories for duplicate video files

This commit is contained in:
2013-07-23 23:59:30 +10:00
parent 5ae07c01e7
commit 5ef02c1e8e
4 changed files with 53 additions and 18 deletions

View File

@@ -31,6 +31,7 @@ def showhelp():
'files that will be processed without actually encoding them' 'files that will be processed without actually encoding them'
print 'TVEncoder.py -e - encode the files that have been processed' print 'TVEncoder.py -e - encode the files that have been processed'
print 'TVEncoder.py -e -l - list the files that would be encoded' print 'TVEncoder.py -e -l - list the files that would be encoded'
print 'TVEncoder.py -c - check the output directories for duplicates'
def print_shows(shows): def print_shows(shows):
@@ -74,9 +75,11 @@ def processarguments(options):
""" """
inputoptions = namedtuple("inputoptions", inputoptions = namedtuple("inputoptions",
"numfiles doencode readonly dolist") "numfiles doencode readonly dolist "
"checkduplicates")
inputoptions.readonly = False inputoptions.readonly = False
inputoptions.checkduplicates = False
for opt, arg in options: for opt, arg in options:
if opt == '-h': if opt == '-h':
@@ -90,6 +93,8 @@ def processarguments(options):
inputoptions.numfiles = arg inputoptions.numfiles = arg
elif opt == "-l": elif opt == "-l":
inputoptions.readonly = True inputoptions.readonly = True
elif opt == "-c":
inputoptions.checkduplicates = True
return inputoptions return inputoptions
@@ -99,7 +104,7 @@ def main(argv):
The main program for TVEncoder. The main program for TVEncoder.
""" """
try: try:
opts, _ = getopt.getopt(argv, "hlpen:") opts, _ = getopt.getopt(argv, "hlpecn:")
except getopt.GetoptError: except getopt.GetoptError:
showhelp() showhelp()
sys.exit(2) sys.exit(2)
@@ -108,6 +113,16 @@ def main(argv):
settings = Settings(SETTINGS) settings = Settings(SETTINGS)
filemanager = FileManager(settings) filemanager = FileManager(settings)
if inputoptions.checkduplicates:
print "Searching for duplicates..."
duplicates = filemanager.checkexistingduplicates()
if duplicates:
for duplicate in duplicates:
print duplicate
else:
print "No duplicates found."
return
if inputoptions.readonly: if inputoptions.readonly:
if inputoptions.doencode: if inputoptions.doencode:
#Generate the list of files that would be encoded #Generate the list of files that would be encoded

View File

@@ -112,6 +112,26 @@ class FileManager:
#will reach here if there were less than numberofFiles found #will reach here if there were less than numberofFiles found
return showstoprocess return showstoprocess
def checkexistingduplicates(self):
"""
Check the existing files in the output directories for duplicate
files, typically in different formats
"""
duplicates = []
for show in self.__settings.getshownames():
outputdir = self.__settings.getshowoutputdirectory(show)
for rootdir, dirnames, filenames in os.walk(outputdir):
for fle in filenames:
filename = os.path.join(rootdir, fle)
if os.path.splitext(fle)[1] in [".avi", ".mpg", ".mpeg",
"mp4", ".mkv"]:
if self.checkduplicates(filename):
duplicates.append(filename)
return duplicates
@staticmethod @staticmethod
def checkduplicates(filename): def checkduplicates(filename):
""" """
@@ -120,13 +140,16 @@ class FileManager:
""" """
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
filename = os.path.basename(filename)[:6] filename = os.path.basename(filename)
fileseasonepisode = filename[:6]
fileextension = os.path.splitext(filename)[1]
for _, _, filenames in os.walk(dirname): for _, _, filenames in os.walk(dirname):
for show in filenames: for show in filenames:
extension = os.path.splitext(show)[1] extension = os.path.splitext(show)[1]
if (extension in [".avi", ".mpg", ".mpeg", "mp4"] and if (extension in [".avi", ".mpg", ".mpeg", "mp4", ".mkv"] and
show[:6] == filename): show[:6] == fileseasonepisode
and fileextension != extension):
return True return True
return False return False

View File

@@ -8,19 +8,6 @@ Created on Fri Jul 5 20:14:15 2013
from configobj import ConfigObj from configobj import ConfigObj
#==============================================================================
# class ShowSettings:
# """
# Container for the settings for a show
# """
#
# def __init__(self, name, inputdirectory, outputdirectory):
# self.name = name
# self.inputdirectory = inputdirectory
# self.outputdirectory = outputdirectory
#==============================================================================
class Settings: class Settings:
""" """
Accessor for the configuration file Accessor for the configuration file

View File

@@ -66,6 +66,16 @@ class libfilemanagertest(unittest.TestCase):
self.assertFalse(result) self.assertFalse(result)
def test_checkduplicatesameextension(self):
settings = Mock('libsettings.Settings')
filemanager = FileManager(settings)
os.walk = dummywalk
result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.avi")
self.assertFalse(result)
def dummywalk(arg): def dummywalk(arg):
return [("/path/to/", [], ["S03E14 - Test - SD TV.avi"])] return [("/path/to/", [], ["S03E14 - Test - SD TV.avi"])]