mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-15 01:32:53 -07:00
add exception on logging close #83
This commit is contained in:
parent
b363473463
commit
2950caad33
9 changed files with 50 additions and 63 deletions
|
@ -90,16 +90,14 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
Logger.info("MAIN: Found video file %s in %s", fileExtension, filePath)
|
Logger.info("MAIN: Found video file %s in %s", fileExtension, filePath)
|
||||||
try:
|
try:
|
||||||
copy_link(filePath, targetDirectory, useLink, outputDestination)
|
copy_link(filePath, targetDirectory, useLink, outputDestination)
|
||||||
except Exception as e:
|
except:
|
||||||
Logger.error("MAIN: Failed to link file: %s", file)
|
Logger.exception("MAIN: Failed to link file: %s", file)
|
||||||
Logger.debug(e)
|
|
||||||
elif fileExtension in metaContainer:
|
elif fileExtension in metaContainer:
|
||||||
Logger.info("MAIN: Found metadata file %s for file %s", fileExtension, filePath)
|
Logger.info("MAIN: Found metadata file %s for file %s", fileExtension, filePath)
|
||||||
try:
|
try:
|
||||||
copy_link(filePath, targetDirectory, useLink, outputDestination)
|
copy_link(filePath, targetDirectory, useLink, outputDestination)
|
||||||
except Exception as e:
|
except:
|
||||||
Logger.error("MAIN: Failed to link file: %s", file)
|
Logger.exception("MAIN: Failed to link file: %s", file)
|
||||||
Logger.debug(e)
|
|
||||||
elif fileExtension in compressedContainer:
|
elif fileExtension in compressedContainer:
|
||||||
numCompressed = numCompressed + 1
|
numCompressed = numCompressed + 1
|
||||||
if re.search(r'\d+', os.path.splitext(fileName)[1]) and numCompressed > 1: # find part numbers in second "extension" from right, if we have more than 1 compressed file.
|
if re.search(r'\d+', os.path.splitext(fileName)[1]) and numCompressed > 1: # find part numbers in second "extension" from right, if we have more than 1 compressed file.
|
||||||
|
@ -113,9 +111,8 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
try:
|
try:
|
||||||
extractor.extract(filePath, outputDestination)
|
extractor.extract(filePath, outputDestination)
|
||||||
extractionSuccess = True # we use this variable to determine if we need to pause a torrent or not in uTorrent (dont need to pause archived content)
|
extractionSuccess = True # we use this variable to determine if we need to pause a torrent or not in uTorrent (dont need to pause archived content)
|
||||||
except Exception as e:
|
except:
|
||||||
Logger.warn("MAIN: Extraction failed for: %s", file)
|
Logger.exception("MAIN: Extraction failed for: %s", file)
|
||||||
Logger.debug(e)
|
|
||||||
else:
|
else:
|
||||||
Logger.debug("MAIN: Ignoring unknown filetype %s for file %s", fileExtension, filePath)
|
Logger.debug("MAIN: Ignoring unknown filetype %s for file %s", fileExtension, filePath)
|
||||||
continue
|
continue
|
||||||
|
@ -140,8 +137,8 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
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:
|
||||||
Logger.error("MAIN: Failed to connect to uTorrent: %s", e)
|
Logger.exception("MAIN: Failed to connect to uTorrent")
|
||||||
|
|
||||||
# if we are using links with uTorrent it means we need to pause it in order to access the files
|
# if we are using links with uTorrent it means we need to pause it in order to access the files
|
||||||
if useLink != "no":
|
if useLink != "no":
|
||||||
|
@ -256,8 +253,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent)
|
inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent)
|
||||||
except Exception as e:
|
except:
|
||||||
Logger.error("MAIN: There was a problem loading variables: %s", e)
|
Logger.exception("MAIN: There was a problem loading variables")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
main(inputDirectory, inputName, inputCategory, inputHash, inputID)
|
main(inputDirectory, inputName, inputCategory, inputHash, inputID)
|
||||||
|
|
|
@ -101,8 +101,8 @@ def Transcode_directory(dirName):
|
||||||
result = 1 # set result to failed in case call fails.
|
result = 1 # set result to failed in case call fails.
|
||||||
try:
|
try:
|
||||||
result = call(command)
|
result = call(command)
|
||||||
except e:
|
except:
|
||||||
Logger.error("Transcoding of video %s failed due to: ", filePath, str(e))
|
Logger.exception("Transcoding of video %s has failed", filePath)
|
||||||
if result == 0:
|
if result == 0:
|
||||||
Logger.info("Transcoding of video %s to %s succeded", filePath, newfilePath)
|
Logger.info("Transcoding of video %s to %s succeded", filePath, newfilePath)
|
||||||
if duplicate == 0: # we get rid of the original file
|
if duplicate == 0: # we get rid of the original file
|
||||||
|
|
|
@ -39,13 +39,7 @@ def processEpisode(dirName, nzbName=None, status=0):
|
||||||
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
|
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
try:
|
config.read(configFilename)
|
||||||
fp = open(configFilename, "r")
|
|
||||||
config.readfp(fp)
|
|
||||||
fp.close()
|
|
||||||
except IOError, e:
|
|
||||||
Logger.error("Could not read configuration file: %s", str(e))
|
|
||||||
return 1 # failure
|
|
||||||
|
|
||||||
host = config.get("Mylar", "host")
|
host = config.get("Mylar", "host")
|
||||||
port = config.get("Mylar", "port")
|
port = config.get("Mylar", "port")
|
||||||
|
@ -80,8 +74,8 @@ def processEpisode(dirName, nzbName=None, status=0):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
result = urlObj.readlines()
|
result = urlObj.readlines()
|
||||||
|
|
|
@ -80,8 +80,8 @@ def process(dirName, nzbName=None, status=0):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
result = json.load(urlObj)
|
result = json.load(urlObj)
|
||||||
|
|
|
@ -69,8 +69,8 @@ def get_movie_info(myOpener, baseURL, imdbid, download_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
movie_id = ""
|
movie_id = ""
|
||||||
|
@ -100,9 +100,9 @@ def get_movie_info(myOpener, baseURL, imdbid, download_id):
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
if not imdbid:
|
if not imdbid:
|
||||||
Logger.error("Could not parse database results to determine imdbid or movie id")
|
Logger.exception("Could not parse database results to determine imdbid or movie id")
|
||||||
else:
|
else:
|
||||||
Logger.error("Could not parse database results to determine movie id for imdbid: %s", imdbid)
|
Logger.exception("Could not parse database results to determine movie id for imdbid: %s", imdbid)
|
||||||
|
|
||||||
return movie_id
|
return movie_id
|
||||||
|
|
||||||
|
@ -116,15 +116,15 @@ def get_status(myOpener, baseURL, movie_id, clientAgent, download_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return "", clientAgent, "none", "none"
|
return "", clientAgent, "none", "none"
|
||||||
result = json.load(urlObj)
|
result = json.load(urlObj)
|
||||||
try:
|
try:
|
||||||
movie_status = result["movie"]["status"]["identifier"]
|
movie_status = result["movie"]["status"]["identifier"]
|
||||||
Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status)
|
Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status)
|
||||||
except e: # index out of range/doesn't exist?
|
except: # index out of range/doesn't exist?
|
||||||
Logger.error("Could not find a status for this movie due to: %s", str(e))
|
Logger.exception("Could not find a status for this movie")
|
||||||
movie_status = ""
|
movie_status = ""
|
||||||
try:
|
try:
|
||||||
release_status = "none"
|
release_status = "none"
|
||||||
|
@ -180,7 +180,7 @@ def get_status(myOpener, baseURL, movie_id, clientAgent, download_id):
|
||||||
Logger.info("Could not find a download_id in the database for this movie")
|
Logger.info("Could not find a download_id in the database for this movie")
|
||||||
release_status = "none"
|
release_status = "none"
|
||||||
except: # index out of range/doesn't exist?
|
except: # index out of range/doesn't exist?
|
||||||
Logger.error("Could not find a download_id for this movie")
|
Logger.exception("Could not find a download_id for this movie")
|
||||||
download_id = "none"
|
download_id = "none"
|
||||||
return movie_status, clientAgent, download_id, release_status
|
return movie_status, clientAgent, download_id, release_status
|
||||||
|
|
||||||
|
@ -268,8 +268,8 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
result = json.load(urlObj)
|
result = json.load(urlObj)
|
||||||
|
@ -296,8 +296,8 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
result = urlObj.readlines()
|
result = urlObj.readlines()
|
||||||
|
@ -309,8 +309,8 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id
|
||||||
Logger.info("Deleting failed files and folder %s", dirName)
|
Logger.info("Deleting failed files and folder %s", dirName)
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(dirName)
|
shutil.rmtree(dirName)
|
||||||
except e:
|
except:
|
||||||
Logger.error("Unable to delete folder %s due to: %s", dirName, str(e))
|
Logger.exception("Unable to delete folder %s", dirName)
|
||||||
return 0 # success
|
return 0 # success
|
||||||
|
|
||||||
if nzbName == "Manual Run":
|
if nzbName == "Manual Run":
|
||||||
|
|
|
@ -85,8 +85,8 @@ def process(dirName, nzbName=None, status=0):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
result = urlObj.readlines()
|
result = urlObj.readlines()
|
||||||
|
|
|
@ -54,8 +54,8 @@ def delete(dirName):
|
||||||
Logger.info("Deleting failed files and folder %s", dirName)
|
Logger.info("Deleting failed files and folder %s", dirName)
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(dirName)
|
shutil.rmtree(dirName)
|
||||||
except e:
|
except:
|
||||||
Logger.error("Unable to delete folder %s due to: %s", dirName, str(e))
|
Logger.exception("Unable to delete folder %s", dirName)
|
||||||
|
|
||||||
|
|
||||||
def processEpisode(dirName, nzbName=None, failed=False):
|
def processEpisode(dirName, nzbName=None, failed=False):
|
||||||
|
@ -69,13 +69,7 @@ def processEpisode(dirName, nzbName=None, failed=False):
|
||||||
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
|
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
try:
|
config.read(configFilename)
|
||||||
fp = open(configFilename, "r")
|
|
||||||
config.readfp(fp)
|
|
||||||
fp.close()
|
|
||||||
except IOError, e:
|
|
||||||
Logger.error("Could not read configuration file: %s", str(e))
|
|
||||||
return 1 # failure
|
|
||||||
|
|
||||||
watch_dir = ""
|
watch_dir = ""
|
||||||
host = config.get("SickBeard", "host")
|
host = config.get("SickBeard", "host")
|
||||||
|
@ -174,8 +168,8 @@ def processEpisode(dirName, nzbName=None, failed=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlObj = myOpener.openit(url)
|
urlObj = myOpener.openit(url)
|
||||||
except IOError, e:
|
except:
|
||||||
Logger.error("Unable to open URL: %s", str(e))
|
Logger.exception("Unable to open URL")
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
result = urlObj.readlines()
|
result = urlObj.readlines()
|
||||||
|
|
|
@ -34,8 +34,8 @@ def create_destination(outputDestination):
|
||||||
try:
|
try:
|
||||||
Logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination)
|
Logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination)
|
||||||
os.makedirs(outputDestination)
|
os.makedirs(outputDestination)
|
||||||
except Exception, e:
|
except:
|
||||||
Logger.error("CREATE DESTINATION: Not possible to create destination folder: %s. Exiting", e)
|
Logger.exception("CREATE DESTINATION: Not possible to create destination folder. Exiting")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
||||||
|
@ -155,10 +155,11 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination):
|
||||||
Logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory)
|
Logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory)
|
||||||
linktastic.link(filePath, targetDirectory)
|
linktastic.link(filePath, targetDirectory)
|
||||||
except:
|
except:
|
||||||
|
Logger.exception("COPYLINK")
|
||||||
if os.path.isfile(targetDirectory):
|
if os.path.isfile(targetDirectory):
|
||||||
Logger.info("COPYLINK: Something went wrong in linktastic.link, but the destination file was created")
|
Logger.warn("COPYLINK: Something went wrong in linktastic.link, but the destination file was created")
|
||||||
else:
|
else:
|
||||||
Logger.info("COPYLINK: Something went wrong in linktastic.link, copying instead")
|
Logger.warn("COPYLINK: Something went wrong in linktastic.link, copying instead")
|
||||||
Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory)
|
Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory)
|
||||||
shutil.copy(filePath, targetDirectory)
|
shutil.copy(filePath, targetDirectory)
|
||||||
elif useLink == "sym":
|
elif useLink == "sym":
|
||||||
|
@ -168,8 +169,9 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination):
|
||||||
Logger.info("COPYLINK: Sym linking %s to %s", targetDirectory, filePath)
|
Logger.info("COPYLINK: Sym linking %s to %s", targetDirectory, filePath)
|
||||||
linktastic.symlink(targetDirectory, filePath)
|
linktastic.symlink(targetDirectory, filePath)
|
||||||
except:
|
except:
|
||||||
|
Logger.exception("COPYLINK")
|
||||||
if os.path.isfile(targetDirectory):
|
if os.path.isfile(targetDirectory):
|
||||||
Logger.info("COPYLINK: Something went wrong in linktastic.link, but the destination file was created")
|
Logger.warn("COPYLINK: Something went wrong in linktastic.link, but the destination file was created")
|
||||||
else:
|
else:
|
||||||
Logger.info("COPYLINK: Something went wrong in linktastic.link, copying instead")
|
Logger.info("COPYLINK: Something went wrong in linktastic.link, copying instead")
|
||||||
Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory)
|
Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory)
|
||||||
|
@ -190,8 +192,8 @@ def flatten(outputDestination):
|
||||||
target = os.path.join(outputDestination, filename)
|
target = os.path.join(outputDestination, filename)
|
||||||
try:
|
try:
|
||||||
shutil.move(source, target)
|
shutil.move(source, target)
|
||||||
except OSError:
|
except:
|
||||||
Logger.error("FLATTEN: Could not flatten %s", source)
|
Logger.exception("FLATTEN: Could not flatten %s", source)
|
||||||
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,6 @@ def extract(filePath, outputDestination):
|
||||||
else:
|
else:
|
||||||
Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res)
|
Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res)
|
||||||
except:
|
except:
|
||||||
Logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd)
|
Logger.exception("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd)
|
||||||
os.chdir(pwd) # Go back to our Original Working Directory
|
os.chdir(pwd) # Go back to our Original Working Directory
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue