From 66e499ab23e6e06dc8ee4fd91afd99d1c2ddfe70 Mon Sep 17 00:00:00 2001 From: echel0n Date: Mon, 19 May 2014 06:08:16 -0700 Subject: [PATCH] Fixes issues with daily searcher not snatching its results when it has any to snatch. Fixes issues with not properly converting scene numbering eps to indexer numbering. --- sickbeard/name_parser/parser.py | 17 ++++-------- sickbeard/providers/generic.py | 9 ++++--- sickbeard/providers/hdbits.py | 47 ++++++++++++++++++++++++++++++--- sickbeard/search_queue.py | 13 +++++---- sickbeard/tvcache.py | 5 +++- 5 files changed, 64 insertions(+), 27 deletions(-) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index 664da402..a527f5c4 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -376,23 +376,16 @@ class ParseResult(object): return to_return.encode('utf-8') - def convert(self): - if not self.series_name: return self # can't work without a series name + def convert(self, show): + if not show: return self # need show object + if not self.season_number: return self # can't work without a season + if not len(self.episode_numbers): return self # need at least one episode if self.air_by_date or self.sports: return self # scene numbering does not apply to air-by-date - if self.season_number == None: return self # can't work without a season - if len(self.episode_numbers) == 0: return self # need at least one episode - - showResult = helpers.searchDBForShow(self.series_name) - if showResult: - self.show = helpers.findCertainShow(sickbeard.showList, int(showResult[0])) - - if not self.show: - return self new_episode_numbers = [] new_season_numbers = [] for epNo in self.episode_numbers: - (s, e) = scene_numbering.get_indexer_numbering(self.show.indexerid, self.show.indexer, self.season_number, + (s, e) = scene_numbering.get_indexer_numbering(show.indexerid, show.indexer, self.season_number, epNo) new_episode_numbers.append(e) new_season_numbers.append(s) diff --git a/sickbeard/providers/generic.py b/sickbeard/providers/generic.py index 516f4592..308d1b0b 100644 --- a/sickbeard/providers/generic.py +++ b/sickbeard/providers/generic.py @@ -289,11 +289,14 @@ class GenericProvider: # parse the file name try: myParser = NameParser(False) - parse_result = myParser.parse(title).convert() + parse_result = myParser.parse(title) except InvalidNameException: logger.log(u"Unable to parse the filename " + title + " into a valid episode", logger.WARNING) continue + # scene -> indexer numbering + parse_result = parse_result.convert(self.show) + if not (self.show.air_by_date or self.show.sports): if search_mode == 'sponly' and len(parse_result.episode_numbers): logger.log( @@ -308,13 +311,13 @@ class GenericProvider: ep_obj.season) + ", ignoring", logger.DEBUG) continue elif len(parse_result.episode_numbers) and ( - parse_result.season_number != ep_obj.season or ep_obj.episode not in parse_result.episode_numbers): + parse_result.season_number != ep_obj.scene_season or ep_obj.episode not in parse_result.episode_numbers): logger.log(u"Episode " + title + " isn't " + str(ep_obj.season) + "x" + str( ep_obj.episode) + ", skipping it", logger.DEBUG) continue # we just use the existing info for normal searches - actual_season = season + actual_season = ep_obj.season actual_episodes = parse_result.episode_numbers else: if not (parse_result.air_by_date or parse_result.sports): diff --git a/sickbeard/providers/hdbits.py b/sickbeard/providers/hdbits.py index 536436f9..f1b5ce48 100644 --- a/sickbeard/providers/hdbits.py +++ b/sickbeard/providers/hdbits.py @@ -13,18 +13,23 @@ # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . +import re import time import datetime import urllib +import urlparse +import sys import generic import sickbeard +from lib import requests +from lib.requests import exceptions from sickbeard import classes from sickbeard import logger, tvcache, exceptions from sickbeard import helpers +from sickbeard import clients from sickbeard.common import cpu_presets from sickbeard.exceptions import ex, AuthException - try: import json except ImportError: @@ -41,13 +46,15 @@ class HDBitsProvider(generic.TorrentProvider): self.enabled = False self.username = None self.password = None + self.uid = None + self.hash = None self.ratio = None self.cache = HDBitsCache(self) - self.url = 'https://hdbits.org' - self.search_url = 'https://hdbits.org/api/torrents' - self.rss_url = 'https://hdbits.org/api/torrents' + self.url = 'http://hdbits.org' + self.search_url = 'http://hdbits.org/api/torrents' + self.rss_url = 'http://hdbits.org/api/torrents' self.download_url = 'http://hdbits.org/download.php?' def isEnabled(self): @@ -92,6 +99,38 @@ class HDBitsProvider(generic.TorrentProvider): return (title, url) + def getURL(self, url, post_data=None, headers=None, json=False): + + if not self.session: + self.session = requests.Session() + + try: + # Remove double-slashes from url + parsed = list(urlparse.urlparse(url)) + parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one + url = urlparse.urlunparse(parsed) + + if sickbeard.PROXY_SETTING: + proxies = { + "http": sickbeard.PROXY_SETTING, + "https": sickbeard.PROXY_SETTING, + } + + r = self.session.get(url, data=post_data, proxies=proxies, verify=False) + else: + r = self.session.get(url, data=post_data, verify=False) + except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e: + logger.log(u"Error loading " + self.name + " URL: " + str(sys.exc_info()) + " - " + ex(e), logger.ERROR) + return None + + if r.status_code != 200: + logger.log(self.name + u" page requested with url " + url + " returned status code is " + str( + r.status_code) + ': ' + clients.http_error_code[r.status_code], logger.WARNING) + return None + if json: + return r.json() + return r.content + def _doSearch(self, search_params, epcount=0, age=0): results = [] diff --git a/sickbeard/search_queue.py b/sickbeard/search_queue.py index 96d0eff3..fb6bf0f4 100644 --- a/sickbeard/search_queue.py +++ b/sickbeard/search_queue.py @@ -100,14 +100,13 @@ class DailySearchQueueItem(generic_queue.QueueItem): if not len(foundResults): logger.log(u"No needed episodes found during daily search for [" + self.show.name + "]") else: - for curEp in foundResults: - for result in curEp: - # just use the first result for now - logger.log(u"Downloading " + result.name + " from " + result.provider.name) - search.snatchEpisode(result) + for result in foundResults: + # just use the first result for now + logger.log(u"Downloading " + result.name + " from " + result.provider.name) + search.snatchEpisode(result) - # give the CPU a break - time.sleep(2) + # give the CPU a break + time.sleep(2) generic_queue.QueueItem.finish(self) diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index efc1e302..1d7b7865 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -268,7 +268,7 @@ class TVCache(): # if we don't have complete info then parse the filename to get it try: myParser = NameParser() - parse_result = myParser.parse(name).convert() + parse_result = myParser.parse(name) except InvalidNameException: logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG) return None @@ -308,6 +308,9 @@ class TVCache(): sickbeard.name_cache.addNameToCache(parse_result.series_name, 0) return None + # scene -> indexer numbering + parse_result = parse_result.convert(showObj) + season = episodes = None if parse_result.air_by_date or parse_result.sports: myDB = db.DBConnection()