From cb914cb65e9ade21e88004ead1591810b506ecc8 Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Fri, 5 Jul 2013 21:30:01 +1000 Subject: [PATCH] interim commit --- libfilemanager.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++ libhandbrake.py | 3 ++- libsettings.py | 15 +++++++++++ libtvdatasource.py | 7 +++++ 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/libfilemanager.py b/libfilemanager.py index b055b8e..1452e17 100644 --- a/libfilemanager.py +++ b/libfilemanager.py @@ -5,3 +5,70 @@ Created on Fri Jul 5 14:11:31 2013 @author: shanef """ +import os +import shutil + +#move this to settings +TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" + +class EncodeData: + inputFile = '' + show = None + outputFile = '' + + def ToString(): + return "Input: {0}/tOutput: {2}".format(inputFile, outputFile) + +def __GetInputFilesToEncode(shows): + 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) + + 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) + + 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) + + return showData + +def GetEncodingFiles(shows, readOnly=True): + showsData = __GetInputFilesToEncode(shows) + for showData in showsData: + showsData = __GetEncodeOutputFile(showData, readOnly) + + return showsData + +def CheckFileExists(file): + return os.path.isfile(file) + +def __GetRecordingFile(fileName): + return os.path.join(TVRECORDINGSDIR, os.path.dirname(fileName).split("/")[-1] + ".mpg") + +def PerformPostEncodeFileOperations(inputFileName, outputFileName): + shutil.rmtree(os.path.dirname(inputFileName)) + + linkAddress = __GetRecordingFile(inputFileName) + + os.remove(linkAddress) + + os.symlink(outputFileName, linkAddress) \ No newline at end of file diff --git a/libhandbrake.py b/libhandbrake.py index fafd199..f077fa0 100644 --- a/libhandbrake.py +++ b/libhandbrake.py @@ -32,4 +32,5 @@ class Encoder: logger.info("Handbrake completed with return code {0}".format(process.returncode)) return process.returncode - return None \ No newline at end of file + return None + \ No newline at end of file diff --git a/libsettings.py b/libsettings.py index 9d87b05..9227e8c 100644 --- a/libsettings.py +++ b/libsettings.py @@ -5,3 +5,18 @@ Created on Fri Jul 5 20:14:15 2013 @author: shanef """ +from libtvdatasource import TVShow +from xml.etree import ElementTree + +class Settings: + def __init__(self, settingsFile): + self.shows = self.LoadSettings(settingsFile) + + def LoadSettings(source): + shows = [] + settingsXml = ElementTree.parse(source).getroot() + + for show in settingsXml.findall('show'): + newShow = TVShow(show[0].text, show[1].text, show[2].text) + shows.append(newShow) + return shows \ No newline at end of file diff --git a/libtvdatasource.py b/libtvdatasource.py index b73fc16..b09eb23 100644 --- a/libtvdatasource.py +++ b/libtvdatasource.py @@ -5,3 +5,10 @@ Created on Fri Jul 5 14:42:47 2013 @author: shanef """ +class TVShow: + def __init__(self, episode, season, title, subtitle, description): + self.episode = episode + self.season = season + self.title = title + self.subtitle = subtitle + self.description = description \ No newline at end of file