diff --git a/TVEncoder.py b/TVEncoder.py index 607dc0b..57ba313 100644 --- a/TVEncoder.py +++ b/TVEncoder.py @@ -7,12 +7,12 @@ Created on Fri Jul 5 14:14:22 2013 import sys import getopt -import libfilemanager +from libfilemanager import FileManager from libsettings import Settings from libhandbrake import Encoder import libtvdatasource -TVRECORDINGSDIR = "/Volumes/TV Recordings/" +#TVRECORDINGSDIR = "/Volumes/TV Recordings/" #TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings def ShowHelp(): @@ -55,37 +55,42 @@ def main(argv): readOnly = True doList = True - showSettings = Settings("settings.xml") # TODO call actual settings file + settings = Settings("settings.cfg") if readOnly and doList: if doEncode: #Generate the list of files that would be encoded - showData = libfilemanager.GetEncodingFiles(showSettings, readOnly) + fileManager = FileManager(settings) + showData = fileManager.GetEncodingFiles(readOnly) PrintShowsToEncode(showData) else: # Generate the list of files to process - tempShowList = ["Thomas and Friends", "Thomas the Tank Engine & Friends", - "Chuggington", "Mike the Knight", "Octonauts", - "The Octonauts", "In the Night Garden", - "Raa Raa! The Noisy Lion"] # TODO get from settings - shows = libfilemanager.GetFilesToPrepare(TVRECORDINGSDIR, numFiles, tempShowList) +# tempShowList = ["Thomas and Friends", "Thomas the Tank Engine & Friends", +# "Chuggington", "Mike the Knight", "Octonauts", +# "The Octonauts", "In the Night Garden", +# "Raa Raa! The Noisy Lion"] # TODO get from settings + fileManager = FileManager(settings) + shows = fileManager.GetFilesToPrepare(numFiles) print "num results: {0}".format(len(shows)) PrintShowsToPrepare(shows) else: if doEncode: #Encode the files and move them to their final destination - showData = libfilemanager.GetEncodingFiles(shows, readOnly) + fileManager = FileManager(settings) + showData = fileManager.GetEncodingFiles(readOnly) for show in showData: - if libfilemanager.CheckFileExists(show.outputFile): + if fileManager.CheckFileExists(show.outputFile): print "File {0} already exists. Cannot process.".format(show.outputFile) else: - result = Encoder.Encode(show.inputFile, show.outputFile) + encoder = Encoder(settings.HandbrakeCommand) + result = encoder.Encode(show.inputFile, show.outputFile) - libfilemanager.PerformPostEncodeFileOperations(show.inputFile, show.outputFile) + fileManager.PerformPostEncodeFileOperations(show.inputFile, show.outputFile) else: # TODO Process files for encoding - shows = libfilemanager.GetFilesToPrepare(TVRECORDINGSDIR, numFiles, shows) + fileManager = FileManager(settings) + shows = fileManager.GetFilesToPrepare(numFiles) libtvdatasource.PrepareEpisodes(shows) if __name__ == "__main__": diff --git a/libfilemanager.py b/libfilemanager.py index c87551e..04c718b 100644 --- a/libfilemanager.py +++ b/libfilemanager.py @@ -6,12 +6,12 @@ Created on Fri Jul 5 14:11:31 2013 """ import glob -import libtvdatasource as TVData +from libtvdatasource import TVData import os import shutil #move this to settings -TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" +#TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" class EncodeData: inputFile = '' @@ -21,80 +21,85 @@ class EncodeData: def ToString(self): return "Input: {0}/tOutput: {2}".format(self.inputFile, self.outputFile) - -def __GetInputFilesToEncode(shows): - fileList = [] +class FileManager: + def __init__(self, settings): + self.settings = settings + + def __GetInputFilesToEncode(self): + fileList = [] + + for show in self.settings.GetShowNames(): + for r,d,f in os.walk(show.GetShowInputDirectory(show)): + for files in f: + if files.endswith(".mpg"): + data = EncodeData() + data.show = show + data.inputFile = os.path.join(r,files) + fileList.append(data) + + return fileList - for show in shows: - for r,d,f in os.walk(show.inputDirectory): - for files in f: - if files.endswith(".mpg"): - data = EncodeData() - data.show = show - data.inputFile = os.path.join(r,files) - fileList.append(data) + def __FindSeason(self, path, fileName, readOnly): + season = "Season {0}".format(fileName[1:3]) + seasonPath = os.path.join(path, season) - return fileList - -def __FindSeason(path, fileName, readOnly): - season = "Season {0}".format(fileName[1:3]) - seasonPath = os.path.join(path, season) - - if not readOnly: - if not os.path.exists(seasonPath): - os.makedirs(seasonPath) + if not readOnly: + if not os.path.exists(seasonPath): + os.makedirs(seasonPath) + + return seasonPath - return seasonPath - -def __GetEncodeOutputFile(showData, readOnly): - inFile = os.path.basename(showData.inputFile) - outFilename = inFile[:-3]+"mkv" - outPath = __FindSeason(showData.show.outputDirectory, outFilename) - showData.outputFile = os.path.join(outPath, outFilename) + def __GetEncodeOutputFile(self, inputFile, showName, readOnly): + inFile = os.path.basename(inputFile) + outFilename = inFile[:-3]+"mkv" + outPath = self.__FindSeason(self.settings.GetShowOutputFile(showName), outFilename) + return os.path.join(outPath, outFilename) - return showData - -def GetEncodingFiles(shows, readOnly=True): - showsData = __GetInputFilesToEncode(shows) - for showData in showsData: - showsData = __GetEncodeOutputFile(showData, readOnly) + def GetEncodingFiles(self, readOnly=True): + showsData = self.__GetInputFilesToEncode(self.settings.GetShowNames()) + for showData in showsData: + showData.outputFile = self.__GetEncodeOutputFile(showData.inputFile, showData.name, readOnly) + + return showsData - return showsData - -def CheckFileExists(file): - return os.path.isfile(file) + def CheckFileExists(self, file): + return os.path.isfile(file) + + def __GetRecordingFile(self, fileName): + return os.path.join(self.settings.TVRecordingDirectory, os.path.dirname(fileName).split("/")[-1] + ".mpg") + + def PerformPostEncodeFileOperations(self, inputFileName, outputFileName): + shutil.rmtree(os.path.dirname(inputFileName)) -def __GetRecordingFile(fileName): - return os.path.join(TVRECORDINGSDIR, os.path.dirname(fileName).split("/")[-1] + ".mpg") + linkAddress = self.__GetRecordingFile(inputFileName) -def PerformPostEncodeFileOperations(inputFileName, outputFileName): - shutil.rmtree(os.path.dirname(inputFileName)) - - linkAddress = __GetRecordingFile(inputFileName) - - os.remove(linkAddress) - - os.symlink(outputFileName, linkAddress) - -def GetFilesToPrepare(path, numberofFiles, shows): - files = glob.glob("{0}*.mpg".format(path)) - files = sorted(files, key=os.path.getctime) - files = filter(lambda file: not os.path.islink(file), files) + os.remove(linkAddress) - #files is now a list of unprocessed files, but contains shows other than those we are interested in + os.symlink(outputFileName, linkAddress) - showsToProcess = [] - i = 0 - print "Found {0} potential files".format(len(files)) - for file in files: - # TODO get these from settings - #if TVData.CheckTitleIsInList('localhost', 'script', 'script', 'mythconverg', file): - showData = TVData.RetrieveEpisodeData('192.168.0.2', 'script', 'script', 'mythconverg', file, shows, '192.168.0.2', '8081', '3678177136222bf5002be209220ccb20') # TODO all these settings need to move to settings - if showData: - showsToProcess.append(showData) - i = i + 1 - if i == int(numberofFiles): - return showsToProcess - - return showsToProcess #will reach here if there were less than numberofFiles found + def GetFilesToPrepare(self, numberofFiles): + path = self.settings.TVRecordingDirectory() + files = glob.glob("{0}*.mpg".format(path)) + files = sorted(files, key=os.path.getctime) + files = filter(lambda file: not os.path.islink(file), files) + + #files is now a list of unprocessed files, but contains shows other than those we are interested in + + showsToProcess = [] + i = 0 + print "Found {0} potential files".format(len(files)) + + tvData = TVData(self.settings) + + for file in files: + # TODO get these from settings + #if TVData.CheckTitleIsInList('localhost', 'script', 'script', 'mythconverg', file): + showData = tvData.RetrieveEpisodeData(file) + if showData: + showsToProcess.append(showData) + i = i + 1 + if i == int(numberofFiles): + return showsToProcess + + return showsToProcess #will reach here if there were less than numberofFiles found \ No newline at end of file diff --git a/libhandbrake.py b/libhandbrake.py index f077fa0..c32e940 100644 --- a/libhandbrake.py +++ b/libhandbrake.py @@ -10,20 +10,25 @@ Library to interface with handbrake to encode video files import logging import subprocess -HANDBRAKECOMMAND = ['HandBrakeCLI', '--verbose', '-i', - "SUBSTITUTE WITH INPUT FILE", '-o', - "SUBSTITUDE WITH OUTPUT FILE", '-f', 'mkv', '-e', 'x264', - '-x264-preset', 'slower', '-x264-tune', 'animation', '-q', - '20', '--loose-anamorphic', '--decomb', '--detelecine', - '--denoise="2:1:2:3"', '--deblock'] +#============================================================================== +# HANDBRAKECOMMAND = ['HandBrakeCLI', '--verbose', '-i', +# "SUBSTITUTE WITH INPUT FILE", '-o', +# "SUBSTITUDE WITH OUTPUT FILE", '-f', 'mkv', '-e', 'x264', +# '-x264-preset', 'slower', '-x264-tune', 'animation', '-q', +# '20', '--loose-anamorphic', '--decomb', '--detelecine', +# '--denoise="2:1:2:3"', '--deblock'] +#============================================================================== class Encoder: - def Encode(input, output, waitForCompletion=True, logger=None): - HANDBRAKECOMMAND[3] = input - HANDBRAKECOMMAND[5] = output + def __init__(self, handbrakeCommand): + self.handbrakeCommand = handbrakeCommand + + def Encode(self, input, output, waitForCompletion=True, logger=None): + self.handbrakeCommand[3] = input + self.handbrakeCommand[5] = output - logger.debug("Handbrake command is: {0}".format(HANDBRAKECOMMAND)) - process = subprocess.Popen(HANDBRAKECOMMAND) + logger.debug("Handbrake command is: {0}".format(self.handbrakeCommand)) + process = subprocess.Popen(self.handbrakeCommand) if waitForCompletion: process.wait() diff --git a/libmythtv.py b/libmythtv.py index 5838849..8d10a38 100644 --- a/libmythtv.py +++ b/libmythtv.py @@ -8,14 +8,25 @@ Created on Fri Jul 5 14:10:47 2013 import MySQLdb as mdb from libtvshow import TVShow -def RetrieveEpisodeData(serverAddress, user, password, database, inputFile): - con = mdb.connect(serverAddress, user, password, database) +class MythTV: + def __init__(self, settings): + self.settings = settings - with con: - cur = con.cursor(mdb.cursors.DictCursor) - cur.execute("select episode, season, title, subtitle, description from mythconverg.recorded where basename = '{0}'".format(inputFile)) - result = cur.fetchone() - #print result + def RetrieveEpisodeData(self, inputFile): + con = mdb.connect(self.settings.MythTVAddress(), self.settings.MythTVUser(), self.settings.MythTVPassword(), self.settings.MythTVDatabase()) - return TVShow(result['episode'], result['season'], result['title'], result['subtitle'], result['description']) + with con: + cur = con.cursor(mdb.cursors.DictCursor) + cur.execute("select episode, season, title, subtitle, description from mythconverg.recorded where basename = '{0}'".format(inputFile)) + result = cur.fetchone() + #print result + + return TVShow(result['episode'], result['season'], result['title'], result['subtitle'], result['description']) + + def FixMythTVEpisodeName(self, showName, episodeTitle): + for prefix in self.settings.GetShowMythTVEpisodePrefix(showName): + if episodeTitle.lower().startswith(prefix.lower()): + return episodeTitle[len(prefix):] + + return episodeTitle #didn't find anything so return the episode title \ No newline at end of file diff --git a/libsettings.py b/libsettings.py index c20a3b2..584696b 100644 --- a/libsettings.py +++ b/libsettings.py @@ -5,7 +5,7 @@ Created on Fri Jul 5 20:14:15 2013 @author: shanef """ -from xml.etree import ElementTree +from configobj import ConfigObj class ShowSettings: def __init__(self, name, inputDirectory, outputDirectory): @@ -13,15 +13,98 @@ class ShowSettings: self.inputDirectory = inputDirectory self.outputDirectory = outputDirectory + class Settings: def __init__(self, settingsFile): - self.shows = self.LoadSettings(settingsFile) + self.__config = ConfigObj(settingsFile) - def LoadSettings(self, source): - shows = [] - settingsXml = ElementTree.parse(source).getroot() + def TVRecordingDirectory(self): + return self.__config["TVRecordings"] - for show in settingsXml.findall('show'): - newShow = ShowSettings(show[0].text, show[1].text, show[2].text) - shows.append(newShow) - return shows \ No newline at end of file + def HandbrakeCommand(self): + return self.__config["HandbrakeCommand"] + + def MythTVAddress(self): + return self.__config["MythTV"]["address"] + + def MythTVUser(self): + return self.__config["MythTV"]["user"] + + def MythTVPassword(self): + return self.__config["MythTV"]["password"] + + def MythTVDatabase(self): + return self.__config["MythTV"]["database"] + + def SickbeardAddress(self): + return self.__config["Sickbeard"]["address"] + + def SickbeardPort(self): + return int(self.__config["Sickbeard"]["port"]) + + def SickbeardAPIKey(self): + return self.__config["Sickbeard"]["APIKey"] + + def UnknownDirectory(self): + return self.__config["Shows"]["UnknownInput"] + + def GetShowNames(self, includeAlias=False): + shows = self.__config["Shows"].sections + result = shows[:] + if includeAlias: + for show in shows: + for alias in self.__config["Shows"][show]["alias"]: + result.append(alias) + return result + + def GetShowInputDirectory(self, showName): + show = self.__GetShowSubsection(showName) + if show is None: + return "" + else: + return show["InputDirectory"] + + def GetShowOutputDirectory(self, showName): + show = self.__GetShowSubsection(showName) + if show is None: + return "" + else: + return show["OutputDirectory"] + + def GetShowAlias(self, showName): + show = self.__GetShowSubsection(showName) + if show is None: + return "" + else: + return show["alias"] + + def GetShowMythTVEpisodePrefix(self, showName): + show = self.__GetShowSubsection(showName) + if show is None: + return "" + else: + return show["MythTvEpisodePrefix"] + + def GetShowSickbeardEpisodePrefix(self, showName): + show = self.__GetShowSubsection(showName) + if show is None: + return "" + else: + return show["SickbeardPrefix"] + + def GetShow(self, showName): + showSection = self.__GetShowSubsection(showName) + if showSection is None: + return None + else: + return showSection.name + + def __GetShowSubsection(self, showName): + if showName in self.GetShowNames(): + return self.__config["Shows"][showName] + else: # check liases + for show in self.GetShowNames(): + if showName in self.__config["Shows"][show]["alias"]: + return self.__config["Shows"][show] + + return None \ No newline at end of file diff --git a/libsickbeard.py b/libsickbeard.py index 6fe27b0..d64bdde 100644 --- a/libsickbeard.py +++ b/libsickbeard.py @@ -12,13 +12,14 @@ from fuzzywuzzy import fuzz from operator import itemgetter class Sickbeard: - def __init__(self, address, port, apikey): - self.address = address - self.port = port - self.apikey = apikey + def __init__(self, settings): + self.__settings = settings + self.__address = settings.SickbeardAddress() + self.__port = settings.SickbeardPort() + self.__apikey = settings.SickbeardAPIKey() def __GetApiURL(self): - return "http://{0}:{1}/api/{2}/".format(self.address, self.port, self.apikey) + return "http://{0}:{1}/api/{2}/".format(self.__address, self.__port, self.__apikey) def FindShowId(self, showName): jsonurl = urlopen(self.__GetApiURL()+"?cmd=shows") @@ -42,10 +43,11 @@ class Sickbeard: def FindEpisodeByDescription(self, showId, season, episode, description): jsonEpisodeUrl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}&episode={3}".format(self.__GetApiURL(), showId, season, episode)) episodeResult = json.loads(jsonEpisodeUrl.read()) - - if fuzz.ratio(episodeResult['data']['description'].lower(), description.lower()) > 85: - return (season, episode, episodeResult['data']['name']) + sickbeardDescription = episodeResult['data']['description'] + if fuzz.ratio(sickbeardDescription.lower(), description.lower()) > 85 or fuzz.ratio(sickbeardDescription.lower()[:len(description)], description.lower()) > 85 or fuzz.ratio(sickbeardDescription.lower(), description.lower()[:len(sickbeardDescription)]) > 85: + return (season, episode, episodeResult['data']['name']) + return None def FindEpisode(self, showId, name=None, description=None): @@ -54,8 +56,8 @@ class Sickbeard: for season in result['data']: for episode in result['data'][season]: - if name is not None and name.lower() == result['data'][season][episode]['name'].lower(): - return (season, episode, name) + if name is not None and fuzz.partial_ratio(name.lower(), result['data'][season][episode]['name'].lower()) > 90: + return (season, episode, result['data'][season][episode]['name']) elif description is not None: descriptionQueryResult = self.FindEpisodeByDescription(showId, season, episode, description) if descriptionQueryResult is not None: @@ -63,8 +65,18 @@ class Sickbeard: return (0, 0, '') - def GetEpisodeName(subtitle, showName): - if subtitle[:len(showName)].lower() == showName.lower(): - return subtitle[len(showName + ' and the '):] - else: - return subtitle \ No newline at end of file +#============================================================================== +# def GetEpisodeName(subtitle, showName): +# if subtitle[:len(showName)].lower() == showName.lower(): +# return subtitle[len(showName + ' and the '):] +# else: +# return subtitle +#============================================================================== + + def FixEpisodeTitle(self, showName, episodeTitle): + sickbeardPrefix = self.__settings.GetShowSickbeardEpisodePrefix(showName) + if sickbeardPrefix != "": + if not episodeTitle.lower.startswith(sickbeardPrefix.lower()): + return "{0} {1}".format(sickbeardPrefix.rstrip(), episodeTitle.lstrip()) + + return episodeTitle \ No newline at end of file diff --git a/libtvdatasource.py b/libtvdatasource.py index b964852..339d6a9 100644 --- a/libtvdatasource.py +++ b/libtvdatasource.py @@ -5,116 +5,131 @@ Created on Fri Jul 5 14:42:47 2013 @author: shanef """ -import libmythtv as MythTV +from libmythtv import MythTV from libsickbeard import Sickbeard import os import shutil # TODO Move these to settings -PROCESSDIR="/srv/storage2/files/VideoProcessing/" -THOMAS="Thomas" -CHUGGINGTON="Chuggington" -MIKE="MikeTheKnight" -OCTONAUTS="Octonauts" -NIGHTGARDEN="InTheNightGarden" -RAARAA="RaaRaa" -INPUTDIR="Input" +#PROCESSDIR="/srv/storage2/files/VideoProcessing/" +#THOMAS="Thomas" +#CHUGGINGTON="Chuggington" +#MIKE="MikeTheKnight" +#OCTONAUTS="Octonauts" +#NIGHTGARDEN="InTheNightGarden" +#RAARAA="RaaRaa" +#INPUTDIR="Input" -def FixEpisodeSeasonNumber(number): - if len(number) == 1: - return "0{0}".format(number) - else: - return number - -def GetDirectory(title, season): - directory = "" - if title == "Thomas and Friends" or title == "Thomas the Tank Engine & Friends": - directory = THOMAS - elif title == "Chuggington": - directory = CHUGGINGTON - elif title == "Mike the Knight": - directory = MIKE - elif title == "Octonauts" or title == "The Octonauts": - directory = OCTONAUTS - elif title == "In the Night Garden": - directory = NIGHTGARDEN - elif title == "Raa Raa! The Noisy Lion": - directory = RAARAA - else: - print "Didn't match" - - return os.path.join(PROCESSDIR, directory, INPUTDIR, season) +class TVData: + def __init__(self, settings): + self.settings = settings -def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, showsToProcess, sickbeardAddress, sickbeardPort, sickbeardAPIKey): - file = os.path.basename(inputFile) - show = MythTV.RetrieveEpisodeData(serverAddress, user, password, database, file) + def FixEpisodeSeasonNumber(self, number): + if len(number) == 1: + return "0{0}".format(number) + else: + return number - if show.title and show.title in showsToProcess: - if show.subtitle: - show.subtitle = GetEpisodeName(show.subtitle, show.title) - - if (show.season == "0" or show.episode == "0"): - sickbeard = Sickbeard(sickbeardAddress, sickbeardPort, sickbeardAPIKey) - showId = sickbeard.FindShowId(show.title) - - result = sickbeard.FindEpisode(showId, show.subtitle, show.description) - show.season = str(result[0]) - show.episode = str(result[1]) - show.subtitle = result[2] - - if show.season != "0" and show.episode != "0": - show.season = FixEpisodeSeasonNumber(show.season) - show.episode = FixEpisodeSeasonNumber(show.episode) - - seasonFolder = "Season {0}".format(show.season) - season = "S{0}".format(show.season) - episode = "E{0}".format(show.episode) - renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) - - directory = GetDirectory(show.title, seasonFolder) - - show.outputFile = os.path.join(directory, file[:-4], renamedFile) - show.inputFile = inputFile - - return show - else: - return None - -def CheckTitleIsInList(serverAddress, user, password, database, inputFile): - """Check that inputFile is a recording of a show that is to be processed.""" - file = os.path.basename(inputFile) - show = MythTV.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file) - - # TODO get this from settings - if show.title in ["Thomas and Friends", "Thomas the Tank Engine & Friends", - "Chuggington", "Mike the Knight", "Octonauts", - "The Octonauts", "In the Night Garden", - "Raa Raa! The Noisy Lion"]: - return True - else: - return False - -def DetermineTargetFilename(directory, filename, inputFilename): - dir = os.path.join(directory, inputFilename[:-4]) - - if not os.path.exists(dir): - os.makedirs(dir) - - return os.path.join(dir, filename) - -def GetEpisodeName(subtitle, showName): - if subtitle[:len(showName)].lower() == showName.lower(): - return subtitle[len(showName + ' and the '):] - else: - return subtitle - -def ProcessEpisode(inputFile, outputFile): - outputdir = os.path.dirname(outputFile) - if not os.path.exists(outputdir): - os.makedirs(outputdir) + def GetDirectory(self, title, season): + show = self.settings.GetShow(title) + if not show or show == "": + print "Couldn't find show for {0}".format(title) + return self.settings.UnknownDirectory() + else: + return os.path.join(self.settings.GetShowInputDirectory(show), season) +#============================================================================== +# if title == "Thomas and Friends" or title == "Thomas the Tank Engine & Friends": +# directory = THOMAS +# elif title == "Chuggington": +# directory = CHUGGINGTON +# elif title == "Mike the Knight": +# directory = MIKE +# elif title == "Octonauts" or title == "The Octonauts": +# directory = OCTONAUTS +# elif title == "In the Night Garden": +# directory = NIGHTGARDEN +# elif title == "Raa Raa! The Noisy Lion": +# directory = RAARAA +# else: +# print "Didn't match" +#============================================================================== - shutil.move(inputFile, outputFile) - -def PrepareEpisodes(showsData): - for showData in showsData: - ProcessEpisode(showData.inputFile, showData.outputFile) \ No newline at end of file +# return os.path.join(PROCESSDIR, directory, INPUTDIR, season) + + def RetrieveEpisodeData(self, inputFile): + file = os.path.basename(inputFile) + + mythTv = MythTV(self.settings) + show = mythTv.RetrieveEpisodeData(file) + + showsToProcess = self.settings.GetShowNames(True) + + if show.title and show.title in showsToProcess: + show.title = self.settings.GetShow(show.title) + + if (show.season == "0" or show.episode == "0"): + sickbeard = Sickbeard(self.settings) + showId = sickbeard.FindShowId(show.title) + + if show.subtitle is not None and show.subtitle: + show.subtitle = mythTv.FixMythTVEpisodeName(show.title, show.subtitle) + show.subtitle = sickbeard.FixEpisodeTitle(show.title, show.subtitle) + + result = sickbeard.FindEpisode(showId, show.subtitle, show.description) + show.season = str(result[0]) + show.episode = str(result[1]) + show.subtitle = result[2] + + if show.season != "0" and show.episode != "0": + show.season = self.FixEpisodeSeasonNumber(show.season) + show.episode = self.FixEpisodeSeasonNumber(show.episode) + + seasonFolder = "Season {0}".format(show.season) + season = "S{0}".format(show.season) + episode = "E{0}".format(show.episode) + renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) + + directory = self.GetDirectory(show.title, seasonFolder) + + show.outputFile = os.path.join(directory, file[:-4], renamedFile) + show.inputFile = inputFile + + return show + else: + return None + +#============================================================================== +# def CheckTitleIsInList(serverAddress, user, password, database, inputFile): +# """Check that inputFile is a recording of a show that is to be processed.""" +# file = os.path.basename(inputFile) +# show = MythTV.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file) +# +# # TODO get this from settings +# if show.title in ["Thomas and Friends", "Thomas the Tank Engine & Friends", +# "Chuggington", "Mike the Knight", "Octonauts", +# "The Octonauts", "In the Night Garden", +# "Raa Raa! The Noisy Lion"]: +# return True +# else: +# return False +#============================================================================== + + def DetermineTargetFilename(directory, filename, inputFilename): + dir = os.path.join(directory, inputFilename[:-4]) + + if not os.path.exists(dir): + os.makedirs(dir) + + return os.path.join(dir, filename) + + + def ProcessEpisode(inputFile, outputFile): + outputdir = os.path.dirname(outputFile) + if not os.path.exists(outputdir): + os.makedirs(outputdir) + + shutil.move(inputFile, outputFile) + + def PrepareEpisodes(self, showsData): + for showData in showsData: + self.ProcessEpisode(showData.inputFile, showData.outputFile) \ No newline at end of file diff --git a/settings.cfg b/settings.cfg new file mode 100644 index 0000000..8f142d5 --- /dev/null +++ b/settings.cfg @@ -0,0 +1,52 @@ +TVRecordings = "/Volumes/TV Recordings/" +HandbrakeCommand = "HandBrakeCLI", "--verbose", "-i", "SUBSTITUTE WITH INPUT FILE", "-o", "SUBSTITUDE WITH OUTPUT FILE", "-f", "mkv", "-e", "x264", "-x264-preset", "slower", "-x264-tune", "animation", "-q", "20", "--loose-anamorphic", "--decomb", "--detelecine", '--denoise="2:1:2:3"', "--deblock" + +[ "MythTV" ] + address = 192.168.0.2 + user = script + password = script + database = mythconverg + +[ "Sickbeard" ] + address = 192.168.0.2 + port = 8081 + APIKey = 3678177136222bf5002be209220ccb20 + +[ "Shows" ] + UnknownInput = "/srv/storage2/files/VideoProcessing/Unknown/" + [[ "Thomas the Tank Engine & Friends" ]] + InputDirectory = "/srv/storage2/files/VideoProcessing/Thomas/Input/" + OutputDirectory = "/srv/storage2/videos/Kids/TV/Thomas The Tank Engine & Friends/" + alias = "Thomas and Friends", + MythTvEpisodePrefix = , + SickbeardPrefix = "" + [[ "Chuggington" ]] + InputDirectory = "/srv/storage2/files/VideoProcessing/Chuggington/Input/" + OutputDirectory = "/srv/storage2/videos/Kids/TV/Chuggington/" + alias = , + MythTvEpisodePrefix = , + SickbeardPrefix = "" + [[ "Mike the Knight" ]] + InputDirectory = "/srv/storage2/files/VideoProcessing/MikeTheKnight/Input/" + OutputDirectory = "/srv/storage2/videos/Kids/TV/Mike the Knight/" + alias = , + MythTvEpisodePrefix = "Mike the Knight and the ", Mike the Knight and " + SickbeardPrefix = "" + [[ "Octonauts" ]] + InputDirectory = "/srv/storage2/files/VideoProcessing/Octonauts/Input/" + OutputDirectory = "/srv/storage2/videos/Kids/TV/Octonauts/" + alias = "The Octonauts", + MythTvEpisodePrefix = "The Octonauts and ", + SickbeardPrefix = "The " + [[ "In the Night Garden" ]] + InputDirectory = "/srv/storage2/files/VideoProcessing/InTheNightGarden/Input/" + OutputDirectory = "/srv/storage2/videos/Kids/TV/In The Night Garden/" + alias = , + MythTvEpisodePrefix = , + SickbeardPrefix = "" + [[ "Raa Raa! The Noisy Lion" ]] + InputDirectory = "/srv/storage2/files/VideoProcessing/RaaRaa/Input/" + OutputDirectory = "/srv/storage2/videos/Kids/TV/Raa Raa the Noisy Lion/" + alias = , + MythTvEpisodePrefix = , + SickbeardPrefix = "" \ No newline at end of file