added settings file

This commit is contained in:
2013-07-08 17:21:42 +10:00
parent ccb103ad36
commit 7a34fd01c8
8 changed files with 418 additions and 230 deletions

View File

@@ -7,12 +7,12 @@ Created on Fri Jul 5 14:14:22 2013
import sys import sys
import getopt import getopt
import libfilemanager from libfilemanager import FileManager
from libsettings import Settings from libsettings import Settings
from libhandbrake import Encoder from libhandbrake import Encoder
import libtvdatasource import libtvdatasource
TVRECORDINGSDIR = "/Volumes/TV Recordings/" #TVRECORDINGSDIR = "/Volumes/TV Recordings/"
#TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings #TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings
def ShowHelp(): def ShowHelp():
@@ -55,37 +55,42 @@ def main(argv):
readOnly = True readOnly = True
doList = True doList = True
showSettings = Settings("settings.xml") # TODO call actual settings file settings = Settings("settings.cfg")
if readOnly and doList: if readOnly and doList:
if doEncode: if doEncode:
#Generate the list of files that would be encoded #Generate the list of files that would be encoded
showData = libfilemanager.GetEncodingFiles(showSettings, readOnly) fileManager = FileManager(settings)
showData = fileManager.GetEncodingFiles(readOnly)
PrintShowsToEncode(showData) PrintShowsToEncode(showData)
else: else:
# Generate the list of files to process # Generate the list of files to process
tempShowList = ["Thomas and Friends", "Thomas the Tank Engine & Friends", # tempShowList = ["Thomas and Friends", "Thomas the Tank Engine & Friends",
"Chuggington", "Mike the Knight", "Octonauts", # "Chuggington", "Mike the Knight", "Octonauts",
"The Octonauts", "In the Night Garden", # "The Octonauts", "In the Night Garden",
"Raa Raa! The Noisy Lion"] # TODO get from settings # "Raa Raa! The Noisy Lion"] # TODO get from settings
shows = libfilemanager.GetFilesToPrepare(TVRECORDINGSDIR, numFiles, tempShowList) fileManager = FileManager(settings)
shows = fileManager.GetFilesToPrepare(numFiles)
print "num results: {0}".format(len(shows)) print "num results: {0}".format(len(shows))
PrintShowsToPrepare(shows) PrintShowsToPrepare(shows)
else: else:
if doEncode: if doEncode:
#Encode the files and move them to their final destination #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: for show in showData:
if libfilemanager.CheckFileExists(show.outputFile): if fileManager.CheckFileExists(show.outputFile):
print "File {0} already exists. Cannot process.".format(show.outputFile) print "File {0} already exists. Cannot process.".format(show.outputFile)
else: 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: else:
# TODO Process files for encoding # TODO Process files for encoding
shows = libfilemanager.GetFilesToPrepare(TVRECORDINGSDIR, numFiles, shows) fileManager = FileManager(settings)
shows = fileManager.GetFilesToPrepare(numFiles)
libtvdatasource.PrepareEpisodes(shows) libtvdatasource.PrepareEpisodes(shows)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -6,12 +6,12 @@ Created on Fri Jul 5 14:11:31 2013
""" """
import glob import glob
import libtvdatasource as TVData from libtvdatasource import TVData
import os import os
import shutil import shutil
#move this to settings #move this to settings
TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" #TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/"
class EncodeData: class EncodeData:
inputFile = '' inputFile = ''
@@ -21,80 +21,85 @@ class EncodeData:
def ToString(self): def ToString(self):
return "Input: {0}/tOutput: {2}".format(self.inputFile, self.outputFile) return "Input: {0}/tOutput: {2}".format(self.inputFile, self.outputFile)
class FileManager:
def __GetInputFilesToEncode(shows): def __init__(self, settings):
fileList = [] 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: def __FindSeason(self, path, fileName, readOnly):
for r,d,f in os.walk(show.inputDirectory): season = "Season {0}".format(fileName[1:3])
for files in f: seasonPath = os.path.join(path, season)
if files.endswith(".mpg"):
data = EncodeData()
data.show = show
data.inputFile = os.path.join(r,files)
fileList.append(data)
return fileList if not readOnly:
if not os.path.exists(seasonPath):
def __FindSeason(path, fileName, readOnly): os.makedirs(seasonPath)
season = "Season {0}".format(fileName[1:3])
seasonPath = os.path.join(path, season) return seasonPath
if not readOnly:
if not os.path.exists(seasonPath):
os.makedirs(seasonPath)
return seasonPath def __GetEncodeOutputFile(self, inputFile, showName, readOnly):
inFile = os.path.basename(inputFile)
def __GetEncodeOutputFile(showData, readOnly): outFilename = inFile[:-3]+"mkv"
inFile = os.path.basename(showData.inputFile) outPath = self.__FindSeason(self.settings.GetShowOutputFile(showName), outFilename)
outFilename = inFile[:-3]+"mkv" return os.path.join(outPath, outFilename)
outPath = __FindSeason(showData.show.outputDirectory, outFilename)
showData.outputFile = os.path.join(outPath, outFilename)
return showData def GetEncodingFiles(self, readOnly=True):
showsData = self.__GetInputFilesToEncode(self.settings.GetShowNames())
def GetEncodingFiles(shows, readOnly=True): for showData in showsData:
showsData = __GetInputFilesToEncode(shows) showData.outputFile = self.__GetEncodeOutputFile(showData.inputFile, showData.name, readOnly)
for showData in showsData:
showsData = __GetEncodeOutputFile(showData, readOnly) return showsData
return showsData def CheckFileExists(self, file):
return os.path.isfile(file)
def CheckFileExists(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): linkAddress = self.__GetRecordingFile(inputFileName)
return os.path.join(TVRECORDINGSDIR, os.path.dirname(fileName).split("/")[-1] + ".mpg")
def PerformPostEncodeFileOperations(inputFileName, outputFileName): os.remove(linkAddress)
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)
#files is now a list of unprocessed files, but contains shows other than those we are interested in os.symlink(outputFileName, linkAddress)
showsToProcess = [] def GetFilesToPrepare(self, numberofFiles):
i = 0 path = self.settings.TVRecordingDirectory()
print "Found {0} potential files".format(len(files)) files = glob.glob("{0}*.mpg".format(path))
for file in files: files = sorted(files, key=os.path.getctime)
# TODO get these from settings files = filter(lambda file: not os.path.islink(file), files)
#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 #files is now a list of unprocessed files, but contains shows other than those we are interested in
if showData:
showsToProcess.append(showData) showsToProcess = []
i = i + 1 i = 0
if i == int(numberofFiles): print "Found {0} potential files".format(len(files))
return showsToProcess
tvData = TVData(self.settings)
return showsToProcess #will reach here if there were less than numberofFiles found
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

View File

@@ -10,20 +10,25 @@ Library to interface with handbrake to encode video files
import logging import logging
import subprocess import subprocess
HANDBRAKECOMMAND = ['HandBrakeCLI', '--verbose', '-i', #==============================================================================
"SUBSTITUTE WITH INPUT FILE", '-o', # HANDBRAKECOMMAND = ['HandBrakeCLI', '--verbose', '-i',
"SUBSTITUDE WITH OUTPUT FILE", '-f', 'mkv', '-e', 'x264', # "SUBSTITUTE WITH INPUT FILE", '-o',
'-x264-preset', 'slower', '-x264-tune', 'animation', '-q', # "SUBSTITUDE WITH OUTPUT FILE", '-f', 'mkv', '-e', 'x264',
'20', '--loose-anamorphic', '--decomb', '--detelecine', # '-x264-preset', 'slower', '-x264-tune', 'animation', '-q',
'--denoise="2:1:2:3"', '--deblock'] # '20', '--loose-anamorphic', '--decomb', '--detelecine',
# '--denoise="2:1:2:3"', '--deblock']
#==============================================================================
class Encoder: class Encoder:
def Encode(input, output, waitForCompletion=True, logger=None): def __init__(self, handbrakeCommand):
HANDBRAKECOMMAND[3] = input self.handbrakeCommand = handbrakeCommand
HANDBRAKECOMMAND[5] = output
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)) logger.debug("Handbrake command is: {0}".format(self.handbrakeCommand))
process = subprocess.Popen(HANDBRAKECOMMAND) process = subprocess.Popen(self.handbrakeCommand)
if waitForCompletion: if waitForCompletion:
process.wait() process.wait()

View File

@@ -8,14 +8,25 @@ Created on Fri Jul 5 14:10:47 2013
import MySQLdb as mdb import MySQLdb as mdb
from libtvshow import TVShow from libtvshow import TVShow
def RetrieveEpisodeData(serverAddress, user, password, database, inputFile): class MythTV:
con = mdb.connect(serverAddress, user, password, database) def __init__(self, settings):
self.settings = settings
with con: def RetrieveEpisodeData(self, inputFile):
cur = con.cursor(mdb.cursors.DictCursor) con = mdb.connect(self.settings.MythTVAddress(), self.settings.MythTVUser(), self.settings.MythTVPassword(), self.settings.MythTVDatabase())
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']) 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

View File

@@ -5,7 +5,7 @@ Created on Fri Jul 5 20:14:15 2013
@author: shanef @author: shanef
""" """
from xml.etree import ElementTree from configobj import ConfigObj
class ShowSettings: class ShowSettings:
def __init__(self, name, inputDirectory, outputDirectory): def __init__(self, name, inputDirectory, outputDirectory):
@@ -13,15 +13,98 @@ class ShowSettings:
self.inputDirectory = inputDirectory self.inputDirectory = inputDirectory
self.outputDirectory = outputDirectory self.outputDirectory = outputDirectory
class Settings: class Settings:
def __init__(self, settingsFile): def __init__(self, settingsFile):
self.shows = self.LoadSettings(settingsFile) self.__config = ConfigObj(settingsFile)
def LoadSettings(self, source): def TVRecordingDirectory(self):
shows = [] return self.__config["TVRecordings"]
settingsXml = ElementTree.parse(source).getroot()
for show in settingsXml.findall('show'): def HandbrakeCommand(self):
newShow = ShowSettings(show[0].text, show[1].text, show[2].text) return self.__config["HandbrakeCommand"]
shows.append(newShow)
return shows 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

View File

@@ -12,13 +12,14 @@ from fuzzywuzzy import fuzz
from operator import itemgetter from operator import itemgetter
class Sickbeard: class Sickbeard:
def __init__(self, address, port, apikey): def __init__(self, settings):
self.address = address self.__settings = settings
self.port = port self.__address = settings.SickbeardAddress()
self.apikey = apikey self.__port = settings.SickbeardPort()
self.__apikey = settings.SickbeardAPIKey()
def __GetApiURL(self): 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): def FindShowId(self, showName):
jsonurl = urlopen(self.__GetApiURL()+"?cmd=shows") jsonurl = urlopen(self.__GetApiURL()+"?cmd=shows")
@@ -42,10 +43,11 @@ class Sickbeard:
def FindEpisodeByDescription(self, showId, season, episode, description): def FindEpisodeByDescription(self, showId, season, episode, description):
jsonEpisodeUrl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}&episode={3}".format(self.__GetApiURL(), showId, season, episode)) jsonEpisodeUrl = urlopen("{0}?cmd=episode&tvdbid={1}&season={2}&episode={3}".format(self.__GetApiURL(), showId, season, episode))
episodeResult = json.loads(jsonEpisodeUrl.read()) 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 return None
def FindEpisode(self, showId, name=None, description=None): def FindEpisode(self, showId, name=None, description=None):
@@ -54,8 +56,8 @@ class Sickbeard:
for season in result['data']: for season in result['data']:
for episode in result['data'][season]: for episode in result['data'][season]:
if name is not None and name.lower() == result['data'][season][episode]['name'].lower(): if name is not None and fuzz.partial_ratio(name.lower(), result['data'][season][episode]['name'].lower()) > 90:
return (season, episode, name) return (season, episode, result['data'][season][episode]['name'])
elif description is not None: elif description is not None:
descriptionQueryResult = self.FindEpisodeByDescription(showId, season, episode, description) descriptionQueryResult = self.FindEpisodeByDescription(showId, season, episode, description)
if descriptionQueryResult is not None: if descriptionQueryResult is not None:
@@ -63,8 +65,18 @@ class Sickbeard:
return (0, 0, '') return (0, 0, '')
def GetEpisodeName(subtitle, showName): #==============================================================================
if subtitle[:len(showName)].lower() == showName.lower(): # def GetEpisodeName(subtitle, showName):
return subtitle[len(showName + ' and the '):] # if subtitle[:len(showName)].lower() == showName.lower():
else: # return subtitle[len(showName + ' and the '):]
return subtitle # 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

View File

@@ -5,116 +5,131 @@ Created on Fri Jul 5 14:42:47 2013
@author: shanef @author: shanef
""" """
import libmythtv as MythTV from libmythtv import MythTV
from libsickbeard import Sickbeard from libsickbeard import Sickbeard
import os import os
import shutil import shutil
# TODO Move these to settings # TODO Move these to settings
PROCESSDIR="/srv/storage2/files/VideoProcessing/" #PROCESSDIR="/srv/storage2/files/VideoProcessing/"
THOMAS="Thomas" #THOMAS="Thomas"
CHUGGINGTON="Chuggington" #CHUGGINGTON="Chuggington"
MIKE="MikeTheKnight" #MIKE="MikeTheKnight"
OCTONAUTS="Octonauts" #OCTONAUTS="Octonauts"
NIGHTGARDEN="InTheNightGarden" #NIGHTGARDEN="InTheNightGarden"
RAARAA="RaaRaa" #RAARAA="RaaRaa"
INPUTDIR="Input" #INPUTDIR="Input"
def FixEpisodeSeasonNumber(number): class TVData:
if len(number) == 1: def __init__(self, settings):
return "0{0}".format(number) self.settings = settings
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)
def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, showsToProcess, sickbeardAddress, sickbeardPort, sickbeardAPIKey): def FixEpisodeSeasonNumber(self, number):
file = os.path.basename(inputFile) if len(number) == 1:
show = MythTV.RetrieveEpisodeData(serverAddress, user, password, database, file) return "0{0}".format(number)
else:
return number
if show.title and show.title in showsToProcess: def GetDirectory(self, title, season):
if show.subtitle: show = self.settings.GetShow(title)
show.subtitle = GetEpisodeName(show.subtitle, show.title) if not show or show == "":
print "Couldn't find show for {0}".format(title)
if (show.season == "0" or show.episode == "0"): return self.settings.UnknownDirectory()
sickbeard = Sickbeard(sickbeardAddress, sickbeardPort, sickbeardAPIKey) else:
showId = sickbeard.FindShowId(show.title) return os.path.join(self.settings.GetShowInputDirectory(show), season)
#==============================================================================
result = sickbeard.FindEpisode(showId, show.subtitle, show.description) # if title == "Thomas and Friends" or title == "Thomas the Tank Engine & Friends":
show.season = str(result[0]) # directory = THOMAS
show.episode = str(result[1]) # elif title == "Chuggington":
show.subtitle = result[2] # directory = CHUGGINGTON
# elif title == "Mike the Knight":
if show.season != "0" and show.episode != "0": # directory = MIKE
show.season = FixEpisodeSeasonNumber(show.season) # elif title == "Octonauts" or title == "The Octonauts":
show.episode = FixEpisodeSeasonNumber(show.episode) # directory = OCTONAUTS
# elif title == "In the Night Garden":
seasonFolder = "Season {0}".format(show.season) # directory = NIGHTGARDEN
season = "S{0}".format(show.season) # elif title == "Raa Raa! The Noisy Lion":
episode = "E{0}".format(show.episode) # directory = RAARAA
renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) # else:
# print "Didn't match"
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)
shutil.move(inputFile, outputFile) # return os.path.join(PROCESSDIR, directory, INPUTDIR, season)
def PrepareEpisodes(showsData): def RetrieveEpisodeData(self, inputFile):
for showData in showsData: file = os.path.basename(inputFile)
ProcessEpisode(showData.inputFile, showData.outputFile)
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)

52
settings.cfg Normal file
View File

@@ -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 = ""