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-08 17:21:42 +10:00
|
|
|
from libfilemanager import FileManager
|
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-09 12:14:02 +10:00
|
|
|
from libtvdatasource import TVData
|
2013-07-05 21:27:53 +10:00
|
|
|
|
2013-07-05 22:40:17 +10:00
|
|
|
|
2013-07-05 21:27:53 +10:00
|
|
|
def ShowHelp():
|
2013-07-10 15:45:42 +10:00
|
|
|
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'
|
2013-07-05 21:27:53 +10:00
|
|
|
print 'TVEncoder.py -e - encode the files that have been processed'
|
|
|
|
|
print 'TVEncoder.py -e -l - list the files that would be encoded'
|
|
|
|
|
|
2013-07-10 15:45:42 +10:00
|
|
|
|
2013-07-09 20:28:47 +10:00
|
|
|
def PrintShowsToEncode(showsData):
|
|
|
|
|
# print "/n".join(showData)
|
|
|
|
|
for showData in showsData:
|
|
|
|
|
print showData.ToString()
|
2013-07-05 15:35:12 +10:00
|
|
|
|
2013-07-10 15:45:42 +10:00
|
|
|
|
2013-07-06 21:59:33 +10:00
|
|
|
def PrintShowsToPrepare(showsData):
|
|
|
|
|
for showData in showsData:
|
|
|
|
|
showData.Print()
|
2013-07-06 20:18:52 +10:00
|
|
|
|
2013-07-10 15:45:42 +10:00
|
|
|
|
2013-07-05 15:35:12 +10:00
|
|
|
def main(argv):
|
|
|
|
|
numFiles = 0
|
2013-07-05 21:27:53 +10:00
|
|
|
doEncode = False
|
2013-07-10 11:13:42 +10:00
|
|
|
readOnly = False
|
2013-07-05 21:27:53 +10:00
|
|
|
doList = False
|
2013-07-10 15:45:42 +10:00
|
|
|
|
2013-07-05 15:35:12 +10:00
|
|
|
try:
|
2013-07-10 15:45:42 +10:00
|
|
|
opts, args = getopt.getopt(argv, "hlpen:")
|
2013-07-05 15:35:12 +10:00
|
|
|
except getopt.GetoptError:
|
2013-07-10 15:45:42 +10:00
|
|
|
ShowHelp()
|
|
|
|
|
sys.exit(2)
|
2013-07-05 15:35:12 +10:00
|
|
|
for opt, arg in opts:
|
2013-07-10 15:45:42 +10:00
|
|
|
if opt == '-h':
|
|
|
|
|
ShowHelp()
|
|
|
|
|
sys.exit()
|
|
|
|
|
elif opt == "-p":
|
|
|
|
|
doEncode = False
|
|
|
|
|
elif opt == "-e":
|
|
|
|
|
doEncode = True
|
|
|
|
|
elif opt == "-n":
|
|
|
|
|
numFiles = arg
|
|
|
|
|
elif opt == "-l":
|
|
|
|
|
readOnly = True
|
|
|
|
|
doList = True
|
|
|
|
|
|
2013-07-08 17:21:42 +10:00
|
|
|
settings = Settings("settings.cfg")
|
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-08 17:21:42 +10:00
|
|
|
fileManager = FileManager(settings)
|
|
|
|
|
showData = fileManager.GetEncodingFiles(readOnly)
|
2013-07-05 21:27:53 +10:00
|
|
|
PrintShowsToEncode(showData)
|
|
|
|
|
else:
|
|
|
|
|
# Generate the list of files to process
|
2013-07-08 17:21:42 +10:00
|
|
|
fileManager = FileManager(settings)
|
|
|
|
|
shows = fileManager.GetFilesToPrepare(numFiles)
|
2013-07-06 21:20:21 +10:00
|
|
|
print "num results: {0}".format(len(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-08 17:21:42 +10:00
|
|
|
fileManager = FileManager(settings)
|
|
|
|
|
showData = fileManager.GetEncodingFiles(readOnly)
|
2013-07-10 15:45:42 +10:00
|
|
|
|
2013-07-05 21:27:53 +10:00
|
|
|
for show in showData:
|
2013-07-08 17:21:42 +10:00
|
|
|
if fileManager.CheckFileExists(show.outputFile):
|
2013-07-10 15:45:42 +10:00
|
|
|
print "File {0} already exists. Cannot process." \
|
|
|
|
|
.format(show.outputFile)
|
2013-07-05 21:27:53 +10:00
|
|
|
else:
|
2013-07-10 11:14:45 +10:00
|
|
|
encoder = Encoder(settings.HandbrakeCommand())
|
2013-07-08 17:21:42 +10:00
|
|
|
result = encoder.Encode(show.inputFile, show.outputFile)
|
2013-07-10 15:45:42 +10:00
|
|
|
|
|
|
|
|
fileManager.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-10 15:45:42 +10:00
|
|
|
fileManager = FileManager(settings)
|
2013-07-08 17:21:42 +10:00
|
|
|
shows = fileManager.GetFilesToPrepare(numFiles)
|
2013-07-09 12:14:02 +10:00
|
|
|
tvData = TVData(settings)
|
|
|
|
|
tvData.PrepareEpisodes(shows)
|
2013-07-05 15:35:12 +10:00
|
|
|
|
2013-07-10 15:45:42 +10:00
|
|
|
|
2013-07-05 15:35:12 +10:00
|
|
|
if __name__ == "__main__":
|
2013-07-09 20:28:47 +10:00
|
|
|
main(sys.argv[1:])
|