mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
Massive changes to the way we handle our config, its now loaded and stored in memory so that we don't keep loading it and possibly get corrupt values.
New logger class added,logger options removed from settings.
This commit is contained in:
parent
d8a3bdb7dc
commit
18926d1db8
30 changed files with 1603 additions and 1058 deletions
|
@ -1,48 +1,44 @@
|
|||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import socket
|
||||
import urllib
|
||||
import nzbtomedia
|
||||
from lib import requests
|
||||
from nzbtomedia.nzbToMediaConfig import config
|
||||
from nzbtomedia.nzbToMediaUtil import convert_to_ascii, getDirectorySize
|
||||
|
||||
Logger = logging.getLogger()
|
||||
from nzbtomedia import logger
|
||||
|
||||
class autoProcessMusic:
|
||||
def process(self, dirName, nzbName=None, status=0, clientAgent="manual", inputCategory=None):
|
||||
if dirName is None:
|
||||
Logger.error("No directory was given!")
|
||||
logger.error("No directory was given!")
|
||||
return 1 # failure
|
||||
|
||||
# auto-detect correct section
|
||||
section = config().findsection(inputCategory)
|
||||
section = nzbtomedia.CFG.findsection(inputCategory)
|
||||
if len(section) == 0:
|
||||
Logger.error(
|
||||
"MAIN: We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
logger.error(
|
||||
"We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
return 1
|
||||
|
||||
socket.setdefaulttimeout(int(config.NZBTOMEDIA_TIMEOUT)) #initialize socket timeout.
|
||||
|
||||
Logger.info("Loading config from %s", config.CONFIG_FILE)
|
||||
logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE)
|
||||
|
||||
status = int(status)
|
||||
|
||||
host = config()[section][inputCategory]["host"]
|
||||
port = config()[section][inputCategory]["port"]
|
||||
apikey = config()[section][inputCategory]["apikey"]
|
||||
delay = float(config()[section][inputCategory]["delay"])
|
||||
host = nzbtomedia.CFG[section][inputCategory]["host"]
|
||||
port = nzbtomedia.CFG[section][inputCategory]["port"]
|
||||
apikey = nzbtomedia.CFG[section][inputCategory]["apikey"]
|
||||
delay = float(nzbtomedia.CFG[section][inputCategory]["delay"])
|
||||
|
||||
try:
|
||||
ssl = int(config()[section][inputCategory]["ssl"])
|
||||
ssl = int(nzbtomedia.CFG[section][inputCategory]["ssl"])
|
||||
except:
|
||||
ssl = 0
|
||||
try:
|
||||
web_root = config()[section][inputCategory]["web_root"]
|
||||
web_root = nzbtomedia.CFG[section][inputCategory]["web_root"]
|
||||
except:
|
||||
web_root = ""
|
||||
try:
|
||||
TimePerGiB = int(config()[section][inputCategory]["TimePerGiB"])
|
||||
TimePerGiB = int(nzbtomedia.CFG[section][inputCategory]["TimePerGiB"])
|
||||
except:
|
||||
TimePerGiB = 60 # note, if using Network to transfer on 100Mbit LAN, expect ~ 600 MB/minute.
|
||||
|
||||
|
@ -72,27 +68,27 @@ class autoProcessMusic:
|
|||
|
||||
url = baseURL + urllib.urlencode(params)
|
||||
|
||||
Logger.info("Waiting for %s seconds to allow HeadPhones to process newly extracted files", str(delay))
|
||||
logger.postprocess("Waiting for %s seconds to allow HeadPhones to process newly extracted files", str(delay))
|
||||
|
||||
time.sleep(delay)
|
||||
|
||||
Logger.debug("Opening URL: %s", url)
|
||||
logger.debug("Opening URL: %s", url)
|
||||
|
||||
try:
|
||||
r = requests.get(url)
|
||||
except requests.ConnectionError:
|
||||
Logger.exception("Unable to open URL")
|
||||
logger.error("Unable to open URL")
|
||||
return 1 # failure
|
||||
|
||||
Logger.info("HeadPhones returned %s", r.text)
|
||||
logger.postprocess("HeadPhones returned %s", r.text)
|
||||
if r.text == "OK":
|
||||
Logger.info("Post-processing started on HeadPhones for %s in folder %s", nzbName, dirName)
|
||||
logger.postprocess("Post-processing started on HeadPhones for %s in folder %s", nzbName, dirName)
|
||||
else:
|
||||
Logger.error("Post-proecssing has NOT started on HeadPhones for %s in folder %s. Exiting", nzbName, dirName)
|
||||
logger.error("Post-proecssing has NOT started on HeadPhones for %s in folder %s. Exiting", nzbName, dirName)
|
||||
return 1 # failure
|
||||
|
||||
else:
|
||||
Logger.info("The download failed. Nothing to process")
|
||||
logger.postprocess("The download failed. Nothing to process")
|
||||
return 0 # Success (as far as this script is concerned)
|
||||
|
||||
if clientAgent == "manual":
|
||||
|
@ -104,7 +100,7 @@ class autoProcessMusic:
|
|||
while (datetime.datetime.now() - start) < datetime.timedelta(minutes=1): # only wait 2 minutes, then return to TorrentToMedia
|
||||
time.sleep(20) # Just stop this looping infinitely and hogging resources for 2 minutes ;)
|
||||
else: # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now.
|
||||
Logger.info("This album should have completed processing. Please check HeadPhones Logs")
|
||||
# Logger.warning("The album does not appear to have changed status after 2 minutes. Please check HeadPhones Logs")
|
||||
logger.postprocess("This album should have completed processing. Please check HeadPhones Logs")
|
||||
# logger.warning("The album does not appear to have changed status after 2 minutes. Please check HeadPhones Logs")
|
||||
# return 1 # failure
|
||||
return 0 # success for now.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue