diff --git a/autoProcessTV/autoProcessTV.py b/autoProcessTV/autoProcessTV.py index 04f4ec06..c784f374 100644 --- a/autoProcessTV/autoProcessTV.py +++ b/autoProcessTV/autoProcessTV.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # Author: Nic Wolfe # URL: http://code.google.com/p/sickbeard/ # @@ -12,95 +14,138 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . +from __future__ import with_statement -import sys -import urllib import os.path -import ConfigParser +import sys -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 ('', '') +# Try importing Python 2 modules using new names +try: + import ConfigParser as configparser + import urllib2 + from urllib import urlencode - def openit(self, url): - self.numTries = 0 - return urllib.FancyURLopener.open(self, url) +# On error import Python 3 modules +except ImportError: + import configparser + import urllib.request as urllib2 + from urllib.parse import urlencode + +# workaround for broken urllib2 in python 2.6.5: wrong credentials lead to an infinite recursion +if sys.version_info >= (2, 6, 5) and sys.version_info < (2, 6, 6): + class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler): + def retry_http_basic_auth(self, host, req, realm): + # don't retry if auth failed + if req.get_header(self.auth_header, None) is not None: + return None + + return urllib2.HTTPBasicAuthHandler.retry_http_basic_auth(self, host, req, realm) + +else: + HTTPBasicAuthHandler = urllib2.HTTPBasicAuthHandler -def processEpisode(dirName, nzbName=None, failed=False): +def processEpisode(dir_to_process, org_NZB_name=None): + # Default values + host = "localhost" + port = "8081" + username = "" + password = "" + ssl = 0 + web_root = "/" + + default_url = host + ":" + port + web_root + if ssl: + default_url = "https://" + default_url + else: + default_url = "http://" + default_url + + # Get values from config_file + config = configparser.RawConfigParser() + config_filename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg") + + if not os.path.isfile(config_filename): + print ("ERROR: " + config_filename + " doesn\'t exist") + print ("copy /rename " + config_filename + ".sample and edit\n") + print ("Trying default url: " + default_url + "\n") + + else: + try: + print ("Loading config from " + config_filename + "\n") + + with open(config_filename, "r") as fp: + config.readfp(fp) + + # Replace default values with config_file values + host = config.get("SickBeard", "host") + port = config.get("SickBeard", "port") + username = config.get("SickBeard", "username") + password = config.get("SickBeard", "password") + + try: + ssl = int(config.get("SickBeard", "ssl")) + + except (configparser.NoOptionError, ValueError): + pass + + try: + web_root = config.get("SickBeard", "web_root") + if not web_root.startswith("/"): + web_root = "/" + web_root + + if not web_root.endswith("/"): + web_root = web_root + "/" + + except configparser.NoOptionError: + pass + + except EnvironmentError: + e = sys.exc_info()[1] + print ("Could not read configuration file: " + str(e)) + # There was a config_file, don't use default values but exit + sys.exit(1) - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg") - print "Loading config from", configFilename - - if not os.path.isfile(configFilename): - print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?" - sys.exit(-1) - - try: - fp = open(configFilename, "r") - config.readfp(fp) - fp.close() - except IOError, e: - print "Could not read configuration file: ", str(e) - sys.exit(1) - - host = config.get("SickBeard", "host") - port = config.get("SickBeard", "port") - username = config.get("SickBeard", "username") - password = config.get("SickBeard", "password") - try: - ssl = int(config.get("SickBeard", "ssl")) - except (ConfigParser.NoOptionError, ValueError): - ssl = 0 - - try: - web_root = config.get("SickBeard", "web_root") - except ConfigParser.NoOptionError: - web_root = "" - params = {} - + params['quiet'] = 1 - params['dir'] = dirName - if nzbName != None: - params['nzbName'] = nzbName + params['dir'] = dir_to_process + if org_NZB_name != None: + params['nzbName'] = org_NZB_name - params['failed'] = int(failed) - - myOpener = AuthURLOpener(username, password) - if ssl: protocol = "https://" else: protocol = "http://" - url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params) - - print "Opening URL:", url - + url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode?" + urlencode(params) + + print ("Opening URL: " + url) + try: - urlObj = myOpener.openit(url) - except IOError, e: - print "Unable to open URL: ", str(e) + password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() + password_mgr.add_password(None, url, username, password) + handler = HTTPBasicAuthHandler(password_mgr) + opener = urllib2.build_opener(handler) + urllib2.install_opener(opener) + + result = opener.open(url).readlines() + + for line in result: + if line: + print (line.strip()) + + except IOError: + e = sys.exc_info()[1] + print ("Unable to open URL: " + str(e)) sys.exit(1) - - result = urlObj.readlines() - for line in result: - print line - + + +if __name__ == "__main__": + print ("This module is supposed to be used as import in other scripts and not run standalone.") + print ("Use sabToSickBeard instead.") + sys.exit(1) \ No newline at end of file diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index fa561465..b64bfa95 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -1001,7 +1001,7 @@ class PostProcessor(object): self._moveAndSymlink(self.file_path, dest_path, new_base_name, sickbeard.MOVE_ASSOCIATED_FILES, sickbeard.USE_SUBTITLES and ep_obj.show.subtitles) else: - logger.log(u"Unknown process method: " + sickbeard.PROCESS_METHOD, logger.ERROR) + logger.log(u"Unknown process method: " + str(self.process_method), logger.ERROR) raise exceptions.PostProcessingFailed("Unable to move the files to their new home") except (OSError, IOError): raise exceptions.PostProcessingFailed("Unable to move the files to their new home") diff --git a/sickbeard/properFinder.py b/sickbeard/properFinder.py index b2ed3484..26a112ba 100644 --- a/sickbeard/properFinder.py +++ b/sickbeard/properFinder.py @@ -254,9 +254,7 @@ class ProperFinder(): result.quality = curProper.quality # snatch it - downloadResult = search.snatchEpisode(result, SNATCHED_PROPER) - - return downloadResult + search.snatchEpisode(result, SNATCHED_PROPER) def _genericName(self, name): return name.replace(".", " ").replace("-", " ").replace("_", " ").lower() diff --git a/sickbeard/providers/kat.py b/sickbeard/providers/kat.py index 4530037f..5e4069a3 100644 --- a/sickbeard/providers/kat.py +++ b/sickbeard/providers/kat.py @@ -253,7 +253,7 @@ class KATProvider(generic.TorrentProvider): for tr in torrent_rows[1:]: try: - link = self.url + (tr.find('div', {'class': 'torrentname'}).find_all('a')[1])['href'] + link = urlparse.urljoin(self.url,(tr.find('div', {'class': 'torrentname'}).find_all('a')[1])['href']) id = tr.get('id')[-7:] title = (tr.find('div', {'class': 'torrentname'}).find_all('a')[1]).text url = tr.find('a', 'imagnet')['href'] diff --git a/sickbeard/providers/scc.py b/sickbeard/providers/scc.py index bd6ca57f..4f5f896b 100644 --- a/sickbeard/providers/scc.py +++ b/sickbeard/providers/scc.py @@ -174,8 +174,11 @@ class SCCProvider(generic.TorrentProvider): #Continue only if one Release is found if len(torrent_rows) < 2: - logger.log(u"The Data returned from " + self.name + " do not contains any torrent", - logger.DEBUG) + if html.title: + source = self.name + " (" + html.title.string + ")" + else: + source = self.name + logger.log(u"The Data returned from " + source + " does not contain any torrent", logger.DEBUG) continue for result in torrent_table.find_all('tr')[1:]: