Merge pull request #2 from clinton-hall/dev

Dev
This commit is contained in:
Joel Kåberg 2013-02-26 00:09:53 -08:00
commit b53615cd48
2 changed files with 48 additions and 18 deletions

View file

@ -22,6 +22,11 @@ from utorrent.client import UTorrentClient
nzbtomedia_configure_logging(os.path.dirname(sys.argv[0])) nzbtomedia_configure_logging(os.path.dirname(sys.argv[0]))
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
def category_search_recurs(inputDirectory, inputName, root, categories):
pass
def category_search(inputDirectory, inputName, inputCategory, root, categories): def category_search(inputDirectory, inputName, inputCategory, root, categories):
categorySearch = [os.path.normpath(inputDirectory),""] #initializie categorySearch = [os.path.normpath(inputDirectory),""] #initializie
notfound = 0 notfound = 0
@ -272,7 +277,7 @@ config.read(configFilename)
clientAgent = config.get("Torrent", "clientAgent") clientAgent = config.get("Torrent", "clientAgent")
try: try:
parse_args(clientAgent) inputDirectory, inputName, inputCategory = parse_args(clientAgent)
except: except:
Logger.error("MAIN: There was a problem loading variables: Exiting") Logger.error("MAIN: There was a problem loading variables: Exiting")
sys.exit(-1) sys.exit(-1)
@ -388,6 +393,7 @@ for dirpath, dirnames, filenames in os.walk(outputDestination):
Logger.info("file %s is a sample file. Removing", filePath) Logger.info("file %s is a sample file. Removing", filePath)
os.unlink(filePath) #remove samples os.unlink(filePath) #remove samples
else: else:
videofile = filePath
video2 = video2 + 1 video2 = video2 + 1
if video2 >= video and video2 > 0: # Check that all video files were moved if video2 >= video and video2 > 0: # Check that all video files were moved
status = 0 status = 0
@ -403,12 +409,6 @@ elif failed_extract == 1 and failed_link == 0: #failed to extract files only.
else: else:
Logger.info("MAIN: Something failed! Please check logs. Exiting") Logger.info("MAIN: Something failed! Please check logs. Exiting")
sys.exit(-1) sys.exit(-1)
# Now we pass off to CouchPotato or Sick-Beard
# Log this output
old_stdout = sys.stdout # Still crude, but we wat to capture this for now
logFile = os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log")
log_file = open(logFile,"a+")
sys.stdout = log_file
# Hardlink solution with uTorrent # Hardlink solution with uTorrent
if inputHash and useLink: if inputHash and useLink:
@ -416,16 +416,32 @@ if inputHash and useLink:
utorrentClass.stop(inputHash) utorrentClass.stop(inputHash)
time.sleep(5) # Give uTorrent some time to catch up with the change time.sleep(5) # Give uTorrent some time to catch up with the change
# Log this output
old_stdout = sys.stdout # Still crude, but we wat to capture this for now
logFile = os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log")
log_file = open(logFile,"a+")
sys.stdout = log_file
# Now we pass off to CouchPotato or Sick-Beard
if inputCategory == movieCategory: if inputCategory == movieCategory:
Logger.info("MAIN: Calling postprocessing script for CouchPotatoServer") Logger.info("MAIN: Calling postprocessing script for CouchPotatoServer") ###can we use logger while logfile open?
autoProcessMovie.process(outputDestination, inputName, status) autoProcessMovie.process(outputDestination, inputName, status)
elif inputCategory == tvCategory: elif inputCategory == tvCategory:
Logger.info("MAIN: Calling postprocessing script for Sick-Beard") Logger.info("MAIN: Calling postprocessing script for Sick-Beard") ###can we use logger while logfile open?
autoProcessTV.processEpisode(outputDestination, inputName, status) autoProcessTV.processEpisode(outputDestination, inputName, status)
sys.stdout = old_stdout
log_file.close()
now = datetime.datetime.now() #set time for timeout
while os.path.exists(videofile): #while this file is still here, CPS hasn't finished renaming
if (datetime.datetime.now() - now) > datetime.timedelta(minutes=3): #note; minimum 1 minute delay in autoProcessMovie
Logger.info("MAIN: The file %s has not been moved after 3 minutes.")
break
else: #CPS (and SickBeard) have finished. We can now resume seeding.
Logger.info("MAIN: The file %s has been moved. Postprocessing appears to have succeeded." %videofile)
# Hardlink solution with uTorrent # Hardlink solution with uTorrent
if inputHash and useLink: if inputHash and useLink:
Logger.debug("MAIN: We are using hardlinks with uTorrent, calling uTorrent to resume download") Logger.debug("MAIN: We are using hardlinks with uTorrent, calling uTorrent to resume download")
utorrentClass.start(inputHash) utorrentClass.start(inputHash)
sys.stdout = old_stdout
log_file.close()

View file

@ -13,32 +13,45 @@ def nzbtomedia_configure_logging(dirname):
fileHandler.level = logging.DEBUG fileHandler.level = logging.DEBUG
logging.getLogger().addHandler(fileHandler) logging.getLogger().addHandler(fileHandler)
def parse_other(args): def parse_other(args):
return os.path.normpath(sys.argv[1]), '', '' return os.path.normpath(sys.argv[1]), '', ''
def parse_utorrent(args): def parse_utorrent(args):
# uTorrent usage: call TorrentToMedia.py "%D" "%N" "%L" "%I" # uTorrent usage: call TorrentToMedia.py "%D" "%N" "%L" "%I"
inputDirectory = os.path.normpath(sys.argv[2]) inputDirectory = os.path.normpath(sys.argv[1])
inputName = sys.argv[3] inputName = sys.argv[2]
try: try:
inputCategory = sys.argv[4] inputCategory = sys.argv[3]
except: except:
inputCategory = '' inputCategory = ''
inputHash = sys.argv[5] try:
if inputHash and useLink: inputHash = sys.argv[4]
except:
inputHash = ''
if inputHash:
utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD) utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD)
return inputDirectory, inputName, inputCategory
def parse_deluge(args): def parse_deluge(args):
# Deluge usage: call TorrentToMedia.py TORRENT_ID TORRENT_NAME TORRENT_DIR # Deluge usage: call TorrentToMedia.py TORRENT_ID TORRENT_NAME TORRENT_DIR
inputDirectory = os.path.normpath(sys.argv[3]) inputDirectory = os.path.normpath(sys.argv[3])
inputName = sys.argv[2] inputName = sys.argv[2]
inputCategory = '' # We dont have a category yet inputCategory = '' # We dont have a category yet
return inputDirectory, inputName, inputCategory
def parse_transmission(args): def parse_transmission(args):
# Transmission usage: call TorrenToMedia.py (%TR_TORRENT_DIR% %TR_TORRENT_NAME% is passed on as environmental variables) # Transmission usage: call TorrenToMedia.py (%TR_TORRENT_DIR% %TR_TORRENT_NAME% is passed on as environmental variables)
inputDirectory = os.path.normpath(os.getenv('TR_TORRENT_DIR')) inputDirectory = os.path.normpath(os.getenv('TR_TORRENT_DIR'))
inputName = os.getenv('TR_TORRENT_NAME') inputName = os.getenv('TR_TORRENT_NAME')
inputCategory = '' # We dont have a category yet inputCategory = '' # We dont have a category yet
return inputDirectory, inputName, inputCategory
__ARG_PARSERS__ = { __ARG_PARSERS__ = {
'other': parse_other, 'other': parse_other,
@ -47,8 +60,9 @@ __ARG_PARSERS__ = {
'transmission': parse_transmission, 'transmission': parse_transmission,
} }
def parse_args(clientAgent): def parse_args(clientAgent):
parseFunc = __ARG_PARSERS__.get(clientAgent, None) parseFunc = __ARG_PARSERS__.get(clientAgent, None)
if not parseFunc: if not parseFunc:
raise RuntimeError("Could not find client-agent") raise RuntimeError("Could not find client-agent")
parseFunc(sys.argv) return parseFunc(sys.argv)