mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-13 08:42:55 -07:00
some minor cleanups
This commit is contained in:
parent
f1a9d62fde
commit
c49e9c702d
1 changed files with 27 additions and 31 deletions
|
@ -32,6 +32,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash):
|
||||||
video = int(0)
|
video = int(0)
|
||||||
video2 = int(0)
|
video2 = int(0)
|
||||||
foundFile = int(0)
|
foundFile = int(0)
|
||||||
|
deleteOriginal = int(0)
|
||||||
extractionSuccess = False
|
extractionSuccess = False
|
||||||
|
|
||||||
Logger.debug("MAIN: Received Directory: %s | Name: %s | Category: %s", inputDirectory, inputName, inputCategory)
|
Logger.debug("MAIN: Received Directory: %s | Name: %s | Category: %s", inputDirectory, inputName, inputCategory)
|
||||||
|
@ -57,11 +58,12 @@ def main(inputDirectory, inputName, inputCategory, inputHash):
|
||||||
targetDirectory = os.path.join(outputDestination, file)
|
targetDirectory = os.path.join(outputDestination, file)
|
||||||
|
|
||||||
if root == 1:
|
if root == 1:
|
||||||
Logger.debug("MAIN: Looking for %s in filename", inputName)
|
if not foundFile:
|
||||||
if (safeName(inputName) in safeName(file)) or (safeName(os.path.splitext(file)[0]) in safeName(inputName)) and foundFile = 0:
|
Logger.debug("MAIN: Looking for %s in: %s", inputName, file)
|
||||||
|
if (safeName(inputName) in safeName(file)) or (safeName(os.path.splitext(file)[0]) in safeName(inputName)) and foundFile == 0:
|
||||||
pass # This file does match the Torrent name
|
pass # This file does match the Torrent name
|
||||||
foundFile = 1
|
foundFile = 1
|
||||||
Logger.debug("Found file %s that matches Torrent Name %s", file, inputName)
|
Logger.debug("MAIN: Found file %s that matches Torrent Name %s", file, inputName)
|
||||||
else:
|
else:
|
||||||
continue # This file does not match the Torrent name, skip it
|
continue # This file does not match the Torrent name, skip it
|
||||||
|
|
||||||
|
@ -69,10 +71,10 @@ def main(inputDirectory, inputName, inputCategory, inputHash):
|
||||||
Logger.debug("MAIN: Looking for files with modified/created dates less than 5 minutes old.")
|
Logger.debug("MAIN: Looking for files with modified/created dates less than 5 minutes old.")
|
||||||
mtime_lapse = now - datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(dirpath, file)))
|
mtime_lapse = now - datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(dirpath, file)))
|
||||||
ctime_lapse = now - datetime.datetime.fromtimestamp(os.path.getctime(os.path.join(dirpath, file)))
|
ctime_lapse = now - datetime.datetime.fromtimestamp(os.path.getctime(os.path.join(dirpath, file)))
|
||||||
if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)) and foundFile = 0:
|
if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)) and foundFile == 0:
|
||||||
pass # This file does match the date time criteria
|
pass # This file does match the date time criteria
|
||||||
foundFile = 1
|
foundFile = 1
|
||||||
Logger.debug("Found file %s with date modifed/created less than 5 minutes ago.", file)
|
Logger.debug("MAIN: Found file %s with date modifed/created less than 5 minutes ago.", file)
|
||||||
else:
|
else:
|
||||||
continue # This file has not been recently moved or created, skip it
|
continue # This file has not been recently moved or created, skip it
|
||||||
|
|
||||||
|
@ -118,19 +120,6 @@ def main(inputDirectory, inputName, inputCategory, inputHash):
|
||||||
continue
|
continue
|
||||||
flatten(outputDestination)
|
flatten(outputDestination)
|
||||||
|
|
||||||
#### quick 'n dirty hardlink solution for uTorrent, need to implent support for deluge, transmission
|
|
||||||
if not extractionSuccess and inputHash and useLink != 0 and clientAgent == 'utorrent':
|
|
||||||
try:
|
|
||||||
Logger.debug("MAIN: Connecting to uTorrent: %s", uTorrentWEBui)
|
|
||||||
utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD)
|
|
||||||
except Exception as e:
|
|
||||||
Logger.error("MAIN: Failed to connect to uTorrent: %s", e)
|
|
||||||
|
|
||||||
Logger.debug("MAIN: Stoping torrent %s in uTorrent while processing", inputName)
|
|
||||||
utorrentClass.stop(inputHash)
|
|
||||||
time.sleep(5) # Give uTorrent some time to catch up with the change
|
|
||||||
##### quick 'n dirty hardlink solution for uTorrent, need to implent support for deluge, transmission
|
|
||||||
|
|
||||||
# Now check if movie files exist in destination:
|
# Now check if movie files exist in destination:
|
||||||
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
|
@ -145,30 +134,38 @@ def main(inputDirectory, inputName, inputCategory, inputHash):
|
||||||
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
|
||||||
|
|
||||||
#### Delete original files from uTorrent
|
# Hardlink solution for uTorrent, need to implent support for deluge, transmission
|
||||||
if deleteOriginal != 0 and clientAgent == 'utorrent':
|
if clientAgent == 'utorrent' and extractionSuccess == False and inputHash:
|
||||||
try:
|
try:
|
||||||
Logger.debug("MAIN: Connecting to uTorrent: %s", uTorrentWEBui)
|
Logger.debug("MAIN: Connecting to uTorrent: %s", uTorrentWEBui)
|
||||||
utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD)
|
utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.error("MAIN: Failed to connect to uTorrent: %s", e)
|
Logger.error("MAIN: Failed to connect to uTorrent: %s", e)
|
||||||
|
|
||||||
Logger.debug("MAIN: Deleting torrent %s from uTorrent", inputName)
|
# if we are using links with uTorrent it means we need to pause it in order to access the files
|
||||||
utorrentClass.removedata(inputHash)
|
if useLink == 1:
|
||||||
|
Logger.debug("MAIN: Stoping torrent %s in uTorrent while processing", inputName)
|
||||||
|
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
|
||||||
|
|
||||||
|
# Delete torrent and torrentdata from uTorrent
|
||||||
|
if deleteOriginal == 1:
|
||||||
|
Logger.debug("MAIN: Deleting torrent %s from uTorrent", inputName)
|
||||||
|
utorrentClass.removedata(inputHash)
|
||||||
|
utorrentClass.remove(inputHash)
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
processCategories = {cpsCategory, sbCategory, hpCategory, mlCategory, gzCategory}
|
processCategories = {cpsCategory, sbCategory, hpCategory, mlCategory, gzCategory}
|
||||||
|
|
||||||
if inputCategory and not (inputCategory in processCategories): # no extra processign to be done... yet.
|
if inputCategory and not (inputCategory in processCategories): # no extra processign to be done... yet.
|
||||||
Logger.info("MAIN: No further processing to be done for category %s.", inputCategory)
|
Logger.info("MAIN: No further processing to be done for category %s.", inputCategory)
|
||||||
result = 1
|
result = 1
|
||||||
elif status == 0: #### Maybe we should move this to a more appropriate place?
|
elif status == 0:
|
||||||
Logger.info("MAIN: Successful run")
|
|
||||||
Logger.debug("MAIN: Calling autoProcess script for successful download.")
|
Logger.debug("MAIN: Calling autoProcess script for successful download.")
|
||||||
else:
|
else:
|
||||||
Logger.error("MAIN: Something failed! Please check logs. Exiting")
|
Logger.error("MAIN: Something failed! Please check logs. Exiting")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Now we pass off to CouchPotato or Sick-Beard
|
|
||||||
if inputCategory == cpsCategory:
|
if inputCategory == cpsCategory:
|
||||||
Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName)
|
Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName)
|
||||||
result = autoProcessMovie.process(outputDestination, inputName, status)
|
result = autoProcessMovie.process(outputDestination, inputName, status)
|
||||||
|
@ -188,11 +185,10 @@ def main(inputDirectory, inputName, inputCategory, inputHash):
|
||||||
if result == 1:
|
if result == 1:
|
||||||
Logger.info("MAIN: A problem was reported in the autoProcess* script. If torrent was pasued we will resume seeding")
|
Logger.info("MAIN: A problem was reported in the autoProcess* script. If torrent was pasued we will resume seeding")
|
||||||
|
|
||||||
#### quick 'n dirty hardlink solution for uTorrent, need to implent support for deluge, transmission
|
# Hardlink solution for uTorrent, need to implent support for deluge, transmission
|
||||||
if not extractionSuccess and inputHash and useLink != 0 and clientAgent == 'utorrent' and deleteOriginal == 0: # we always want to resume seeding, for now manually find out what is wrong when extraction fails
|
if clientAgent == 'utorrent' and extractionSuccess == False and inputHash and useLink == 1 and deleteOriginal == 0: # we always want to resume seeding, for now manually find out what is wrong when extraction fails
|
||||||
Logger.debug("MAIN: Starting torrent %s in uTorrent", inputName)
|
Logger.debug("MAIN: Starting torrent %s in uTorrent", inputName)
|
||||||
utorrentClass.start(inputHash)
|
utorrentClass.start(inputHash)
|
||||||
#### quick 'n dirty hardlink solution for uTorrent, need to implent support for deluge, transmission
|
|
||||||
|
|
||||||
Logger.info("MAIN: All done.")
|
Logger.info("MAIN: All done.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue