Code cleanup

This commit is contained in:
echel0n 2014-04-17 07:25:08 -07:00
parent 92d00ed62a
commit cdadf045a8
15 changed files with 106 additions and 92 deletions

View file

@ -332,7 +332,7 @@ def main(args):
logger.postprocess("#########################################################")
# debug command line options
logger.debug("Options passed into TorrentToMedia: " + str(args))
logger.debug("Options passed into TorrentToMedia: %s", args)
# Post-Processing Result
result = 0

View file

@ -20,12 +20,12 @@
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
ssl = 0
web_root =
delay = 65
method = renamer
delete_failed = 0
wait_for = 2
#### # Set to path where completed downloads go on the remote CouchPotatoServer
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[SickBeard]
@ -40,13 +40,15 @@
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
web_root =
ssl = 0
delay = 0
watch_dir =
fork = auto
delete_failed = 0
nzbExtractionBy = Downloader
Torrent_NoLink = 0
process_method =
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[NzbDrone]
#### autoProcessing for TV Series
@ -61,11 +63,13 @@
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
web_root =
ssl = 0
delay = 0
watch_dir =
delete_failed = 0
nzbExtractionBy = Downloader
Torrent_NoLink = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[HeadPhones]
#### autoProcessing for Music
@ -78,7 +82,10 @@
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
ssl = 0
web_root =
delay = 65
wait_for = 2
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[Mylar]
@ -93,6 +100,9 @@
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
web_root=
ssl=0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[Gamez]
@ -106,6 +116,9 @@
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
ssl = 0
web_root =
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[Torrent]

View file

@ -47,14 +47,9 @@
# CouchPotato watch directory.
#
# set this if CouchPotato and nzbGet are on different systems.
# set this to where your CouchPotato completed downloads are.
#cpswatch_dir=
# CouchPotato Postprocess Delay.
#
# must be at least 60 seconds.
#cpsdelay=65
# CouchPotato Postprocess Method (renamer, manage).
#
# use "renamer" for CPS renamer (default) or "manage" to call a manage update.

View file

@ -46,6 +46,11 @@
# set this if using a reverse proxy.
#gzweb_root=
# Gamez watch directory.
#
# set this to where your Gamez completed downloads are.
#gzwatch_dir=
## WakeOnLan
# use WOL (0, 1).

View file

@ -45,10 +45,15 @@
# set this if using a reverse proxy.
#hpweb_root=
# HeadPhones Postprocess Delay.
# HeadPhones watch directory.
#
# set as required to ensure correct processing.
#hpdelay=65
# set this to where your HeadPhones completed downloads are.
#hpwatch_dir=
# HeadPhones wait_for
#
# Set the number of minutes to wait after initiating HeadPhones post-processing to check if the album status has changed.
#hpwait_for=2
## WakeOnLan

View file

@ -45,11 +45,6 @@
# set this if using a reverse proxy.
#cpsweb_root=
# CouchPotato Postprocess Delay.
#
# must be at least 60 seconds.
#cpsdelay=65
# CouchPotato Postprocess Method (renamer, manage).
#
# use "renamer" for CPS renamer (default) or "manage" to call a manage update.
@ -99,11 +94,6 @@
# set this if using a reverse proxy.
#sbweb_root=
# SickBeard delay
#
# Set the number of seconds to wait before calling post-process in SickBeard.
#sbdelay=0
# SickBeard watch directory.
#
# set this if SickBeard and nzbGet are on different systems.
@ -176,11 +166,6 @@
# set this if using a reverse proxy.
#hpweb_root=
# HeadPhones Postprocess Delay.
#
# set as required to ensure correct processing.
#hpdelay=65
## Mylar
# Mylar script category.
@ -338,7 +323,7 @@ def main(args, section=None):
logger.postprocess("#########################################################")
# debug command line options
logger.debug("Options passed into nzbToMedia: " + str(args))
logger.debug("Options passed into nzbToMedia: %s", args)
# Post-Processing Result
result = 0

View file

@ -49,6 +49,11 @@
# set this if using a reverse proxy.
#myweb_root=
# Mylar watch directory.
#
# set this to where your Mylar completed downloads are.
#mywatch_dir=
## WakeOnLan
# use WOL (0, 1).

View file

@ -48,14 +48,9 @@
# set this if using a reverse proxy.
#ndweb_root=
# NzbDrone delay
#
# Set the number of seconds to wait before calling post-process in NzbDrone.
#nddelay=0
# NzbDrone watch directory.
#
# set this if NzbDrone and nzbGet are on different systems.
# set this to where your NzbDrone completed downloads are.
#ndwatch_dir=
## Extensions

View file

@ -53,14 +53,9 @@
# set this if using a reverse proxy.
#sbweb_root=
# SickBeard delay
#
# Set the number of seconds to wait before calling post-process in SickBeard.
#sbdelay=0
# SickBeard watch directory.
#
# set this if SickBeard and nzbGet are on different systems.
# set this to where your SickBeard completed downloads are.
#sbwatch_dir=
# SickBeard fork.

View file

@ -1,4 +1,4 @@
import urllib
import os
import time
import nzbtomedia
from lib import requests
@ -38,17 +38,18 @@ class autoProcessComics:
web_root = ""
try:
watch_dir = nzbtomedia.CFG[section][inputCategory]["watch_dir"]
remote_path = nzbtomedia.CFG[section][inputCategory]["remote_path"]
except:
watch_dir = ""
params = {}
remote_path = None
nzbName, dirName = convert_to_ascii(nzbName, dirName)
if dirName == "Manual Run" and watch_dir != "":
dirName = watch_dir
params = {}
params['nzb_folder'] = dirName
if remote_path:
dirName_new = os.path.join(remote_path, os.path.basename(dirName)).replace("\\", "/")
params['nzb_folder'] = dirName_new
if nzbName != None:
params['nzb_name'] = nzbName
@ -57,12 +58,12 @@ class autoProcessComics:
else:
protocol = "http://"
url = protocol + host + ":" + port + web_root + "/post_process?" + urllib.urlencode(params)
url = protocol + host + ":" + port + web_root + "/post_process"
logger.debug("Opening URL: %s", url)
try:
r = requests.get(url, auth=(username, password), stream=True)
r = requests.get(url, params=params, auth=(username, password), stream=True)
except requests.ConnectionError:
logger.error("Unable to open URL")
return 1 # failure

View file

@ -1,4 +1,3 @@
import json
import nzbtomedia
from lib import requests
from nzbtomedia.nzbToMediaUtil import convert_to_ascii
@ -44,29 +43,34 @@ class autoProcessGames:
nzbName, dirName = convert_to_ascii(nzbName, dirName)
baseURL = protocol + host + ":" + port + web_root + "/api?api_key=" + apikey + "&mode="
baseURL = protocol + host + ":" + port + web_root + "/api"
fields = nzbName.split("-")
gamezID = fields[0].replace("[","").replace("]","").replace(" ","")
downloadStatus = 'Wanted'
if status == 0:
downloadStatus = 'Downloaded'
url = baseURL + "UPDATEREQUESTEDSTATUS&db_id=" + gamezID + "&status=" + downloadStatus
params = {}
params['api_key'] = apikey
params['mode'] = 'UPDATEREQUESTEDSTATUS'
params['db_id'] = gamezID
params['status'] = downloadStatus
url = baseURL
logger.debug("Opening URL: %s", url)
try:
r = requests.get(url, stream=True)
r = requests.get(url, params=params)
except requests.ConnectionError:
logger.error("Unable to open URL")
return 1 # failure
result = {}
for line in r.iter_lines():
if line:
logger.postprocess("%s", line)
result.update(json.load(line))
result = r.json()
logger.postprocess("%s", result)
if result['success']:
logger.postprocess("Status for %s has been set to %s in Gamez", gamezID, downloadStatus)

View file

@ -1,7 +1,6 @@
import os
import re
import time
import urllib
import nzbtomedia
from lib import requests
from nzbtomedia.Transcoder import Transcoder
@ -153,6 +152,9 @@ class autoProcessMovie:
if not releases:
logger.error("Could not find any releases marked as WANTED on CouchPotato to compare changes against %s, skipping ...", nzbName)
return 1
release_id = releases.keys()[0]
media_id = releases[release_id]['media_id']
process_all_exceptions(nzbName.lower(), dirName)
nzbName, dirName = convert_to_ascii(nzbName, dirName)
@ -171,14 +173,16 @@ class autoProcessMovie:
command = "/renamer.scan"
params = {}
if len(releases) == 1:
download_id =
if download_id:
params['downloader'] = clientAgent
params['download_id'] = download_id
params['media_folder'] = urllib.quote(dirName)
params['media_folder'] = dirName
if remote_path:
dirName_new = os.path.join(remote_path, os.path.basename(dirName)).replace("\\", "/")
params['media_folder'] = urllib.quote(dirName_new)
params['media_folder'] = dirName_new
url = baseURL + command
@ -211,9 +215,6 @@ class autoProcessMovie:
logger.warning("Please manually ignore this release and refresh the wanted movie from CouchPotato, Exiting ...")
return 1 # failure
release_id = releases.keys()[0]
media_id = releases[release_id]['media_id']
logger.postprocess("Ignoring current failed release %s ...", nzbName)
url = baseURL + "/release.ignore"
@ -251,7 +252,7 @@ class autoProcessMovie:
return 1
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
timeout = time.time() + 60 * int(wait_for)
timeout = time.time() + 60 * wait_for
while (time.time() < timeout): # only wait 2 (default) minutes, then return.
releases_current = self.get_releases(baseURL, download_id, dirName, nzbName)
releasesDiff = self.releases_diff(releases, releases_current)
@ -261,7 +262,7 @@ class autoProcessMovie:
return 0 # success
# pause and let CouchPotatoServer catch its breath
time.sleep(10 * int(wait_for))
time.sleep(10 * wait_for)
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.
logger.warning("The movie does not appear to have changed status after %s minutes. Please check CouchPotato Logs", wait_for)

View file

@ -1,7 +1,5 @@
import os
import time
import datetime
import urllib
import nzbtomedia
from lib import requests
from nzbtomedia.nzbToMediaUtil import convert_to_ascii
@ -53,7 +51,7 @@ class autoProcessMusic:
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"])
wait_for = int(nzbtomedia.CFG[section][inputCategory]["wait_for"])
try:
ssl = int(nzbtomedia.CFG[section][inputCategory]["ssl"])
@ -64,6 +62,11 @@ class autoProcessMusic:
except:
web_root = ""
try:
remote_path = nzbtomedia.CFG[section][inputCategory]["remote_path"]
except:
remote_path = None
if ssl:
protocol = "https://"
else:
@ -78,7 +81,11 @@ class autoProcessMusic:
params = {}
params['apikey'] = apikey
params['cmd'] = "forceProcess"
params['dir'] = os.path.dirname(dirName)
if remote_path:
dirName_new = os.path.join(remote_path, os.path.basename(os.path.dirname(dirName))).replace("\\", "/")
params['dir'] = dirName_new
url = baseURL
@ -112,14 +119,14 @@ class autoProcessMusic:
return 0 # Success (as far as this script is concerned)
# we will now wait 1 minutes for this album to be processed before returning to TorrentToMedia and unpausing.
timeout = time.time() + 60 * 2
timeout = time.time() + 60 * wait_for
while (time.time() < timeout): # only wait 2 (default) minutes, then return.
current_status = self.get_status(url, apikey, dirName)
if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie.
logger.postprocess("SUCCESS: This release is now marked as status [%s] in HeadPhones",current_status)
return 0
time.sleep(10 * 2)
time.sleep(10 * wait_for)
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.
logger.warning("The music album does not appear to have changed status after %s minutes. Please check HeadPhones Logs",2)

View file

@ -1,9 +1,5 @@
import copy
import json
import os
import urllib
import time
import sys
import nzbtomedia
from lib import requests
from nzbtomedia.Transcoder import Transcoder
@ -75,6 +71,10 @@ class autoProcessTV:
Torrent_NoLink = int(nzbtomedia.CFG[section][inputCategory]["Torrent_NoLink"])
except:
Torrent_NoLink = 0
try:
remote_path = nzbtomedia.CFG[section][inputCategory]["remote_path"]
except:
remote_path = None
if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name.
dirName = os.path.split(os.path.normpath(dirName))[0]
@ -124,6 +124,9 @@ class autoProcessTV:
if param in ["dirName", "dir"]:
fork_params[param] = dirName
if remote_path:
dirName_new = os.path.join(remote_path, os.path.basename(dirName)).replace("\\", "/")
fork_params[param] = dirName_new
if param == "process_method":
if fork in nzbtomedia.SICKBEARD_TORRENT and Torrent_NoLink == 1 and not clientAgent in ['nzbget','sabnzbd']: #use default SickBeard settings here.

View file

@ -211,8 +211,8 @@ class ConfigObj(configobj.ConfigObj, Section):
section = "CouchPotato"
envCatKey = 'NZBPO_CPSCATEGORY'
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'DELAY', 'METHOD', 'DELETE_FAILED', 'REMOTECPS', 'WAIT_FOR', 'TIMEPERGIB']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'delay', 'method', 'delete_failed', 'remoteCPS', 'wait_for', 'TimePerGiB']
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'METHOD', 'DELETE_FAILED', 'REMOTECPS', 'WAIT_FOR', 'WATCH_DIR']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'method', 'delete_failed', 'remoteCPS', 'wait_for', 'watch_dir']
if os.environ.has_key(envCatKey):
for index in range(len(envKeys)):
key = 'NZBPO_CPS' + envKeys[index]
@ -226,8 +226,8 @@ class ConfigObj(configobj.ConfigObj, Section):
section = "SickBeard"
envCatKey = 'NZBPO_SBCATEGORY'
envKeys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'DELAY', 'TIMEPERGIB', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'delay', 'TimePerGiB', 'Torrent_NoLink', 'nzbExtractionBy']
envKeys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy']
if os.environ.has_key(envCatKey):
for index in range(len(envKeys)):
key = 'NZBPO_SB' + envKeys[index]
@ -241,8 +241,8 @@ class ConfigObj(configobj.ConfigObj, Section):
section = "HeadPhones"
envCatKey = 'NZBPO_HPCATEGORY'
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'DELAY', 'TIMEPERGIB']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'delay', 'TimePerGiB']
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WAIT_FOR', 'WATCH_DIR']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'wait_for', 'watch_dir']
if os.environ.has_key(envCatKey):
for index in range(len(envKeys)):
key = 'NZBPO_HP' + envKeys[index]
@ -256,8 +256,8 @@ class ConfigObj(configobj.ConfigObj, Section):
section = "Mylar"
envCatKey = 'NZBPO_MYCATEGORY'
envKeys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root']
envKeys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir']
if os.environ.has_key(envCatKey):
for index in range(len(envKeys)):
key = 'NZBPO_MY' + envKeys[index]
@ -271,8 +271,8 @@ class ConfigObj(configobj.ConfigObj, Section):
section = "Gamez"
envCatKey = 'NZBPO_GZCATEGORY'
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root']
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'watch_dir']
if os.environ.has_key(envCatKey):
for index in range(len(envKeys)):
key = 'NZBPO_GZ' + envKeys[index]
@ -286,8 +286,8 @@ class ConfigObj(configobj.ConfigObj, Section):
section = "NzbDrone"
envCatKey = 'NZBPO_NDCATEGORY'
envKeys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'DELAY', 'TIMEPERGIB', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'delay', 'TimePerGiB', 'Torrent_NoLink', 'nzbExtractionBy']
envKeys = ['ENABLED', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy']
if os.environ.has_key(envCatKey):
for index in range(len(envKeys)):
key = 'NZBPO_ND' + envKeys[index]