recordingprocessing/TVEncoder.py

85 lines
2.7 KiB
Python
Raw Normal View History

2013-07-05 14:15:03 +10:00
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 5 14:14:22 2013
@author: shanef
"""
2013-07-05 15:35:12 +10:00
import sys
import getopt
2013-07-05 21:27:53 +10:00
import libfilemanager
2013-07-06 20:18:52 +10:00
from libsettings import Settings
2013-07-06 20:28:49 +10:00
from libhandbrake import Encoder
2013-07-06 20:18:52 +10:00
import libtvdatasource
2013-07-05 21:27:53 +10:00
2013-07-05 22:40:17 +10:00
TVRECORDINGSDIR = "/srv/storage2/videos/TVRecordings/" # TODO move this to settings
2013-07-05 21:27:53 +10:00
def ShowHelp():
print 'TVEncoder.py -p -n <number of files to prepare for processing> - prepare n recordings'
print 'TVEncoder.py -p -l -n <number of files to process> - lists the files that will be processed without actually encoding them'
print 'TVEncoder.py -e - encode the files that have been processed'
print 'TVEncoder.py -e -l - list the files that would be encoded'
def PrintShowsToEncode(showData):
print "/n".join(showData)
2013-07-05 15:35:12 +10:00
2013-07-06 20:18:52 +10:00
def PrintShowsToPrepare(showData):
print "/n".join(showData)
2013-07-05 15:35:12 +10:00
def main(argv):
numFiles = 0
2013-07-05 21:27:53 +10:00
doEncode = False
readOnly = True
doList = False
2013-07-05 15:35:12 +10:00
try:
2013-07-05 21:27:53 +10:00
opts, args = getopt.getopt(argv,"hlpen:")
2013-07-05 15:35:12 +10:00
except getopt.GetoptError:
2013-07-05 21:27:53 +10:00
ShowHelp()
2013-07-05 15:35:12 +10:00
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
2013-07-05 21:27:53 +10:00
ShowHelp()
2013-07-05 15:35:12 +10:00
sys.exit()
2013-07-05 21:27:53 +10:00
elif opt == "-p":
doEncode = False
readOnly = False
elif opt == "-e":
readOnly = False
doEncode = True
2013-07-05 15:35:12 +10:00
elif opt == "-n":
numFiles = arg
2013-07-05 21:27:53 +10:00
elif opt == "-l":
readOnly = True
doList = True
2013-07-05 22:40:17 +10:00
shows = Settings("") # TODO call actual settings file
2013-07-05 15:35:12 +10:00
2013-07-05 21:27:53 +10:00
if readOnly and doList:
if doEncode:
#Generate the list of files that would be encoded
2013-07-06 20:28:49 +10:00
showData = libfilemanager.GetEncodingFiles(shows, readOnly)
2013-07-05 21:27:53 +10:00
PrintShowsToEncode(showData)
else:
# Generate the list of files to process
2013-07-06 20:28:49 +10:00
shows = libfilemanager.GetFilesToPrepare(TVRECORDINGSDIR, numFiles, shows)
2013-07-06 20:18:52 +10:00
PrintShowsToPrepare(shows)
2013-07-05 21:27:53 +10:00
else:
if doEncode:
#Encode the files and move them to their final destination
2013-07-06 20:28:49 +10:00
showData = libfilemanager.GetEncodingFiles(shows, readOnly)
2013-07-05 21:27:53 +10:00
for show in showData:
2013-07-06 20:28:49 +10:00
if libfilemanager.CheckFileExists(show.outputFile):
2013-07-05 21:27:53 +10:00
print "File {0} already exists. Cannot process.".format(show.outputFile)
else:
result = Encoder.Encode(show.inputFile, show.outputFile)
2013-07-06 20:28:49 +10:00
libfilemanager.PerformPostEncodeFileOperations(show.inputFile, show.outputFile)
2013-07-05 21:27:53 +10:00
else:
2013-07-05 22:40:17 +10:00
# TODO Process files for encoding
2013-07-06 20:28:49 +10:00
shows = libfilemanager.GetFilesToPrepare(TVRECORDINGSDIR, numFiles, shows)
libtvdatasource.PrepareEpisodes(shows)
2013-07-05 15:35:12 +10:00
if __name__ == "__main__":
main(sys.argv[1:])