mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
Added feature that will auto-detect the SickBeard fork
This commit is contained in:
parent
2cb59eb0dd
commit
351215add1
7 changed files with 113 additions and 36 deletions
|
@ -17,10 +17,11 @@ import extractor.extractor as extractor
|
||||||
import autoProcess.autoProcessComics as autoProcessComics
|
import autoProcess.autoProcessComics as autoProcessComics
|
||||||
import autoProcess.autoProcessGames as autoProcessGames
|
import autoProcess.autoProcessGames as autoProcessGames
|
||||||
import autoProcess.autoProcessMusic as autoProcessMusic
|
import autoProcess.autoProcessMusic as autoProcessMusic
|
||||||
import autoProcess.autoProcessTV as autoProcessTV
|
|
||||||
import autoProcess.autoProcessMovie as autoProcessMovie
|
import autoProcess.autoProcessMovie as autoProcessMovie
|
||||||
|
import autoProcess.autoProcessTV as autoProcessTV
|
||||||
from autoProcess.nzbToMediaEnv import *
|
from autoProcess.nzbToMediaEnv import *
|
||||||
from autoProcess.nzbToMediaUtil import *
|
from autoProcess.nzbToMediaUtil import *
|
||||||
|
from autoSickBeardFork import autoFork
|
||||||
from utorrent.client import UTorrentClient
|
from utorrent.client import UTorrentClient
|
||||||
from transmissionrpc.client import Client as TransmissionClient
|
from transmissionrpc.client import Client as TransmissionClient
|
||||||
from synchronousdeluge.client import DelugeClient
|
from synchronousdeluge.client import DelugeClient
|
||||||
|
@ -491,7 +492,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
cpsCategory = (config.get("CouchPotato", "cpsCategory")).split(',') # movie
|
cpsCategory = (config.get("CouchPotato", "cpsCategory")).split(',') # movie
|
||||||
sbCategory = (config.get("SickBeard", "sbCategory")).split(',') # tv
|
sbCategory = (config.get("SickBeard", "sbCategory")).split(',') # tv
|
||||||
sbFork = config.get("SickBeard", "fork") # default
|
sbFork, sbParams = autoFork(config.get("SickBeard", "fork")) # default
|
||||||
Torrent_ForceLink = int(config.get("SickBeard", "Torrent_ForceLink")) # 1
|
Torrent_ForceLink = int(config.get("SickBeard", "Torrent_ForceLink")) # 1
|
||||||
hpCategory = (config.get("HeadPhones", "hpCategory")).split(',') # music
|
hpCategory = (config.get("HeadPhones", "hpCategory")).split(',') # music
|
||||||
mlCategory = (config.get("Mylar", "mlCategory")).split(',') # comics
|
mlCategory = (config.get("Mylar", "mlCategory")).split(',') # comics
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Transcoder
|
||||||
from nzbToMediaEnv import *
|
from nzbToMediaEnv import *
|
||||||
from nzbToMediaUtil import *
|
from nzbToMediaUtil import *
|
||||||
from nzbToMediaSceneExceptions import process_all_exceptions
|
from nzbToMediaSceneExceptions import process_all_exceptions
|
||||||
|
from autoSickBeardFork import autoFork
|
||||||
|
|
||||||
Logger = logging.getLogger()
|
Logger = logging.getLogger()
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@ class AuthURLOpener(urllib.FancyURLopener):
|
||||||
self.numTries = 0
|
self.numTries = 0
|
||||||
return urllib.FancyURLopener.open(self, url)
|
return urllib.FancyURLopener.open(self, url)
|
||||||
|
|
||||||
|
|
||||||
def delete(dirName):
|
def delete(dirName):
|
||||||
Logger.info("Deleting failed files and folder %s", dirName)
|
Logger.info("Deleting failed files and folder %s", dirName)
|
||||||
try:
|
try:
|
||||||
|
@ -63,6 +63,7 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
|
||||||
port = config.get(section, "port")
|
port = config.get(section, "port")
|
||||||
username = config.get(section, "username")
|
username = config.get(section, "username")
|
||||||
password = config.get(section, "password")
|
password = config.get(section, "password")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ssl = int(config.get(section, "ssl"))
|
ssl = int(config.get(section, "ssl"))
|
||||||
except (ConfigParser.NoOptionError, ValueError):
|
except (ConfigParser.NoOptionError, ValueError):
|
||||||
|
@ -78,11 +79,6 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
|
||||||
except ConfigParser.NoOptionError:
|
except ConfigParser.NoOptionError:
|
||||||
watch_dir = ""
|
watch_dir = ""
|
||||||
|
|
||||||
try:
|
|
||||||
fork = config.get(section, "fork")
|
|
||||||
except ConfigParser.NoOptionError:
|
|
||||||
fork = "default"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
transcode = int(config.get("Transcoder", "transcode"))
|
transcode = int(config.get("Transcoder", "transcode"))
|
||||||
except (ConfigParser.NoOptionError, ValueError):
|
except (ConfigParser.NoOptionError, ValueError):
|
||||||
|
@ -125,16 +121,14 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
|
||||||
if os.path.isdir(SpecificPath):
|
if os.path.isdir(SpecificPath):
|
||||||
dirName = SpecificPath
|
dirName = SpecificPath
|
||||||
|
|
||||||
SICKBEARD_TORRENT_USE = SICKBEARD_TORRENT
|
# auto-detect fork type
|
||||||
|
fork, params = autoFork()
|
||||||
|
|
||||||
if clientAgent in ['nzbget','sabnzbd'] and not nzbExtractionBy == "Destination": #Assume Torrent actions (unrar and link) don't happen. We need to check for valid media here.
|
if (not fork in SICKBEARD_TORRENT) or (clientAgent in ['nzbget','sabnzbd'] and not nzbExtractionBy == "Destination"):
|
||||||
SICKBEARD_TORRENT_USE = []
|
|
||||||
|
|
||||||
if not fork in SICKBEARD_TORRENT_USE:
|
|
||||||
process_all_exceptions(nzbName.lower(), dirName)
|
process_all_exceptions(nzbName.lower(), dirName)
|
||||||
nzbName, dirName = converto_to_ascii(nzbName, dirName)
|
nzbName, dirName = converto_to_ascii(nzbName, dirName)
|
||||||
|
|
||||||
if nzbName != "Manual Run" and not fork in SICKBEARD_TORRENT_USE:
|
if nzbName != "Manual Run" and not fork in SICKBEARD_TORRENT:
|
||||||
# Now check if movie files exist in destination:
|
# Now check if movie files exist in destination:
|
||||||
video = int(0)
|
video = int(0)
|
||||||
for dirpath, dirnames, filenames in os.walk(dirName):
|
for dirpath, dirnames, filenames in os.walk(dirName):
|
||||||
|
@ -157,10 +151,12 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
|
||||||
if watch_dir != "" and (not host in ['localhost', '127.0.0.1'] or nzbName == "Manual Run"):
|
if watch_dir != "" and (not host in ['localhost', '127.0.0.1'] or nzbName == "Manual Run"):
|
||||||
dirName = watch_dir
|
dirName = watch_dir
|
||||||
|
|
||||||
params = {}
|
|
||||||
|
|
||||||
params['quiet'] = 1
|
params['quiet'] = 1
|
||||||
if fork in SICKBEARD_DIRNAME:
|
|
||||||
|
if hasattr(params, "failed"):
|
||||||
|
params['failed'] = failed
|
||||||
|
|
||||||
|
if hasattr(params, "dirName"):
|
||||||
params['dirName'] = dirName
|
params['dirName'] = dirName
|
||||||
else:
|
else:
|
||||||
params['dir'] = dirName
|
params['dir'] = dirName
|
||||||
|
@ -168,9 +164,6 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
|
||||||
if nzbName != None:
|
if nzbName != None:
|
||||||
params['nzbName'] = nzbName
|
params['nzbName'] = nzbName
|
||||||
|
|
||||||
if fork in SICKBEARD_FAILED:
|
|
||||||
params['failed'] = failed
|
|
||||||
|
|
||||||
if status == 0:
|
if status == 0:
|
||||||
Logger.info("The download succeeded. Sending process request to SickBeard's %s branch", fork)
|
Logger.info("The download succeeded. Sending process request to SickBeard's %s branch", fork)
|
||||||
elif fork in SICKBEARD_FAILED:
|
elif fork in SICKBEARD_FAILED:
|
||||||
|
|
|
@ -60,10 +60,7 @@ def migrate():
|
||||||
option = "sbCategory"
|
option = "sbCategory"
|
||||||
if option == "failed_fork": # change this old format
|
if option == "failed_fork": # change this old format
|
||||||
option = "fork"
|
option = "fork"
|
||||||
if int(value) == 1:
|
value = "auto"
|
||||||
value = "failed"
|
|
||||||
else:
|
|
||||||
value = "default"
|
|
||||||
if option == "outputDirectory": # move this to new location format
|
if option == "outputDirectory": # move this to new location format
|
||||||
value = os.path.split(os.path.normpath(value))[0]
|
value = os.path.split(os.path.normpath(value))[0]
|
||||||
confignew.set("Torrent", option, value)
|
confignew.set("Torrent", option, value)
|
||||||
|
|
|
@ -9,11 +9,15 @@ SABNZB_NO_OF_ARGUMENTS = 8
|
||||||
SABNZB_0717_NO_OF_ARGUMENTS = 9
|
SABNZB_0717_NO_OF_ARGUMENTS = 9
|
||||||
|
|
||||||
# Constants pertaining to SickBeard Branches:
|
# Constants pertaining to SickBeard Branches:
|
||||||
# extend this list to include all branches/forks that use "failed" to handle failed downloads.
|
fork_default = "default"
|
||||||
SICKBEARD_FAILED = ["failed", "TPB-failed", "Pistachitos", "TPB"]
|
fork_failed = "failed"
|
||||||
# extend this list to include all branches/forks that use "dirName" not "dir"
|
fork_failed_torrent = "failed-torrent"
|
||||||
SICKBEARD_DIRNAME = ["failed"]
|
|
||||||
# extend this list to include all branches/forks that process rar and link files for torrents and therefore skip extraction and linking in TorrentToMedia.
|
|
||||||
SICKBEARD_TORRENT = ["TPB", "TPB-failed", "Pistachitos"]
|
|
||||||
|
|
||||||
|
forks = {}
|
||||||
|
forks[fork_default] = {"dir": None, "process": None}
|
||||||
|
forks[fork_failed] = {"dir": None, "failed": None}
|
||||||
|
forks[fork_failed_torrent] = {"dir": None, "failed": None, "process_method": None}
|
||||||
|
|
||||||
|
SICKBEARD_FAILED = [fork_failed, fork_failed_torrent]
|
||||||
|
SICKBEARD_TORRENT = [fork_failed_torrent]
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ ssl = 0
|
||||||
delay = 0
|
delay = 0
|
||||||
wait_for = 5
|
wait_for = 5
|
||||||
watch_dir =
|
watch_dir =
|
||||||
fork = default
|
fork = auto
|
||||||
delete_failed = 0
|
delete_failed = 0
|
||||||
nzbExtractionBy = Downloader
|
nzbExtractionBy = Downloader
|
||||||
Torrent_ForceLink = 1
|
Torrent_ForceLink = 1
|
||||||
|
|
82
autoSickBeardFork.py
Normal file
82
autoSickBeardFork.py
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import sys
|
||||||
|
import urllib
|
||||||
|
import os
|
||||||
|
import ConfigParser
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from autoProcess.nzbToMediaEnv import *
|
||||||
|
|
||||||
|
Logger = logging.getLogger()
|
||||||
|
|
||||||
|
class AuthURLOpener(urllib.FancyURLopener):
|
||||||
|
def __init__(self, user, pw):
|
||||||
|
self.username = user
|
||||||
|
self.password = pw
|
||||||
|
self.numTries = 0
|
||||||
|
urllib.FancyURLopener.__init__(self)
|
||||||
|
|
||||||
|
def prompt_user_passwd(self, host, realm):
|
||||||
|
if self.numTries == 0:
|
||||||
|
self.numTries = 1
|
||||||
|
return (self.username, self.password)
|
||||||
|
else:
|
||||||
|
return ('', '')
|
||||||
|
|
||||||
|
def openit(self, url):
|
||||||
|
self.numTries = 0
|
||||||
|
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")
|
||||||
|
|
||||||
|
try:
|
||||||
|
ssl = int(config.get(section, "ssl"))
|
||||||
|
except (ConfigParser.NoOptionError, ValueError):
|
||||||
|
ssl = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
web_root = config.get(section, "web_root")
|
||||||
|
except ConfigParser.NoOptionError:
|
||||||
|
web_root = ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
fork = config.get(section, "fork")
|
||||||
|
if not fork in "auto":
|
||||||
|
fork = forks[fork] \
|
||||||
|
if fork in SICKBEARD_FAILED or SICKBEARD_TORRENT else forks[fork_default]
|
||||||
|
except ConfigParser.NoOptionError:
|
||||||
|
fork = forks[fork_default]
|
||||||
|
|
||||||
|
myOpener = AuthURLOpener(username, password)
|
||||||
|
|
||||||
|
if ssl:
|
||||||
|
protocol = "https://"
|
||||||
|
else:
|
||||||
|
protocol = "http://"
|
||||||
|
|
||||||
|
if fork in "auto":
|
||||||
|
Logger.info("Attempting to auto-detect SickBeard fork")
|
||||||
|
for f in forks.iteritems():
|
||||||
|
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(f[1])
|
||||||
|
|
||||||
|
# attempting to auto-detect fork
|
||||||
|
urlObj = myOpener.openit(url)
|
||||||
|
|
||||||
|
if urlObj.getcode() == 200:
|
||||||
|
Logger.info("SickBeard fork auto-detection successful. Fork set to %s", f[0])
|
||||||
|
return f[0], f[1]
|
||||||
|
|
||||||
|
# failed to auto-detect fork
|
||||||
|
Logger.info("SickBeard fork auto-detection failed")
|
||||||
|
|
||||||
|
Logger.info("SickBeard fork set to %s", fork[0])
|
||||||
|
return fork[0], fork[1]
|
|
@ -109,8 +109,8 @@
|
||||||
|
|
||||||
# SickBeard fork.
|
# SickBeard fork.
|
||||||
#
|
#
|
||||||
# set to default or TPB or failed if using the custom "TPB" or "failed fork".
|
# set to default or auto to auto-detect the custom failed fork type".
|
||||||
#sbfork=default
|
#sbfork=auto
|
||||||
|
|
||||||
# SickBeard Delete Failed Downloads (0, 1)
|
# SickBeard Delete Failed Downloads (0, 1)
|
||||||
#
|
#
|
||||||
|
@ -265,8 +265,8 @@ import autoProcess.migratecfg as migratecfg
|
||||||
import autoProcess.autoProcessComics as autoProcessComics
|
import autoProcess.autoProcessComics as autoProcessComics
|
||||||
import autoProcess.autoProcessGames as autoProcessGames
|
import autoProcess.autoProcessGames as autoProcessGames
|
||||||
import autoProcess.autoProcessMusic as autoProcessMusic
|
import autoProcess.autoProcessMusic as autoProcessMusic
|
||||||
import autoProcess.autoProcessTV as autoProcessTV
|
|
||||||
import autoProcess.autoProcessMovie as autoProcessMovie
|
import autoProcess.autoProcessMovie as autoProcessMovie
|
||||||
|
import autoProcess.autoProcessTV as autoProcessTV
|
||||||
from autoProcess.nzbToMediaEnv import *
|
from autoProcess.nzbToMediaEnv import *
|
||||||
from autoProcess.nzbToMediaUtil import *
|
from autoProcess.nzbToMediaUtil import *
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue