added settings file
This commit is contained in:
33
TVEncoder.py
33
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__":
|
||||
|
||||
@@ -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,12 +21,15 @@ class EncodeData:
|
||||
def ToString(self):
|
||||
return "Input: {0}/tOutput: {2}".format(self.inputFile, self.outputFile)
|
||||
|
||||
class FileManager:
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
|
||||
def __GetInputFilesToEncode(shows):
|
||||
def __GetInputFilesToEncode(self):
|
||||
fileList = []
|
||||
|
||||
for show in shows:
|
||||
for r,d,f in os.walk(show.inputDirectory):
|
||||
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()
|
||||
@@ -36,7 +39,7 @@ def __GetInputFilesToEncode(shows):
|
||||
|
||||
return fileList
|
||||
|
||||
def __FindSeason(path, fileName, readOnly):
|
||||
def __FindSeason(self, path, fileName, readOnly):
|
||||
season = "Season {0}".format(fileName[1:3])
|
||||
seasonPath = os.path.join(path, season)
|
||||
|
||||
@@ -46,37 +49,36 @@ def __FindSeason(path, fileName, readOnly):
|
||||
|
||||
return seasonPath
|
||||
|
||||
def __GetEncodeOutputFile(showData, readOnly):
|
||||
inFile = os.path.basename(showData.inputFile)
|
||||
def __GetEncodeOutputFile(self, inputFile, showName, readOnly):
|
||||
inFile = os.path.basename(inputFile)
|
||||
outFilename = inFile[:-3]+"mkv"
|
||||
outPath = __FindSeason(showData.show.outputDirectory, outFilename)
|
||||
showData.outputFile = os.path.join(outPath, outFilename)
|
||||
outPath = self.__FindSeason(self.settings.GetShowOutputFile(showName), outFilename)
|
||||
return os.path.join(outPath, outFilename)
|
||||
|
||||
return showData
|
||||
|
||||
def GetEncodingFiles(shows, readOnly=True):
|
||||
showsData = __GetInputFilesToEncode(shows)
|
||||
def GetEncodingFiles(self, readOnly=True):
|
||||
showsData = self.__GetInputFilesToEncode(self.settings.GetShowNames())
|
||||
for showData in showsData:
|
||||
showsData = __GetEncodeOutputFile(showData, readOnly)
|
||||
showData.outputFile = self.__GetEncodeOutputFile(showData.inputFile, showData.name, readOnly)
|
||||
|
||||
return showsData
|
||||
|
||||
def CheckFileExists(file):
|
||||
def CheckFileExists(self, file):
|
||||
return os.path.isfile(file)
|
||||
|
||||
def __GetRecordingFile(fileName):
|
||||
return os.path.join(TVRECORDINGSDIR, os.path.dirname(fileName).split("/")[-1] + ".mpg")
|
||||
def __GetRecordingFile(self, fileName):
|
||||
return os.path.join(self.settings.TVRecordingDirectory, os.path.dirname(fileName).split("/")[-1] + ".mpg")
|
||||
|
||||
def PerformPostEncodeFileOperations(inputFileName, outputFileName):
|
||||
def PerformPostEncodeFileOperations(self, inputFileName, outputFileName):
|
||||
shutil.rmtree(os.path.dirname(inputFileName))
|
||||
|
||||
linkAddress = __GetRecordingFile(inputFileName)
|
||||
linkAddress = self.__GetRecordingFile(inputFileName)
|
||||
|
||||
os.remove(linkAddress)
|
||||
|
||||
os.symlink(outputFileName, linkAddress)
|
||||
|
||||
def GetFilesToPrepare(path, numberofFiles, shows):
|
||||
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)
|
||||
@@ -86,10 +88,13 @@ def GetFilesToPrepare(path, numberofFiles, shows):
|
||||
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('192.168.0.2', 'script', 'script', 'mythconverg', file, shows, '192.168.0.2', '8081', '3678177136222bf5002be209220ccb20') # TODO all these settings need to move to settings
|
||||
showData = tvData.RetrieveEpisodeData(file)
|
||||
if showData:
|
||||
showsToProcess.append(showData)
|
||||
i = i + 1
|
||||
|
||||
@@ -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
|
||||
|
||||
logger.debug("Handbrake command is: {0}".format(HANDBRAKECOMMAND))
|
||||
process = subprocess.Popen(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(self.handbrakeCommand))
|
||||
process = subprocess.Popen(self.handbrakeCommand)
|
||||
|
||||
if waitForCompletion:
|
||||
process.wait()
|
||||
|
||||
15
libmythtv.py
15
libmythtv.py
@@ -8,8 +8,12 @@ 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
|
||||
|
||||
def RetrieveEpisodeData(self, inputFile):
|
||||
con = mdb.connect(self.settings.MythTVAddress(), self.settings.MythTVUser(), self.settings.MythTVPassword(), self.settings.MythTVDatabase())
|
||||
|
||||
with con:
|
||||
cur = con.cursor(mdb.cursors.DictCursor)
|
||||
@@ -19,3 +23,10 @@ def RetrieveEpisodeData(serverAddress, user, password, database, inputFile):
|
||||
|
||||
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
|
||||
|
||||
101
libsettings.py
101
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
|
||||
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
|
||||
@@ -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")
|
||||
@@ -43,7 +44,8 @@ class Sickbeard:
|
||||
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:
|
||||
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
|
||||
@@ -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
|
||||
#==============================================================================
|
||||
# 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
|
||||
@@ -5,73 +5,91 @@ 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):
|
||||
class TVData:
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
|
||||
def FixEpisodeSeasonNumber(self, 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
|
||||
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:
|
||||
print "Didn't match"
|
||||
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"
|
||||
#==============================================================================
|
||||
|
||||
return os.path.join(PROCESSDIR, directory, INPUTDIR, season)
|
||||
# return os.path.join(PROCESSDIR, directory, INPUTDIR, season)
|
||||
|
||||
def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, showsToProcess, sickbeardAddress, sickbeardPort, sickbeardAPIKey):
|
||||
def RetrieveEpisodeData(self, inputFile):
|
||||
file = os.path.basename(inputFile)
|
||||
show = MythTV.RetrieveEpisodeData(serverAddress, user, password, database, file)
|
||||
|
||||
mythTv = MythTV(self.settings)
|
||||
show = mythTv.RetrieveEpisodeData(file)
|
||||
|
||||
showsToProcess = self.settings.GetShowNames(True)
|
||||
|
||||
if show.title and show.title in showsToProcess:
|
||||
if show.subtitle:
|
||||
show.subtitle = GetEpisodeName(show.subtitle, show.title)
|
||||
show.title = self.settings.GetShow(show.title)
|
||||
|
||||
if (show.season == "0" or show.episode == "0"):
|
||||
sickbeard = Sickbeard(sickbeardAddress, sickbeardPort, sickbeardAPIKey)
|
||||
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 = FixEpisodeSeasonNumber(show.season)
|
||||
show.episode = FixEpisodeSeasonNumber(show.episode)
|
||||
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 = GetDirectory(show.title, seasonFolder)
|
||||
directory = self.GetDirectory(show.title, seasonFolder)
|
||||
|
||||
show.outputFile = os.path.join(directory, file[:-4], renamedFile)
|
||||
show.inputFile = inputFile
|
||||
@@ -80,21 +98,23 @@ def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, 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)
|
||||
#==============================================================================
|
||||
# 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
|
||||
#==============================================================================
|
||||
|
||||
# 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):
|
||||
def DetermineTargetFilename(directory, filename, inputFilename):
|
||||
dir = os.path.join(directory, inputFilename[:-4])
|
||||
|
||||
if not os.path.exists(dir):
|
||||
@@ -102,19 +122,14 @@ def DetermineTargetFilename(directory, filename, inputFilename):
|
||||
|
||||
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):
|
||||
def ProcessEpisode(inputFile, outputFile):
|
||||
outputdir = os.path.dirname(outputFile)
|
||||
if not os.path.exists(outputdir):
|
||||
os.makedirs(outputdir)
|
||||
|
||||
shutil.move(inputFile, outputFile)
|
||||
|
||||
def PrepareEpisodes(showsData):
|
||||
def PrepareEpisodes(self, showsData):
|
||||
for showData in showsData:
|
||||
ProcessEpisode(showData.inputFile, showData.outputFile)
|
||||
self.ProcessEpisode(showData.inputFile, showData.outputFile)
|
||||
52
settings.cfg
Normal file
52
settings.cfg
Normal 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 = ""
|
||||
Reference in New Issue
Block a user