finished initial coding

This commit is contained in:
2013-07-06 20:18:52 +10:00
parent 61a5eb9768
commit b8acbcbdc1
3 changed files with 78 additions and 9 deletions

View File

@@ -8,8 +8,9 @@ Created on Fri Jul 5 14:14:22 2013
import sys import sys
import getopt import getopt
import libfilemanager import libfilemanager
import libsettings from libsettings import Settings
import libhandbrake import libhandbrake
import libtvdatasource
TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings
@@ -22,6 +23,9 @@ def ShowHelp():
def PrintShowsToEncode(showData): def PrintShowsToEncode(showData):
print "/n".join(showData) print "/n".join(showData)
def PrintShowsToPrepare(showData):
print "/n".join(showData)
def main(argv): def main(argv):
numFiles = 0 numFiles = 0
doEncode = False doEncode = False
@@ -58,7 +62,8 @@ def main(argv):
PrintShowsToEncode(showData) PrintShowsToEncode(showData)
else: else:
# Generate the list of files to process # Generate the list of files to process
files = GetFilesToPrepare(TVRECORDINGSDIR, numFiles, shows) shows = GetFilesToPrepare(TVRECORDINGSDIR, numFiles, 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
@@ -73,6 +78,8 @@ def main(argv):
PerformPostEncodeFileOperations(show.inputFile, show.outputFile) PerformPostEncodeFileOperations(show.inputFile, show.outputFile)
else: else:
# TODO Process files for encoding # TODO Process files for encoding
shows = GetFilesToPrepare(TVRECORDINGSDIR, numFiles, shows)
PrepareEpisodes(shows)
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])

View File

@@ -21,6 +21,7 @@ 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)
def __GetInputFilesToEncode(shows): def __GetInputFilesToEncode(shows):
fileList = [] fileList = []
@@ -82,15 +83,17 @@ def GetFilesToPrepare(path, numberofFiles, shows):
#files is now a list of unprocessed files, but contains shows other than those we are interested in #files is now a list of unprocessed files, but contains shows other than those we are interested in
filesToProcess = [] showsToProcess = []
i = 0 i = 0
for file in files: for file in files:
# TODO get these from settings # TODO get these from settings
if TVData.CheckTitleIsInList('localhost', 'script', 'script', 'mythconverg', file): #if TVData.CheckTitleIsInList('localhost', 'script', 'script', 'mythconverg', file):
filesToProcess.append(file) showData = TVData.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file, shows)
if showData:
showsToProcess.append(showData)
i = i + 1 i = i + 1
if i == numberofFiles: if i == numberofFiles:
return filesToProcess return showsToProcess
return filesToProcess #will reach here if there were less than numberofFiles found return showsToProcess #will reach here if there were less than numberofFiles found

View File

@@ -7,6 +7,18 @@ Created on Fri Jul 5 14:42:47 2013
import libmythtv as MythTV import libmythtv as MythTV
from libsickbeard import Sickbeard 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"
class TVShow: class TVShow:
def __init__(self, episode, season, title, subtitle, description, inputFile='', outputFile=''): def __init__(self, episode, season, title, subtitle, description, inputFile='', outputFile=''):
@@ -23,11 +35,31 @@ def FixEpisodeSeasonNumber(number):
return "0{0}".format(number) return "0{0}".format(number)
else: else:
return str(number) return str(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): def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, showsToProcess):
file = os.path.basename(inputFile)
show = MythTV.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file) show = MythTV.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file)
if show.title: if show.title and show.title in showsToProcess:
if show.subtitle: if show.subtitle:
show.subtitle = GetEpisodeName(show.subtitle, show.title) show.subtitle = GetEpisodeName(show.subtitle, show.title)
@@ -48,9 +80,17 @@ def RetrieveEpisodeData(serverAddress, user, password, database, inputFile, show
renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle) renamedFile = "{0}{1} - {2} - SD TV_.mpg".format(season, episode, show.subtitle)
directory = GetDirectory(show.title, seasonFolder) directory = GetDirectory(show.title, seasonFolder)
show.outputFile = os.path.join(directory, inputFile[:-4], renamedFile)
show.inputFile = inputFile
return show
else:
return None
def CheckTitleIsInList(serverAddress, user, password, database, inputFile): def CheckTitleIsInList(serverAddress, user, password, database, inputFile):
"""Check that inputFile is a recording of a show that is to be processed.""" """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) show = MythTV.RetrieveEpisodeData('localhost', 'script', 'script', 'mythconverg', file)
# TODO get this from settings # TODO get this from settings
@@ -62,8 +102,27 @@ def CheckTitleIsInList(serverAddress, user, password, database, inputFile):
else: else:
return False 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): def GetEpisodeName(subtitle, showName):
if subtitle[:len(showName)].lower() == showName.lower(): if subtitle[:len(showName)].lower() == showName.lower():
return subtitle[len(showName + ' and the '):] return subtitle[len(showName + ' and the '):]
else: else:
return subtitle return subtitle
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):
for showData in showsData:
ProcessEpisode(showData.inputFile, showData.outputFile)