Added in a config class to access main config properly and now can be called from anywhere in the code by creating a instance.

Re-coded migratecfg, vast improvements made and code cleanup of unrequired checks.

Fixed numerous small bugs throughout nzbToMedia including possible calls to variables that may not have been created do to conditional statements.
This commit is contained in:
echel0n 2014-04-01 18:35:20 -07:00
parent 08bd4584d8
commit 6d45257035
29 changed files with 348 additions and 543 deletions

View file

@ -81,7 +81,7 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5
os.utime(filepath, None)
continue
except:
print "Error: unable to reset time for file", filePath
print "Error: unable to reset time for file", file
sys.exit(POSTPROCESS_ERROR)
sys.exit(POSTPROCESS_SUCCESS)

View file

@ -1,15 +1,9 @@
#!/usr/bin/env python
#System imports
import os
import sys
import ConfigParser
import shutil
import logging
import datetime
import time
import re
from subprocess import call, Popen
from subprocess import Popen
# Custom imports
import autoProcess.migratecfg as migratecfg
@ -450,69 +444,65 @@ if __name__ == "__main__":
WakeUp()
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilename):
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
sys.exit(-1)
# CONFIG FILE
Logger.info("MAIN: Loading config from %s", configFilename)
config.read(configFilename)
Logger.info("MAIN: Loading config from %s", CONFIG_FILE)
# EXAMPLE VALUES:
clientAgent = config.get("Torrent", "clientAgent") # utorrent | deluge | transmission | rtorrent | other
useLink_in = config.get("Torrent", "useLink") # no | hard | sym
outputDirectory = config.get("Torrent", "outputDirectory") # /abs/path/to/complete/
categories = (config.get("Torrent", "categories")).split(',') # music,music_videos,pictures,software
noFlatten = (config.get("Torrent", "noFlatten")).split(',')
clientAgent = config().get("Torrent", "clientAgent") # utorrent | deluge | transmission | rtorrent | other
useLink_in = config().get("Torrent", "useLink") # no | hard | sym
outputDirectory = config().get("Torrent", "outputDirectory") # /abs/path/to/complete/
categories = (config().get("Torrent", "categories")).split(',') # music,music_videos,pictures,software
noFlatten = (config().get("Torrent", "noFlatten")).split(',')
uTorrentWEBui = config.get("Torrent", "uTorrentWEBui") # http://localhost:8090/gui/
uTorrentUSR = config.get("Torrent", "uTorrentUSR") # mysecretusr
uTorrentPWD = config.get("Torrent", "uTorrentPWD") # mysecretpwr
uTorrentWEBui = config().get("Torrent", "uTorrentWEBui") # http://localhost:8090/gui/
uTorrentUSR = config().get("Torrent", "uTorrentUSR") # mysecretusr
uTorrentPWD = config().get("Torrent", "uTorrentPWD") # mysecretpwr
TransmissionHost = config.get("Torrent", "TransmissionHost") # localhost
TransmissionPort = config.get("Torrent", "TransmissionPort") # 8084
TransmissionUSR = config.get("Torrent", "TransmissionUSR") # mysecretusr
TransmissionPWD = config.get("Torrent", "TransmissionPWD") # mysecretpwr
TransmissionHost = config().get("Torrent", "TransmissionHost") # localhost
TransmissionPort = config().get("Torrent", "TransmissionPort") # 8084
TransmissionUSR = config().get("Torrent", "TransmissionUSR") # mysecretusr
TransmissionPWD = config().get("Torrent", "TransmissionPWD") # mysecretpwr
DelugeHost = config.get("Torrent", "DelugeHost") # localhost
DelugePort = config.get("Torrent", "DelugePort") # 8084
DelugeUSR = config.get("Torrent", "DelugeUSR") # mysecretusr
DelugePWD = config.get("Torrent", "DelugePWD") # mysecretpwr
DelugeHost = config().get("Torrent", "DelugeHost") # localhost
DelugePort = config().get("Torrent", "DelugePort") # 8084
DelugeUSR = config().get("Torrent", "DelugeUSR") # mysecretusr
DelugePWD = config().get("Torrent", "DelugePWD") # mysecretpwr
deleteOriginal = int(config.get("Torrent", "deleteOriginal")) # 0
forceClean = int(config.get("Torrent", "forceClean")) # 0
deleteOriginal = int(config().get("Torrent", "deleteOriginal")) # 0
forceClean = int(config().get("Torrent", "forceClean")) # 0
compressedContainer = (config.get("Extensions", "compressedExtensions")).split(',') # .zip,.rar,.7z
mediaContainer = (config.get("Extensions", "mediaExtensions")).split(',') # .mkv,.avi,.divx
metaContainer = (config.get("Extensions", "metaExtensions")).split(',') # .nfo,.sub,.srt
minSampleSize = int(config.get("Extensions", "minSampleSize")) # 200 (in MB)
SampleIDs = (config.get("Extensions", "SampleIDs")).split(',') # sample,-s.
compressedContainer = (config().get("Extensions", "compressedExtensions")).split(',') # .zip,.rar,.7z
mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',') # .mkv,.avi,.divx
metaContainer = (config().get("Extensions", "metaExtensions")).split(',') # .nfo,.sub,.srt
minSampleSize = int(config().get("Extensions", "minSampleSize")) # 200 (in MB)
SampleIDs = (config().get("Extensions", "SampleIDs")).split(',') # sample,-s.
cpsCategory = (config.get("CouchPotato", "cpsCategory")).split(',') # movie
sbCategory = (config.get("SickBeard", "sbCategory")).split(',') # tv
Torrent_ForceLink = int(config.get("SickBeard", "Torrent_ForceLink")) # 1
hpCategory = (config.get("HeadPhones", "hpCategory")).split(',') # music
mlCategory = (config.get("Mylar", "mlCategory")).split(',') # comics
gzCategory = (config.get("Gamez", "gzCategory")).split(',') # games
cpsCategory = (config().get("CouchPotato", "cpsCategory")).split(',') # movie
sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv
Torrent_ForceLink = int(config().get("SickBeard", "Torrent_ForceLink")) # 1
hpCategory = (config().get("HeadPhones", "hpCategory")).split(',') # music
mlCategory = (config().get("Mylar", "mlCategory")).split(',') # comics
gzCategory = (config().get("Gamez", "gzCategory")).split(',') # games
categories.extend(cpsCategory)
categories.extend(sbCategory)
categories.extend(hpCategory)
categories.extend(mlCategory)
categories.extend(gzCategory)
user_script_categories = config.get("UserScript", "user_script_categories").split(',') # NONE
user_script_categories = config().get("UserScript", "user_script_categories").split(',') # NONE
if not "NONE" in user_script_categories:
user_script_mediaExtensions = (config.get("UserScript", "user_script_mediaExtensions")).split(',')
user_script = config.get("UserScript", "user_script_path")
user_script_param = (config.get("UserScript", "user_script_param")).split(',')
user_script_successCodes = (config.get("UserScript", "user_script_successCodes")).split(',')
user_script_clean = int(config.get("UserScript", "user_script_clean"))
user_delay = int(config.get("UserScript", "delay"))
user_script_runOnce = int(config.get("UserScript", "user_script_runOnce"))
user_script_mediaExtensions = (config().get("UserScript", "user_script_mediaExtensions")).split(',')
user_script = config().get("UserScript", "user_script_path")
user_script_param = (config().get("UserScript", "user_script_param")).split(',')
user_script_successCodes = (config().get("UserScript", "user_script_successCodes")).split(',')
user_script_clean = int(config().get("UserScript", "user_script_clean"))
user_delay = int(config().get("UserScript", "delay"))
user_script_runOnce = int(config().get("UserScript", "user_script_runOnce"))
transcode = int(config.get("Transcoder", "transcode"))
transcode = int(config().get("Transcoder", "transcode"))
n = 0
for arg in sys.argv:

View file

@ -1,10 +1,11 @@
import sys
import os
import ConfigParser
import logging
import errno
from subprocess import call
from nzbToMediaConfig import *
Logger = logging.getLogger()
def Transcode_directory(dirName):
@ -29,31 +30,27 @@ def Transcode_directory(dirName):
ffmpeg = 'ffmpeg'
useNiceness = True
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
Logger.info("Loading config from %s", CONFIG_FILE)
if not os.path.isfile(configFilename):
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
mediaContainer = (config.get("Extensions", "mediaExtensions")).split(',')
duplicate = int(config.get("Transcoder", "duplicate"))
ignoreExtensions = (config.get("Transcoder", "ignoreExtensions")).split(',')
outputVideoExtension = config.get("Transcoder", "outputVideoExtension").strip()
outputVideoCodec = config.get("Transcoder", "outputVideoCodec").strip()
outputVideoPreset = config.get("Transcoder", "outputVideoPreset").strip()
outputVideoFramerate = config.get("Transcoder", "outputVideoFramerate").strip()
outputVideoBitrate = config.get("Transcoder", "outputVideoBitrate").strip()
outputAudioCodec = config.get("Transcoder", "outputAudioCodec").strip()
outputAudioBitrate = config.get("Transcoder", "outputAudioBitrate").strip()
outputSubtitleCodec = config.get("Transcoder", "outputSubtitleCodec").strip()
outputFastStart = int(config.get("Transcoder", "outputFastStart"))
outputQualityPercent = int(config.get("Transcoder", "outputQualityPercent"))
mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',')
duplicate = int(config().get("Transcoder", "duplicate"))
ignoreExtensions = (config().get("Transcoder", "ignoreExtensions")).split(',')
outputVideoExtension = config().get("Transcoder", "outputVideoExtension").strip()
outputVideoCodec = config().get("Transcoder", "outputVideoCodec").strip()
outputVideoPreset = config().get("Transcoder", "outputVideoPreset").strip()
outputVideoFramerate = config().get("Transcoder", "outputVideoFramerate").strip()
outputVideoBitrate = config().get("Transcoder", "outputVideoBitrate").strip()
outputAudioCodec = config().get("Transcoder", "outputAudioCodec").strip()
outputAudioBitrate = config().get("Transcoder", "outputAudioBitrate").strip()
outputSubtitleCodec = config().get("Transcoder", "outputSubtitleCodec").strip()
outputFastStart = int(config().get("Transcoder", "outputFastStart"))
outputQualityPercent = int(config().get("Transcoder", "outputQualityPercent"))
if useNiceness:
niceness = int(config.get("Transcoder", "niceness"))
niceness = int(config().get("Transcoder", "niceness"))
map(lambda ext: ext.strip(), mediaContainer)
map(lambda ext: ext.strip(), ignoreExtensions)

View file

@ -1,14 +1,9 @@
import sys
import urllib
import os.path
import time
import ConfigParser
import logging
import socket
from nzbToMediaEnv import *
from nzbToMediaUtil import *
from nzbToMediaSceneExceptions import process_all_exceptions
Logger = logging.getLogger()
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
@ -34,36 +29,36 @@ class AuthURLOpener(urllib.FancyURLopener):
def processEpisode(dirName, nzbName=None, status=0, inputCategory=None):
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
if not os.path.isfile(configFilename):
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
section = "Mylar"
if inputCategory != None and config.has_section(inputCategory):
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
host = config.get(section, "host")
port = config.get(section, "port")
username = config.get(section, "username")
password = config.get(section, "password")
host = config().get(section, "host")
port = config().get(section, "port")
username = config().get(section, "username")
password = config().get(section, "password")
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
try:
watch_dir = config.get(section, "watch_dir")
except ConfigParser.NoOptionError:
watch_dir = config().get(section, "watch_dir")
except config.NoOptionError:
watch_dir = ""
params = {}

View file

@ -1,49 +1,43 @@
import sys
import urllib
import os
import shutil
import ConfigParser
import datetime
import time
import json
import logging
import socket
from nzbToMediaEnv import *
from nzbToMediaUtil import *
Logger = logging.getLogger()
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
def process(dirName, nzbName=None, status=0, inputCategory=None):
status = int(status)
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
if not os.path.isfile(configFilename):
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
section = "Gamez"
if inputCategory != None and config.has_section(inputCategory):
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
host = config.get(section, "host")
port = config.get(section, "port")
apikey = config.get(section, "apikey")
host = config().get(section, "host")
port = config().get(section, "port")
apikey = config().get(section, "apikey")
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
if ssl:

View file

@ -1,19 +1,14 @@
import sys
import urllib
import os
import shutil
import ConfigParser
import datetime
import time
import json
import logging
import socket
import Transcoder
from nzbToMediaEnv import *
from nzbToMediaUtil import *
from nzbToMediaSceneExceptions import process_all_exceptions
Logger = logging.getLogger()
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
@ -130,7 +125,7 @@ def get_movie_info(baseURL, imdbid, download_id):
return movie_id, imdbid, download_id, movie_status, release_status
def get_status(baseURL, movie_id, download_id):
result = None
movie_status = None
release_status = None
if not movie_id:
@ -151,6 +146,7 @@ def get_status(baseURL, movie_id, download_id):
Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status)
except:
Logger.exception("Could not find a status for this movie")
try:
if len(result["media"]["releases"]) == 1 and result["media"]["releases"][0]["status"] == "done":
release_status = result["media"]["releases"][0]["status"]
@ -167,46 +163,43 @@ def get_status(baseURL, movie_id, download_id):
def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id = "", inputCategory=None):
status = int(status)
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
if not os.path.isfile(configFilename):
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
section = "CouchPotato"
if inputCategory != None and config.has_section(inputCategory):
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
host = config.get(section, "host")
port = config.get(section, "port")
apikey = config.get(section, "apikey")
delay = float(config.get(section, "delay"))
method = config.get(section, "method")
delete_failed = int(config.get(section, "delete_failed"))
wait_for = int(config.get(section, "wait_for"))
host = config().get(section, "host")
port = config().get(section, "port")
apikey = config().get(section, "apikey")
delay = float(config().get(section, "delay"))
method = config().get(section, "method")
delete_failed = int(config().get(section, "delete_failed"))
wait_for = int(config().get(section, "wait_for"))
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
try:
transcode = int(config.get("Transcoder", "transcode"))
except (ConfigParser.NoOptionError, ValueError):
transcode = int(config().get("Transcoder", "transcode"))
except (config.NoOptionError, ValueError):
transcode = 0
try:
remoteCPS = int(config.get(section, "remoteCPS"))
except (ConfigParser.NoOptionError, ValueError):
remoteCPS = int(config().get(section, "remoteCPS"))
except (config.NoOptionError, ValueError):
remoteCPS = 0
nzbName = str(nzbName) # make sure it is a string
@ -312,6 +305,7 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
release_status = None
start = datetime.datetime.now() # set time for timeout
pause_for = int(wait_for) * 10 # keep this so we only ever have 6 complete loops. This may not be necessary now?
while (datetime.datetime.now() - start) < datetime.timedelta(minutes=wait_for): # only wait 2 (default) minutes, then return.

View file

@ -1,50 +1,44 @@
import sys
import urllib
import os
import shutil
import ConfigParser
import datetime
import time
import json
import logging
import socket
from nzbToMediaEnv import *
from nzbToMediaUtil import *
Logger = logging.getLogger()
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
def process(dirName, nzbName=None, status=0, inputCategory=None):
status = int(status)
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
if not os.path.isfile(configFilename):
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
section = "HeadPhones"
if inputCategory != None and config.has_section(inputCategory):
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
host = config.get(section, "host")
port = config.get(section, "port")
apikey = config.get(section, "apikey")
delay = float(config.get(section, "delay"))
host = config().get(section, "host")
port = config().get(section, "port")
apikey = config().get(section, "apikey")
delay = float(config().get(section, "delay"))
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
if ssl:

View file

@ -3,10 +3,10 @@ import logging
import copy
import Transcoder
from nzbToMediaEnv import *
from nzbToMediaUtil import *
from nzbToMediaSceneExceptions import process_all_exceptions
from autoProcess.autoSickBeardFork import autoFork
from nzbToMediaEnv import *
from nzbToMediaUtil import *
Logger = logging.getLogger()
@ -40,72 +40,72 @@ def delete(dirName):
def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputCategory=None):
status = int(failed)
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
if not os.path.isfile(configFilename):
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
section = "SickBeard"
if inputCategory != None and config.has_section(inputCategory):
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
watch_dir = ""
host = config.get(section, "host")
port = config.get(section, "port")
username = config.get(section, "username")
password = config.get(section, "password")
host = config().get(section, "host")
port = config().get(section, "port")
username = config().get(section, "username")
password = config().get(section, "password")
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
try:
watch_dir = config.get(section, "watch_dir")
except ConfigParser.NoOptionError:
watch_dir = config().get(section, "watch_dir")
except config.NoOptionError:
watch_dir = ""
try:
transcode = int(config.get("Transcoder", "transcode"))
except (ConfigParser.NoOptionError, ValueError):
transcode = int(config().get("Transcoder", "transcode"))
except (config.NoOptionError, ValueError):
transcode = 0
try:
delete_failed = int(config.get(section, "delete_failed"))
except (ConfigParser.NoOptionError, ValueError):
delete_failed = int(config().get(section, "delete_failed"))
except (config.NoOptionError, ValueError):
delete_failed = 0
try:
delay = float(config.get(section, "delay"))
except (ConfigParser.NoOptionError, ValueError):
delay = float(config().get(section, "delay"))
except (config.NoOptionError, ValueError):
delay = 0
try:
wait_for = int(config.get(section, "wait_for"))
except (ConfigParser.NoOptionError, ValueError):
wait_for = int(config().get(section, "wait_for"))
except (config.NoOptionError, ValueError):
wait_for = 5
try:
SampleIDs = (config.get("Extensions", "SampleIDs")).split(',')
except (ConfigParser.NoOptionError, ValueError):
SampleIDs = (config().get("Extensions", "SampleIDs")).split(',')
except (config.NoOptionError, ValueError):
SampleIDs = ['sample','-s.']
try:
nzbExtractionBy = config.get(section, "nzbExtractionBy")
except (ConfigParser.NoOptionError, ValueError):
nzbExtractionBy = config().get(section, "nzbExtractionBy")
except (config.NoOptionError, ValueError):
nzbExtractionBy = "Downloader"
try:
process_method = config.get(section, "process_method")
except ConfigParser.NoOptionError:
process_method = config().get(section, "process_method")
except config.NoOptionError:
process_method = None
TimeOut = 60 * int(wait_for) # SickBeard needs to complete all moving and renaming before returning the log sequence via url.
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
mediaContainer = (config.get("Extensions", "mediaExtensions")).split(',')
minSampleSize = int(config.get("Extensions", "minSampleSize"))
mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',')
minSampleSize = int(config().get("Extensions", "minSampleSize"))
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]

View file

@ -1,11 +1,10 @@
import sys
import urllib
import os
import ConfigParser
import logging
from nzbToMediaConfig import *
from autoProcess.nzbToMediaEnv import *
Logger = logging.getLogger()
class AuthURLOpener(urllib.FancyURLopener):
@ -27,29 +26,26 @@ class AuthURLOpener(urllib.FancyURLopener):
return urllib.FancyURLopener.open(self, url)
def autoFork(fork=None):
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
config.read(configFilename)
# config settings
section = "SickBeard"
host = config.get(section, "host")
port = config.get(section, "port")
username = config.get(section, "username")
password = config.get(section, "password")
host = config().get(section, "host")
port = config().get(section, "port")
username = config().get(section, "username")
password = config().get(section, "password")
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
try:
fork = forks.items()[forks.keys().index(config.get(section, "fork"))]
fork = forks.items()[forks.keys().index(config().get(section, "fork"))]
except:
fork = "auto"

View file

@ -1,298 +1,129 @@
#System imports
import ConfigParser
import sys
import os
from nzbToMediaConfig import *
def migrate():
confignew = ConfigParser.ConfigParser()
confignew.optionxform = str
configFilenamenew = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")
confignew.read(configFilenamenew)
configold = ConfigParser.ConfigParser()
configold.optionxform = str
categories = []
confignew = config(SAMPLE_CONFIG_FILE)
configold = config(CONFIG_FILE)
section = "CouchPotato"
original = []
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilenameold): # lets look back for an older version.
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMovie.cfg")
if not os.path.isfile(configFilenameold): # no config available
configFilenameold = ""
if configFilenameold: # read our old config.
configold.read(configFilenameold)
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if option == "category": # change this old format
for option, value in configold.items(section) or config(MOVIE_CONFIG_FILE).items(section):
if option is "category": # change this old format
option = "cpsCategory"
if option == "outputDirectory": # move this to new location format
if option is "outputDirectory": # move this to new location format
value = os.path.split(os.path.normpath(value))[0]
confignew.set("Torrent", option, value)
continue
if option in ["username", "password" ]: # these are no-longer needed.
continue
if option == "cpsCategory":
if option is "cpsCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
section = "SickBeard"
original = []
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilenameold): # lets look back for an older version.
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
if not os.path.isfile(configFilenameold): # no config available
configFilenameold = ""
if configFilenameold: # read our old config.
configold.read(configFilenameold)
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if option == "category": # change this old format
for option, value in configold.items(section) or config(TV_CONFIG_FILE).items(section):
if option is "category": # change this old format
option = "sbCategory"
if option == "failed_fork": # change this old format
if option is "failed_fork": # change this old format
option = "fork"
if value not in ["default", "failed", "failed-torrent", "auto"]:
value = "auto"
if option == "fork" and value not in ["default", "failed", "failed-torrent", "auto"]:
if option is "fork" and value not in ["default", "failed", "failed-torrent", "auto"]:
value = "auto"
if option == "outputDirectory": # move this to new location format
if option is "outputDirectory": # move this to new location format
value = os.path.split(os.path.normpath(value))[0]
confignew.set("Torrent", option, value)
continue
if option == "sbCategory":
if option is "sbCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
section = "HeadPhones"
original = []
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if os.path.isfile(configFilenameold): # read our old config.
configold.read(configFilenameold)
try:
original = configold.items(section)
except:
pass
for item in original:
if option in ["username", "password" ]: # these are no-longer needed.
for section in configold.sections():
if section is "HeadPhones":
if option in ["username", "password" ]:
continue
option, value = item
if option == "hpCategory":
if option is "hpCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
section = "Mylar"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if option == "mlCategory":
if section is "Mylar":
if option in "mlCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
section = "Gamez"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "Gamez":
if option in ["username", "password" ]: # these are no-longer needed.
continue
if option == "gzCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
for section in categories:
original = []
try:
original = configold.items(section)
except:
continue
try:
confignew.add_section(section)
except:
pass
for item in original:
option, value = item
confignew.set(section, option, value)
section = "Torrent"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "Torrent":
if option in ["compressedExtensions", "mediaExtensions", "metaExtensions", "minSampleSize"]:
section = "Extensions" # these were moved
if option == "useLink": # Sym links supported now as well.
try:
num_value = int(value)
if num_value == 1:
if option is "useLink": # Sym links supported now as well.
num_value = int(value or 0)
if num_value is 1:
value = "hard"
else:
value = "no"
except ValueError:
pass
confignew.set(section, option, value)
section = "Torrent" # reset in case extensions out of order.
section = "Extensions"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
confignew.set(section, option, value)
section = "Transcoder"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "Extensions":
confignew.set(section, option, value)
section = "WakeOnLan"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "Transcoder":
confignew.set(section, option, value)
section = "UserScript"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "WakeOnLan":
confignew.set(section, option, value)
section = "ASCII"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "UserScript":
confignew.set(section, option, value)
section = "passwords"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "ASCII":
confignew.set(section, option, value)
section = "loggers"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "passwords":
confignew.set(section, option, value)
section = "handlers"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "loggers":
confignew.set(section, option, value)
section = "formatters"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "handlers":
confignew.set(section, option, value)
section = "logger_root"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "formatters":
confignew.set(section, option, value)
section = "handler_console"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "logger_root":
confignew.set(section, option, value)
section = "formatter_generic"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
if section is "handler_console":
confignew.set(section, option, value)
# writing our configuration file to 'autoProcessMedia.cfg.sample'
with open(configFilenamenew, 'wb') as configFile:
confignew.write(configFile)
if section is "formatter_generic":
confignew.set(section, option, value)
for section in categories:
if configold.items(section):
confignew.add_section(section)
for option, value in configold.items(section):
confignew.set(section, option, value)
# create a backup of our old config
if os.path.isfile(configFilenameold):
backupname = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.old")
if os.path.isfile(backupname): # remove older backups
os.unlink(backupname)
os.rename(configFilenameold, backupname)
if os.path.isfile(CONFIG_FILE):
cfgbak_name = CONFIG_FILE + ".old"
if os.path.isfile(cfgbak_name): # remove older backups
os.unlink(cfgbak_name)
os.rename(CONFIG_FILE, cfgbak_name)
if os.path.isfile(configFilenamenew):
# rename our newly edited autoProcessMedia.cfg.sample to autoProcessMedia.cfg
os.rename(configFilenamenew, configFilenameold)
return
# writing our configuration file to 'autoProcessMedia.cfg.sample'
with open(CONFIG_FILE, 'wb') as configFile:
confignew.write(configFile)
def addnzbget():
confignew = ConfigParser.ConfigParser()
confignew.optionxform = str
configFilenamenew = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
confignew.read(configFilenamenew)
confignew = config()
section = "CouchPotato"
envKeys = ['CATEGORY', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'DELAY', 'METHOD', 'DELETE_FAILED', 'REMOTECPS', 'WAIT_FOR']
cfgKeys = ['cpsCategory', 'apikey', 'host', 'port', 'ssl', 'web_root', 'delay', 'method', 'delete_failed', 'remoteCPS', 'wait_for']
@ -374,9 +205,6 @@ def addnzbget():
value = os.environ[key]
confignew.set(section, option, value)
# writing our configuration file to 'autoProcessMedia.cfg'
with open(configFilenamenew, 'wb') as configFile:
with open(CONFIG_FILE, 'wb') as configFile:
confignew.write(configFile)
return

View file

@ -1,28 +1,26 @@
import logging
import logging.config
import os
import re
import sys
import shutil
import struct
import socket
import time
import ConfigParser
import linktastic.linktastic as linktastic
from nzbToMediaConfig import *
Logger = logging.getLogger()
def safeName(name):
safename = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "", name) #make this name safe for use in directories for windows etc.
return safename
def nzbtomedia_configure_logging(dirname):
logFile = os.path.join(dirname, "postprocess.log")
logging.config.fileConfig(os.path.join(dirname, "autoProcessMedia.cfg"))
fileHandler = logging.handlers.RotatingFileHandler(logFile, mode='a', maxBytes=1048576, backupCount=1, encoding='utf-8', delay=True)
logging.config.fileConfig(CONFIG_FILE)
fileHandler = logging.handlers.RotatingFileHandler(LOG_FILE, mode='a', maxBytes=1048576, backupCount=1, encoding='utf-8', delay=True)
fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S')
fileHandler.level = logging.DEBUG
logging.getLogger().addHandler(fileHandler)
@ -316,22 +314,18 @@ def TestCon(host, port):
def WakeUp():
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilename):
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
if not config():
Logger.error("You need an autoProcessMedia.config() file - did you rename and edit the .sample?")
return
config.read(configFilename)
wake = int(config.get("WakeOnLan", "wake"))
wake = int(config().get("WakeOnLan", "wake"))
if wake == 0: # just return if we don't need to wake anything.
return
Logger.info("Loading WakeOnLan config from %s", configFilename)
config.get("WakeOnLan", "host")
host = config.get("WakeOnLan", "host")
port = int(config.get("WakeOnLan", "port"))
mac = config.get("WakeOnLan", "mac")
Logger.info("Loading WakeOnLan config from %s", CONFIG_FILE)
config().get("WakeOnLan", "host")
host = config().get("WakeOnLan", "host")
port = int(config().get("WakeOnLan", "port"))
mac = config().get("WakeOnLan", "mac")
i=1
while TestCon(host, port) == "Down" and i < 4:
@ -346,13 +340,11 @@ def WakeUp():
Logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac)
def converto_to_ascii(nzbName, dirName):
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilename):
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return nzbName, dirName
config.read(configFilename)
ascii_convert = int(config.get("ASCII", "convert"))
ascii_convert = int(config().get("ASCII", "convert"))
if ascii_convert == 0 or os.name == 'nt': # just return if we don't want to convert or on windows os and "\" is replaced!.
return nzbName, dirName

View file

@ -1,9 +1,8 @@
import os
import sys
import ConfigParser
sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]),'autoProcess/'))
import logging
from subprocess import call, Popen, PIPE
from nzbToMediaConfig import *
from subprocess import call, Popen
from autoProcess.nzbToMediaUtil import create_destination
@ -112,11 +111,9 @@ def extract(filePath, outputDestination):
# Create outputDestination folder
create_destination(outputDestination)
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("MAIN: Loading config from %s", configFilename)
config.read(configFilename)
passwordsfile = config.get("passwords", "PassWordFile")
Logger.info("MAIN: Loading config from %s", CONFIG_FILE)
passwordsfile = config().get("passwords", "PassWordFile")
if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)):
passwords = [line.strip() for line in open(os.path.normpath(passwordsfile))]
else:

View file

@ -116,8 +116,6 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import os
import sys
import logging
import autoProcess.migratecfg as migratecfg

View file

@ -57,8 +57,6 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import os
import sys
import logging
import autoProcess.migratecfg as migratecfg

View file

@ -62,8 +62,6 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import os
import sys
import logging
import autoProcess.migratecfg as migratecfg

View file

@ -261,22 +261,25 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import os
import sys
import ConfigParser
import logging
import autoProcess.migratecfg as migratecfg
import autoProcess.autoProcessComics as autoProcessComics
import autoProcess.autoProcessGames as autoProcessGames
import autoProcess.autoProcessMusic as autoProcessMusic
import autoProcess.autoProcessMovie as autoProcessMovie
import autoProcess.autoProcessTV as autoProcessTV
import autoProcess.migratecfg as migratecfg
from autoProcess.nzbToMediaEnv import *
from autoProcess.nzbToMediaUtil import *
# Exit codes used by NZBGet
POSTPROCESS_PARCHECK = 92
POSTPROCESS_SUCCESS = 93
POSTPROCESS_ERROR = 94
POSTPROCESS_NONE = 95
# check to migrate old cfg before trying to load.
if os.path.isfile(os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")):
if config(SAMPLE_CONFIG_FILE):
migratecfg.migrate()
# check to write settings from nzbGet UI to autoProcessMedia.cfg.
if os.environ.has_key('NZBOP_SCRIPTDIR'):
@ -290,20 +293,17 @@ Logger.info("nzbToMedia %s", VERSION)
WakeUp()
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
if not os.path.isfile(configFilename):
if not config():
Logger.error("MAIN: You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
sys.exit(-1)
# CONFIG FILE
Logger.info("MAIN: Loading config from %s", configFilename)
config.read(configFilename)
cpsCategory = (config.get("CouchPotato", "cpsCategory")).split(',') # movie
sbCategory = (config.get("SickBeard", "sbCategory")).split(',') # tv
hpCategory = (config.get("HeadPhones", "hpCategory")).split(',') # music
mlCategory = (config.get("Mylar", "mlCategory")).split(',') # comics
gzCategory = (config.get("Gamez", "gzCategory")).split(',') # games
Logger.info("MAIN: Loading config from %s", CONFIG_FILE)
cpsCategory = (config().get("CouchPotato", "cpsCategory")).split(',') # movie
sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv
hpCategory = (config().get("HeadPhones", "hpCategory")).split(',') # music
mlCategory = (config().get("Mylar", "mlCategory")).split(',') # comics
gzCategory = (config().get("Gamez", "gzCategory")).split(',') # games
# NZBGet V11+
# Check if the script is called from nzbget 11.0 or later
@ -312,11 +312,6 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5
# NZBGet argv: all passed as environment variables.
clientAgent = "nzbget"
# Exit codes used by NZBGet
POSTPROCESS_PARCHECK=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95
# Check nzbget.conf options
status = 0

35
nzbToMediaConfig.py Normal file
View file

@ -0,0 +1,35 @@
import os
import ConfigParser
# init paths
MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
MY_NAME = os.path.basename(MY_FULLNAME)
PROG_DIR = os.path.dirname(MY_FULLNAME)
# init config file names
CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessMedia.cfg")
SAMPLE_CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessMedia.cfg.sample")
MOVIE_CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessMovie.cfg")
TV_CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessTv.cfg")
LOG_FILE = os.path.join(PROG_DIR, "postprocess.log")
class config(ConfigParser.ConfigParser):
# link error handlers
Error = ConfigParser.Error
NoSectionError = ConfigParser.NoSectionError
NoOptionError = ConfigParser.NoOptionError
DuplicateSectionError = ConfigParser.DuplicateSectionError
InterpolationError = ConfigParser.InterpolationError
InterpolationMissingOptionError = ConfigParser.InterpolationMissingOptionError
InterpolationSyntaxError = ConfigParser.InterpolationSyntaxError
InterpolationDepthError = ConfigParser.InterpolationDepthError
ParsingError = ConfigParser.ParsingError
MissingSectionHeaderError = ConfigParser.MissingSectionHeaderError
def __init__(self, *file):
ConfigParser.ConfigParser.__init__(self)
self.optionxform = str
if not file:
file = CONFIG_FILE
self.read(file)

View file

@ -60,8 +60,6 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import os
import sys
import logging
import autoProcess.migratecfg as migratecfg

View file

@ -124,8 +124,6 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import os
import sys
import logging
import autoProcess.migratecfg as migratecfg

View file

@ -1,6 +1,5 @@
import os
import platform
from collections import defaultdict
from itertools import imap
@ -8,6 +7,7 @@ from synchronousdeluge.exceptions import DelugeRPCError
from synchronousdeluge.protocol import DelugeRPCRequest, DelugeRPCResponse
from synchronousdeluge.transfer import DelugeTransfer
__all__ = ["DelugeClient"]

View file

@ -63,7 +63,6 @@ __all__ = ['dumps', 'loads']
#
import struct
import string
from threading import Lock
# Default number of bits for serialized floats, either 32 or 64 (also a parameter for dumps()).

3
tests/test_autofork.py Normal file
View file

@ -0,0 +1,3 @@
from autoProcess.autoSickBeardFork import autoFork
fork, params = autoFork()
print fork, params

View file

@ -2,7 +2,11 @@
# Copyright (c) 2008-2013 Erik Svensson <erik.public@gmail.com>
# Licensed under the MIT license.
import re, time, operator, warnings, os
import re
import time
import operator
import warnings
import os
import base64
import json
@ -12,9 +16,9 @@ from transmissionrpc.utils import LOGGER, get_arguments, make_rpc_name, argument
from transmissionrpc.httphandler import DefaultHTTPHandler
from transmissionrpc.torrent import Torrent
from transmissionrpc.session import Session
from six import PY3, integer_types, string_types, iteritems
if PY3:
from urllib.parse import urlparse
from urllib.request import urlopen

View file

@ -3,8 +3,10 @@
# Licensed under the MIT license.
import logging
from six import iteritems
LOGGER = logging.getLogger('transmissionrpc')
LOGGER.setLevel(logging.ERROR)

View file

@ -5,7 +5,6 @@
import sys
from transmissionrpc.error import HTTPHandlerError
from six import PY3
if PY3:

View file

@ -151,7 +151,7 @@ _moved_attributes = [
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("config", "config"),
MovedModule("copyreg", "copy_reg"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),

View file

@ -2,11 +2,11 @@
# Copyright (c) 2008-2013 Erik Svensson <erik.public@gmail.com>
# Licensed under the MIT license.
import sys, datetime
import sys
import datetime
from transmissionrpc.constants import PRIORITY, RATIO_LIMIT, IDLE_LIMIT
from transmissionrpc.utils import Field, format_timedelta
from six import integer_types, string_types, text_type, iteritems

View file

@ -2,13 +2,16 @@
# Copyright (c) 2008-2013 Erik Svensson <erik.public@gmail.com>
# Licensed under the MIT license.
import socket, datetime, logging
import socket
import datetime
import logging
from collections import namedtuple
import transmissionrpc.constants as constants
from transmissionrpc.constants import LOGGER
from six import string_types, iteritems
UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']
def format_size(size):

View file

@ -3,9 +3,7 @@
import itertools
import mimetools
import mimetypes
from cStringIO import StringIO
import urllib
import urllib2
class MultiPartForm(object):
"""Accumulate the data to be used when posting a form."""