Re-coded the Indexer cache, cache lookups are only performed for existing shows and we don't add any cache entries unless we are Indexing the show in our database so we don't waste cpu cycles and memory.

Manual and backlog searches both search the cache first before even attempting to send a search request to a provider.

More bugs have been worked out.
This commit is contained in:
echel0n 2014-04-29 06:14:19 -07:00
parent dbee4b6dbf
commit 87b752b4e5
29 changed files with 427 additions and 581 deletions

View file

@ -54,7 +54,7 @@ class FailedProcessor(object):
parser = NameParser(False)
try:
parsed = parser.parse(releaseName, True)
parsed = parser.parse(releaseName)
except InvalidNameException:
self._log(u"Error: release name is invalid: " + releaseName, logger.WARNING)
raise exceptions.FailedProcessingFailed()

View file

@ -255,8 +255,12 @@ def download_file(url, filename):
return True
def findCertainShow(showList, indexerid):
results = filter(lambda x: x.indexerid == indexerid, showList)
def findCertainShow(showList, indexerid=None):
if indexerid:
results = filter(lambda x: x.indexerid == indexerid, showList)
else:
results = filter(lambda x: x.indexerid == indexerid, showList)
if len(results) == 0:
return None
elif len(results) > 1:
@ -276,7 +280,7 @@ def makeDir(path):
return True
def searchDBForShow(regShowName, indexer_id=None):
def searchDBForShow(regShowName):
showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName]))
myDB = db.DBConnection()
@ -319,38 +323,36 @@ def searchDBForShow(regShowName, indexer_id=None):
return None
def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=True):
def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None):
showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName]))
# Query Indexers for each search term and build the list of results
for indexer in sickbeard.indexerApi().indexers if not indexer else [int(indexer)]:
# Query Indexers for each search term and build the list of results
lINDEXER_API_PARMS = sickbeard.indexerApi(indexer).api_params.copy()
if ui:lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI
if ui:lINDEXER_API_PARMS['custom_ui'] = ui
t = sickbeard.indexerApi(indexer).indexer(**lINDEXER_API_PARMS)
for name in showNames:
logger.log(u"Trying to find " + name + " on " + sickbeard.indexerApi(indexer).name, logger.DEBUG)
try:
if indexer_id:
search = t[indexer_id]
else:
search = t[name]
if isinstance(search, dict):
search = [search]
search = t[indexer_id] if indexer_id else t[name]
# add search results
for i in range(len(search)):
part = search[i]
seriesname = part['seriesname'].encode('UTF-8').lower()
name = name.encode('UTF-8').lower()
seriesname = part['seriesname'].lower()
if (name in seriesname) or (indexer_id is not None and part['id'] == indexer_id):
if str(name).lower() == seriesname or (indexer_id and part['id'] == indexer_id):
return [sickbeard.indexerApi(indexer).config['id'], part['id']]
except KeyError:break
except Exception:continue
except KeyError:
if indexer:
break
else:
continue
except Exception:
continue
def sizeof_fmt(num):
'''
@ -950,8 +952,6 @@ def _check_against_names(name, show):
def get_show_by_name(name, showList, useIndexer=False):
logger.log(u"Trying to get the indexerid for " + name, logger.DEBUG)
if showList:
for show in showList:
if _check_against_names(name, show):

View file

@ -190,48 +190,49 @@ sports_regexs = [
('sports_event',
# Show.Name.123.Event.Nov.23rd.2010.Source.Quality.Etc-Group
'''
^(?P<series_name>.*?)[. _-]+
(?P<parts>\d{1,3}\d{1,3}.*?)[. _-]+
(?P<event>.*?)[. _-]+
(?P<air_day>\d{1,2}).+
(?P<air_month>[a-zA-Z]{3,})[. _-]+
(?P<air_year>\d{4})[. _-]+
(?P<extra_info>.*?(?<![. _-])(?<!WEB))[. _-]+
^(?P<series_name>.*?)\W
(?P<parts>\d{1,3})\W
(?P<event>.*?)\W
(?P<air_day>\d{1,2})(\w{2})\W
(?P<air_month>\w{3,})\W
(?P<air_year>\d{4})\W
(?P<extra_info>.*?)\W
(?P<release_group>.*?)$
'''),
('sports_event_without_parts',
# Show.Name.Event.Nov.23rd.2010.Source.Quality.Etc-Group
'''
^(?P<series_name>.*?)[. _-]+
(?P<event>.*?)[. _-]+
(?P<air_day>\d{1,2}).+
(?P<air_month>[a-zA-Z]{3,})[. _-]+
(?P<air_year>\d{4})[. _-]+
(?P<extra_info>.*?(?<![. _-])(?<!WEB))[. _-]+
^(?P<series_name>.*?)\W
(?P<event>.*?)\W
(?P<air_day>\d{1,2})(\w{2})\W
(?P<air_month>\w{3,})\W
(?P<air_year>\d{4})\W
(?P<extra_info>.*?)\W
(?P<release_group>.*?)$
'''),
('sports_parts_without_event',
# Show.Name.Event.Nov.23rd.2010.Source.Quality.Etc-Group
'''
^(?P<series_name>.*?)[. _-]+
(?P<parts>\d{1,3}\d{1,3}.*?)[. _-]+
(?P<air_day>\d{1,2}).+
(?P<air_month>[a-zA-Z]{3,})[. _-]+
(?P<air_year>\d{4})[. _-]+
(?P<extra_info>.*?(?<![. _-])(?<!WEB))[. _-]+
^(?P<series_name>.*?)\W
(?P<parts>\d{1,3})\W
(?P<air_day>\d{1,2})(\w{2})\W
(?P<air_month>\w{3,})\W
(?P<air_year>\d{4})\W
(?P<extra_info>.*?)\W
(?P<release_group>.*?)$
'''),
('sports_date_only',
# Show.Name.Event.Nov.23rd.2010.Source.Quality.Etc-Group
'''
^(?P<series_name>.*?)[. _-]+
(?P<air_day>\d{1,2})[. _-]+
(?P<air_month>[a-zA-Z]{3,})[. _-]+
(?P<air_year>\d{4})[. _-]+
(?P<extra_info>.*?(?<![. _-])(?<!WEB))[. _-]+
(?P<release_group>.*?)$
^(?P<series_name>.*?)\W
(?P<air_day>\d{1,2})(\w{2})\W
(?P<air_month>\w{3,})\W
(?P<air_year>\d{4})\W
(?P<extra_info>.*?)\W
(?P<release_group>.*?)$
'''),
]

View file

@ -538,7 +538,7 @@ class PostProcessor(object):
# see if we can find the name on the Indexer
for cur_name in name_list:
foundInfo = helpers.searchIndexerForShowID(cur_name)
foundInfo = helpers.searchIndexerForShowID(cur_name, ui=classes.ShowListUI)
if foundInfo:
indexer_id = foundInfo[1]
self._log(

View file

@ -37,7 +37,6 @@ import math
class BTNProvider(generic.TorrentProvider):
def __init__(self):
generic.TorrentProvider.__init__(self, "BTN")
self.supportsBacklog = True
@ -191,58 +190,55 @@ class BTNProvider(generic.TorrentProvider):
return (title, url)
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_params = []
name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid) + [show.name]
name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
for name in name_exceptions:
current_params = {}
if show.indexer == 1:
current_params['tvdb'] = show.indexerid
elif show.indexer == 2:
current_params['tvrage'] = show.indexerid
if self.show.indexer == 1:
current_params['tvdb'] = self.show.indexerid
elif self.show.indexer == 2:
current_params['tvrage'] = self.show.indexerid
else:
# Search by name if we don't have tvdb or tvrage id
current_params['series'] = sanitizeSceneName(name)
whole_season_params = current_params.copy()
partial_season_params = current_params.copy()
# Search for entire seasons: no need to do special things for air by date shows
whole_season_params['category'] = 'Season'
whole_season_params['name'] = 'Season ' + str(season)
search_params.append(whole_season_params)
# Search for episodes in the season
search_params.append(self._get_episode_search_strings(show, season, episode)[0])
search_params.append(self._get_episode_search_strings(season, episode)[0])
return search_params
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
if not episode:
return [{}]
search_params = {'category': 'Episode'}
if show.indexer == 1:
search_params['tvdb'] = show.indexerid
elif show.indexer == 2:
search_params['tvrage'] = show.indexerid
if self.show.indexer == 1:
search_params['tvdb'] = self.show.indexerid
elif self.show.indexer == 2:
search_params['tvrage'] = self.show.indexerid
else:
search_params['series'] = sanitizeSceneName(show.name)
search_params['series'] = sanitizeSceneName(self.show.name)
if show.air_by_date:
if self.show.air_by_date:
date_str = str(episode)
# BTN uses dots in dates, we just search for the date since that
# combined with the series identifier should result in just one episode
search_params['name'] = date_str.replace('-', '.')
if show.sports:
if self.show.sports:
date_str = str(episode)
# BTN uses dots in dates, we just search for the date since that
@ -258,11 +254,11 @@ class BTNProvider(generic.TorrentProvider):
if 'series' in search_params:
# add new query string for every exception
name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid)
name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid)
for cur_exception in name_exceptions:
# don't add duplicates
if cur_exception == show.name:
if cur_exception == self.show.name:
continue
# copy all other parameters before setting the show name for this exception

View file

@ -52,21 +52,21 @@ class DTTProvider(generic.TorrentProvider):
def _dtt_show_id(self, show_name):
return sanitizeSceneName(show_name).replace('.', '-').lower()
def _get_season_search_strings(self, show, season, episode):
def _get_season_search_strings(self, season, episode):
search_string = []
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
show_string = sanitizeSceneName(show_name).replace('.', '-').lower()
search_string.append(show_string)
return search_string
def _get_episode_search_strings(self, show, season, episode, add_string=''):
return self._get_season_search_strings(show, season, episode)
def _get_episode_search_strings(self, season, episode, add_string=''):
return self._get_season_search_strings(season, episode)
def _doSearch(self, search_params, show=None, age=None):
# show_id = self._dtt_show_id(show.name)
# show_id = self._dtt_show_id(self.show.name)
params = {"items": "all"}

View file

@ -61,7 +61,7 @@ class EZRSSProvider(generic.TorrentProvider):
results = {}
if show.air_by_date or show.sports:
if self.show.air_by_date or show.sports:
logger.log(self.name + u" doesn't support air-by-date or sports backloging because of limitations on their RSS search.",
logger.WARNING)
return results
@ -70,33 +70,30 @@ class EZRSSProvider(generic.TorrentProvider):
return results
def _get_season_search_strings(self, show, season, episode):
def _get_season_search_strings(self, season, episode):
params = {}
if not show:
return params
params['show_name'] = helpers.sanitizeSceneName(show.name, ezrss=True).replace('.', ' ').encode('utf-8')
params['show_name'] = helpers.sanitizeSceneName(self.show.name, ezrss=True).replace('.', ' ').encode('utf-8')
params['season'] = season
params['episode'] = self._get_episode_search_strings(show, season, episode)[0]['episode']
params['episode'] = self._get_episode_search_strings(season, episode)[0]['episode']
return [params]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
params = {}
if not episode:
return params
params['show_name'] = helpers.sanitizeSceneName(show.name, ezrss=True).replace('.', ' ').encode('utf-8')
params['show_name'] = helpers.sanitizeSceneName(self.show.name, ezrss=True).replace('.', ' ').encode('utf-8')
if show.air_by_date:
if self.show.air_by_date:
params['date'] = str(episode)
if show.sports:
if self.show.sports:
params['date'] = str(episode)
else:
params['season'] = season

View file

@ -21,14 +21,8 @@ from __future__ import with_statement
import datetime
import os
import sys
import re
import urllib
import urllib2
import itertools
import operator
import collections
import urlparse
import sickbeard
@ -36,13 +30,13 @@ import sickbeard
from lib import requests
from lib.feedparser import feedparser
from sickbeard import helpers, classes, logger, db
from sickbeard.common import Quality, MULTI_EP_RESULT, SEASON_RESULT #, SEED_POLICY_TIME, SEED_POLICY_RATIO
from sickbeard.common import MULTI_EP_RESULT, SEASON_RESULT #, SEED_POLICY_TIME, SEED_POLICY_RATIO
from sickbeard import tvcache
from sickbeard import encodingKludge as ek
from sickbeard.exceptions import ex
from lib.hachoir_parser import createParser
from sickbeard.name_parser.parser import NameParser, InvalidNameException
from sickbeard.common import Quality, Overview
from sickbeard.common import Quality
class GenericProvider:
NZB = "nzb"
@ -54,8 +48,8 @@ class GenericProvider:
self.providerType = None
self.name = name
self.url = ''
self.session = None
self.show = None
self.supportsBacklog = False
self.cache = tvcache.TVCache(self)
@ -64,6 +58,7 @@ class GenericProvider:
self.session.verify = False
self.session.headers.update({'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36'})
def getID(self):
return GenericProvider.makeID(self.name)
@ -225,10 +220,10 @@ class GenericProvider:
def _doSearch(self, search_params, show=None, age=None):
return []
def _get_season_search_strings(self, show, season, episode):
def _get_season_search_strings(self, season, episode):
return []
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
return []
def _get_title_and_url(self, item):
@ -255,40 +250,24 @@ class GenericProvider:
results = {}
self._checkAuth()
self.show = show
regexMode = 0
if show.sports:
regexMode = 1
# update cache
self.cache.updateCache()
regexMode = 2
for ep_obj in ep_objs:
# get scene season/episode info
scene_season = ep_obj.scene_season
scene_episode = ep_obj.scene_episode
if show.air_by_date or show.sports:
scene_episode = ep_obj.airdate
if not seasonSearch:
logger.log(u'Searching "%s" for "%s" as "%s"'
% (self.name, ep_obj.prettyName(), ep_obj.scene_prettyName()))
results = self.cache.searchCache(ep_obj, manualSearch)
logger.log(u"Cache results: " + str(results), logger.DEBUG)
logger.log(u"manualSearch: " + str(manualSearch), logger.DEBUG)
# if we got some results then use them no matter what.
# OR
# return anyway unless we're doing a manual search
if results:
return results
if show.sports:
logger.log(
u'Searching "%s" for "%s" as "%s"' % (self.name, ep_obj.prettyName(), ep_obj.sports_prettyName()))
else:
logger.log(u'Searching "%s" for "%s" as "%s"' % (self.name, ep_obj.prettyName(), ep_obj.scene_prettyName()))
if seasonSearch:
for curString in self._get_season_search_strings(show, scene_season, scene_episode):
for curString in self._get_season_search_strings(ep_obj.scene_season, ep_obj.scene_episode):
itemList += self._doSearch(curString, show=show)
else:
for curString in self._get_episode_search_strings(show, scene_season, scene_episode):
for curString in self._get_episode_search_strings(ep_obj.scene_season, ep_obj.scene_episode):
itemList += self._doSearch(curString, show=show)
for item in itemList:

View file

@ -74,8 +74,8 @@ class HDBitsProvider(generic.TorrentProvider):
# gather all episodes for season and then pick out the wanted episodes and compare to determin if we want whole season or just a few episodes
if episode is None:
seasonEps = show.getAllEpisodes(season)
wantedEps = [x for x in seasonEps if show.getOverview(x.status) in (Overview.WANTED, Overview.QUAL)]
seasonEps = self.show.getAllEpisodes(season)
wantedEps = [x for x in seasonEps if self.show.getOverview(x.status) in (Overview.WANTED, Overview.QUAL)]
else:
wantedEps = [show.getEpisode(season, episode)]

View file

@ -110,39 +110,37 @@ class HDTorrentsProvider(generic.TorrentProvider):
return True
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
elif show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode}
@ -177,7 +175,7 @@ class HDTorrentsProvider(generic.TorrentProvider):
continue
# Remove HDTorrents NEW list
split_data = data.partition('<!-- Show New Torrents After Last Visit -->\n\n\n\n')
split_data = data.partition('<!-- show New Torrents After Last Visit -->\n\n\n\n')
data = split_data[2]
try:
@ -307,18 +305,13 @@ class HDTorrentsProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -92,40 +92,38 @@ class IPTorrentsProvider(generic.TorrentProvider):
return True
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
if show.sports:
for show_name in set(allPossibleShowNames(show)):
if self.show.sports:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode} + ' %s' % add_string
@ -256,12 +254,12 @@ class IPTorrentsProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
searchString = self._get_episode_search_strings(curShow, curEp.scene_season, curEp.scene_episode, curShow.air_by_date or curShow.sports, add_string='PROPER|REPACK')
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, curshow.air_by_date or curshow.sports, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -164,46 +164,36 @@ class KATProvider(generic.TorrentProvider):
logger.log(u"Failed parsing " + self.name + " Traceback: " + traceback.format_exc(), logger.ERROR)
def _get_season_search_strings(self, show, season, episode):
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
if not show:
return []
self.show = show
for show_name in set(allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) + ' -S%02d' % int(season) + 'E' + ' category:tv' #1) ShowName SXX -SXXE
for show_name in set(allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) + ' -S%02d' % int(season) + 'E' + ' category:tv' #1) showName SXX -SXXE
search_string['Season'].append(ep_string)
ep_string = show_name + ' Season ' + str(season) + ' -Ep*' + ' category:tv' #2) ShowName Season X
ep_string = show_name + ' Season ' + str(season) + ' -Ep*' + ' category:tv' #2) showName Season X
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not show:
return []
self.show = show
if show.air_by_date:
for show_name in set(allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-','|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
if show.sports:
for show_name in set(allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(allPossibleShowNames(show)):
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode} + '|' + \
@ -389,18 +379,13 @@ class KATProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -251,11 +251,11 @@ class NewzbinProvider(generic.NZBProvider):
return data
def _get_season_search_strings(self, show, season, episode):
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(show, season, episode)]
def _get_season_search_strings(self, season, episode):
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, season, episode)]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
return ['^' + x for x in show_name_helpers.makeSceneSearchString(show, season, episode)]
def _get_episode_search_strings(self, season, episode, add_string=''):
return ['^' + x for x in show_name_helpers.makeSceneSearchString(self.show, season, episode)]
def _doSearch(self, searchStr, show=None, age=None):

View file

@ -80,15 +80,12 @@ class NewznabProvider(generic.NZBProvider):
def isEnabled(self):
return self.enabled
def _get_season_search_strings(self, show, season, episode):
if not show:
return [{}]
def _get_season_search_strings(self, season, episode):
to_return = []
# add new query strings for exceptions
name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid) + [show.name]
name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid) + [self.show.name]
for cur_exception in name_exceptions:
cur_params = {}
@ -100,13 +97,13 @@ class NewznabProvider(generic.NZBProvider):
cur_params['season'] = str(season)
# episode
cur_params['episode'] = self._get_episode_search_strings(show, season, episode)[0]['ep']
cur_params['episode'] = self._get_episode_search_strings(season, episode)[0]['ep']
to_return.append(cur_params)
return to_return
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
params = {}
@ -114,14 +111,14 @@ class NewznabProvider(generic.NZBProvider):
return [params]
# search
params['q'] = helpers.sanitizeSceneName(show.name)
params['q'] = helpers.sanitizeSceneName(self.show.name)
if show.air_by_date:
if self.show.air_by_date:
date_str = str(episode)
params['season'] = date_str.partition('-')[0]
params['ep'] = date_str.partition('-')[2].replace('-', '/')
elif show.sports:
elif self.show.sports:
date_str = str(episode)
params['season'] = date_str.partition('-')[0]
@ -136,11 +133,11 @@ class NewznabProvider(generic.NZBProvider):
if 'q' in params:
# add new query strings for exceptions
name_exceptions = scene_exceptions.get_scene_exceptions(show.indexerid)
name_exceptions = scene_exceptions.get_scene_exceptions(self.show.indexerid)
for cur_exception in name_exceptions:
# don't add duplicates
if cur_exception == show.name:
if cur_exception == self.show.name:
continue
cur_return = params.copy()

View file

@ -131,41 +131,38 @@ class NextGenProvider(generic.TorrentProvider):
logger.log(u'Failed to login:' + str(error), logger.ERROR)
return False
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
elif show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode}
@ -305,12 +302,12 @@ class NextGenProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
searchString = self._get_episode_search_strings(curShow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -58,13 +58,13 @@ class NyaaProvider(generic.TorrentProvider):
results = generic.TorrentProvider.getSearchResults(self, show, season, ep_objs, seasonSearch, manualSearch)
return results
def _get_season_search_strings(self, show, season, episode):
def _get_season_search_strings(self, season, episode):
names = []
names.extend(show_name_helpers.makeSceneShowSearchStrings(show))
names.extend(show_name_helpers.makeSceneshowSearchStrings(self.show))
return names
def _get_episode_search_strings(self, show, season, episode, add_string=''):
return self._get_season_search_strings(show, season, episode)
def _get_episode_search_strings(self, season, episode, add_string=''):
return self._get_season_search_strings(season, episode)
def _doSearch(self, search_string, show=None, age=None):

View file

@ -53,11 +53,11 @@ class NZBsProvider(generic.NZBProvider):
if sickbeard.NZBS_UID in (None, "") or sickbeard.NZBS_HASH in (None, ""):
raise exceptions.AuthException("NZBs.org authentication details are empty, check your config")
def _get_season_search_strings(self, show, season, episode):
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(show, season, episode)]
def _get_season_search_strings(self, season, episode):
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, season, episode)]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
return ['^' + x for x in show_name_helpers.makeSceneSearchString(show, season, episode)]
def _get_episode_search_strings(self, season, episode, add_string=''):
return ['^' + x for x in show_name_helpers.makeSceneSearchString(self.show, season, episode)]
def _doSearch(self, curString, show=None, age=None):

View file

@ -42,11 +42,11 @@ class NZBsRUSProvider(generic.NZBProvider):
if sickbeard.NZBSRUS_UID in (None, "") or sickbeard.NZBSRUS_HASH in (None, ""):
raise exceptions.AuthException("NZBs'R'US authentication details are empty, check your config")
def _get_season_search_strings(self, show, season, episode):
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(show, season, episode)]
def _get_season_search_strings(self, season, episode):
return ['^' + x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, season, episode)]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
return ['^' + x for x in show_name_helpers.makeSceneSearchString(show, season, episode)]
def _get_episode_search_strings(self, season, episode, add_string=''):
return ['^' + x for x in show_name_helpers.makeSceneSearchString(self.show, season, episode)]
def _doSearch(self, search, show=None, age=None):
params = {'uid': sickbeard.NZBSRUS_UID,

View file

@ -85,11 +85,11 @@ class OmgwtfnzbsProvider(generic.NZBProvider):
return True
def _get_season_search_strings(self, show, season, episode):
return [x for x in show_name_helpers.makeSceneSeasonSearchString(show, season, episode)]
def _get_season_search_strings(self, season, episode):
return [x for x in show_name_helpers.makeSceneSeasonSearchString(self.show, season, episode)]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
return [x for x in show_name_helpers.makeSceneSearchString(show, season, episode)]
def _get_episode_search_strings(self, season, episode, add_string=''):
return [x for x in show_name_helpers.makeSceneSearchString(self.show, season, episode)]
def _get_title_and_url(self, item):
return (item['release'], item['getnzb'])

View file

@ -72,44 +72,41 @@ class PublicHDProvider(generic.TorrentProvider):
quality = Quality.sceneQuality(item[0])
return quality
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX -SXXE
for show_name in set(allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX -SXXE
search_string['Season'].append(ep_string)
ep_string = show_name + ' Season ' + str(season) #2) ShowName Season X
ep_string = show_name + ' Season ' + str(season) #2) showName Season X
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
elif show.sports:
for show_name in set(allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(allPossibleShowNames(show)):
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode}
@ -277,18 +274,18 @@ class PublicHDProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
if curshow.air_by_date or curshow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -99,41 +99,38 @@ class SCCProvider(generic.TorrentProvider):
return True
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
elif show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode}
@ -279,18 +276,18 @@ class SCCProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
if curshow.air_by_date or curshow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -90,43 +90,40 @@ class SpeedCDProvider(generic.TorrentProvider):
return True
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
#If Every episode in Season is a wanted Episode then search for Season first
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name +' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name +' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
#Building the search string with the episodes we need
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
elif show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) +' '+ \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season, 'episodenumber': episode}
@ -235,18 +232,18 @@ class SpeedCDProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
if curshow.air_by_date or curshow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curShow, season, episode,add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curshow, season, episode,add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -169,48 +169,38 @@ class ThePirateBayProvider(generic.TorrentProvider):
return title
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
self.show = show
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
ep_string = show_name + ' Season ' + str(season) + ' -Ep*' #2) ShowName Season X
ep_string = show_name + ' Season ' + str(season) + ' -Ep*' #2) showName Season X
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not show:
return []
self.show = show
if show.air_by_date:
for show_name in set(allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
elif show.sports:
for show_name in set(allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(allPossibleShowNames(show)):
for show_name in set(allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode} + '|' + \
@ -382,18 +372,13 @@ class ThePirateBayProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -112,41 +112,38 @@ class TorrentDayProvider(generic.TorrentProvider):
return True
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
if show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode}
@ -162,6 +159,9 @@ class TorrentDayProvider(generic.TorrentProvider):
freeleech = '&free=on' if sickbeard.TORRENTDAY_FREELEECH else ''
if not self.session:
self._doLogin()
if not self._doLogin():
return []
@ -251,18 +251,18 @@ class TorrentDayProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
if curshow.air_by_date or curshow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -94,41 +94,38 @@ class TorrentLeechProvider(generic.TorrentProvider):
return True
def _get_season_search_strings(self, show, season, episode):
if not show:
return []
def _get_season_search_strings(self, season, episode):
search_string = {'Season': [], 'Episode': []}
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
ep_string = show_name + ' S%02d' % int(season) #1) ShowName SXX
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name + ' S%02d' % int(season) #1) showName SXX
search_string['Season'].append(ep_string)
search_string['Episode'] = self._get_episode_search_strings(show, season, episode)[0]['Episode']
search_string['Episode'] = self._get_episode_search_strings(season, episode)[0]['Episode']
return [search_string]
def _get_episode_search_strings(self, show, season, episode, add_string=''):
def _get_episode_search_strings(self, season, episode, add_string=''):
search_string = {'Episode': []}
if not episode:
return []
if show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
if show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
episode.strftime('%b')
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(show)):
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': season,
'episodenumber': episode}
@ -255,18 +252,13 @@ class TorrentLeechProvider(generic.TorrentProvider):
if not sqlResults:
return []
for sqlShow in sqlResults:
curShow = helpers.findCertainShow(sickbeard.showList, int(sqlShow["showid"]))
curEp = curShow.getEpisode(int(sqlShow["season"]), int(sqlShow["episode"]))
for sqlshow in sqlResults:
curshow = helpers.findCertainshow(sickbeard.showList, int(sqlshow["showid"]))
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
season = curEp.scene_season
episode = curEp.scene_episode
if curShow.air_by_date or curShow.sports:
episode = curEp.airdate
searchString = self._get_episode_search_strings(curshow, curEp.scene_season, curEp.scene_episode, add_string='PROPER|REPACK')
searchString = self._get_episode_search_strings(curShow, season, episode, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0], show=curShow):
for item in self._doSearch(searchString[0], show=curshow):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today()))

View file

@ -39,8 +39,7 @@ from sickbeard import encodingKludge as ek
from sickbeard import providers
from sickbeard import failed_history
from sickbeard.exceptions import ex
from sickbeard.providers.generic import GenericProvider
from sickbeard.providers.generic import GenericProvider, tvcache
def _downloadResult(result):
"""
@ -351,7 +350,7 @@ def isFirstBestMatch(result):
def searchProviders(show, season, episode=None, manualSearch=False):
logger.log(u"Searching for stuff we need from " + show.name + " season " + str(season))
curResults = {}
foundResults = {}
didSearch = False
@ -367,35 +366,56 @@ def searchProviders(show, season, episode=None, manualSearch=False):
ep_obj = show.getEpisode(season, episode)
wantedEps = [ep_obj]
for curProvider in providers.sortedProviderList():
for curProvider in providers.sortedProviderList():
if not curProvider.isActive():
continue
try:
curResults = curProvider.getSearchResults(show, season, wantedEps, seasonSearch, manualSearch)
# update cache
if manualSearch:
curProvider.cache.updateCache()
# make a list of all the results for this provider
for curEp in curResults:
# search cache first for wanted episodes
for ep_obj in wantedEps:
curResults.update(curProvider.cache.searchCache(ep_obj, manualSearch))
# skip non-tv crap
curResults[curEp] = filter(
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name,show),curResults[curEp])
# did we find our results ?
if curResults:
logger.log(u"Cache results: " + str(curResults), logger.DEBUG)
didSearch = True
break
if curEp in foundResults:
foundResults[curEp] += curResults[curEp]
else:
foundResults[curEp] = curResults[curEp]
if not curResults:
for curProvider in providers.sortedProviderList():
if not curProvider.isActive():
continue
except exceptions.AuthException, e:
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
continue
except Exception, e:
logger.log(u"Error while searching " + curProvider.name + ", skipping: " + ex(e), logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG)
continue
try:
if not curResults:
curResults = curProvider.getSearchResults(show, season, wantedEps, seasonSearch, manualSearch)
didSearch = True
# make a list of all the results for this provider
for curEp in curResults:
# skip non-tv crap
curResults[curEp] = filter(
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name,show),curResults[curEp])
if curEp in foundResults:
foundResults[curEp] += curResults[curEp]
else:
foundResults[curEp] = curResults[curEp]
except exceptions.AuthException, e:
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
continue
except Exception, e:
logger.log(u"Error while searching " + curProvider.name + ", skipping: " + ex(e), logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG)
continue
didSearch = True
if not didSearch:
logger.log(u"No NZB/Torrent providers found or enabled in the sickbeard config. Please check your settings.",

View file

@ -1815,6 +1815,16 @@ class TVEpisode(object):
return self._format_pattern('%SN - %XMSx%0XME - %EN')
def sports_prettyName(self):
"""
Returns the name of this episode in a "pretty" human-readable format. Used for logging
and notifications and such.
Returns: A string representing the episode's name and season/ep numbers
"""
return self._format_pattern('%SN - %A-D - %EN')
def _ep_name(self):
"""
Returns the name of the episode to use during renaming. Combines the names of related episodes.

View file

@ -183,175 +183,109 @@ class TVCache():
return True
def _addCacheEntry(self, name, url, season=None, episodes=None, indexer_id=0, quality=None, extraNames=[]):
myDB = self._getDB()
def _addCacheEntry(self, name, url):
cacheDB = self._getDB()
parse_result = None
from_cache = False
indexer_id = None
# if we don't have complete info then parse the filename to get it
for curName in [name] + extraNames:
while(True):
try:
myParser = NameParser()
parse_result = myParser.parse(curName)
parse_result = myParser.parse(name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + curName + " into a valid episode", logger.DEBUG)
continue
logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
return None
if not parse_result:
logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
return None
if not parse_result:
logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
return None
if not parse_result.series_name:
logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
return None
if not parse_result.series_name:
logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
return None
indexer_lang = None
if indexer_id:
# if we have only the indexer_id, use the database
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
if showObj:
self.indexer = int(showObj.indexer)
indexer_lang = showObj.lang
else:
logger.log(u"We were given a Indexer ID " + str(indexer_id) + " but it doesn't match a show we have in our list, so leaving indexer_id empty",logger.DEBUG)
indexer_id = 0
# if no indexerID then fill out as much info as possible by searching the show name
if not indexer_id:
from_cache = False
# check the name cache and see if we already know what show this is
logger.log(
u"Checking the cache for Indexer ID of " + parse_result.series_name,
u"Checking the cahe for show:" + str(parse_result.series_name),
logger.DEBUG)
# remember if the cache lookup worked or not so we know whether we should bother updating it later
indexer_id = name_cache.retrieveNameFromCache(parse_result.series_name)
if indexer_id:
logger.log(u"Cache lookup found " + repr(indexer_id) + ", using that", logger.DEBUG)
cache_id = name_cache.retrieveNameFromCache(parse_result.series_name)
if cache_id:
logger.log(u"Cache lookup found Indexer ID:" + repr(indexer_id) + ", using that for " + parse_result.series_name, logger.DEBUG)
from_cache = True
indexer_id = cache_id
break
# if the cache failed, try looking up the show name in the database
if not indexer_id:
logger.log(
u"Checking the database for show:" + str(parse_result.series_name),
logger.DEBUG)
showResult = helpers.searchDBForShow(parse_result.series_name)
if showResult:
logger.log(
u"Checking the database for Indexer ID of " + str(parse_result.series_name),
logger.DEBUG)
u"Database lookup found Indexer ID:" + str(showResult[1]) + ", using that for " + parse_result.series_name, logger.DEBUG)
indexer_id = showResult[1]
break
showResult = helpers.searchDBForShow(parse_result.series_name)
if showResult:
logger.log(
u"" + parse_result.series_name + " was found to be show " + showResult[2] + " (" + str(
showResult[1]) + ") in our DB.", logger.DEBUG)
indexer_id = showResult[1]
# if we didn't find a Indexer ID return None
if not indexer_id:
return None
# if the database failed, try looking up the show name from scene exceptions list
if not indexer_id:
logger.log(
u"Checking the scene exceptions list for Indexer ID of " + parse_result.series_name,
logger.DEBUG)
sceneResult = sickbeard.scene_exceptions.get_scene_exception_by_name(parse_result.series_name)
if sceneResult:
logger.log(
u"" + str(parse_result.series_name) + " was found in scene exceptions list with Indexer ID: " + str(sceneResult), logger.DEBUG)
indexer_id = sceneResult
# if the DB lookup fails then do a comprehensive regex search
if not indexer_id:
logger.log(
u"Checking the shows list for Indexer ID of " + str(parse_result.series_name),
logger.DEBUG)
for curShow in sickbeard.showList:
if show_name_helpers.isGoodResult(name, curShow, False):
logger.log(u"Successfully matched " + name + " to " + curShow.name + " from shows list",
logger.DEBUG)
indexer_id = curShow.indexerid
indexer_lang = curShow.lang
break
# if the database failed, try looking up the show name from scene exceptions list
if not indexer_id:
logger.log(
u"Checking Indexers for Indexer ID of " + parse_result.series_name,
logger.DEBUG)
# check indexers
try:indexerResult = helpers.searchIndexerForShowID(parse_result.series_name)
except:indexerResult = None
if indexerResult:
logger.log(
u"" + str(parse_result.series_name) + " was found on " + str(sickbeard.indexerApi(indexerResult[0]).name) + " with Indexer ID: " + str(indexerResult[1]), logger.DEBUG)
indexer_id = indexerResult[1]
# if indexer_id was anything but None (0 or a number) then
if not from_cache:
name_cache.addNameToCache(parse_result.series_name, indexer_id)
# if we came out with indexer_id = None it means we couldn't figure it out at all, just use 0 for that
if indexer_id == None:
indexer_id = 0
# if we found the show then retrieve the show object
if indexer_id:
try:
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
except (MultipleShowObjectsException):
showObj = None
if showObj:
self.indexer = int(showObj.indexer)
indexer_lang = showObj.lang
# if the show isn't in out database then return None
try:showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
except:return None
# if we weren't provided with season/episode information then get it from the name that we parsed
if not season:
season = parse_result.season_number if parse_result.season_number != None else 1
if not episodes:
season = None
episodes = None
myDB = db.DBConnection()
if parse_result.air_by_date:
sql_results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
[showObj.indexerid, parse_result.air_date.toordinal()])
if sql_results > 0:
season = int(sql_results[0]["season"])
episodes = [int(sql_results[0]["episode"])]
elif parse_result.sports:
sql_results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
[showObj.indexerid, parse_result.sports_date.toordinal()])
if sql_results > 0:
season = int(sql_results[0]["season"])
episodes = [int(sql_results[0]["episode"])]
else:
season = parse_result.season_number
episodes = parse_result.episode_numbers
# if we have an air-by-date show then get the real season/episode numbers
if (parse_result.air_by_date or parse_result.sports) and indexer_id:
try:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
if not (indexer_lang == "" or indexer_lang == "en" or indexer_lang == None):
lINDEXER_API_PARMS['language'] = indexer_lang
if not (season and episodes):
return None
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
epObj = None
if parse_result.air_by_date:
epObj = t[indexer_id].airedOn(parse_result.air_date)[0]
elif parse_result.sports:
epObj = t[indexer_id].airedOn(parse_result.sports_date)[0]
if epObj is None:
return None
season = int(epObj["seasonnumber"])
episodes = [int(epObj["episodenumber"])]
except sickbeard.indexer_episodenotfound:
logger.log(u"Unable to find episode with date " + str(
parse_result.air_date) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
# convert scene numbered releases before storing to cache
convertedEps = {}
for curEp in episodes:
epObj = showObj.getEpisode(season, curEp, sceneConvert=True)
if not epObj:
return None
except sickbeard.indexer_error, e:
logger.log(u"Unable to contact " + sickbeard.indexerApi(self.indexer).name + ": " + ex(e),
logger.WARNING)
return None
episodeText = "|" + "|".join(map(str, episodes)) + "|"
if not epObj.season in convertedEps:
convertedEps[epObj.season] = []
convertedEps[epObj.season].append(epObj.episode)
# get the current timestamp
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
if not quality:
quality = Quality.sceneQuality(name)
# get quality of release
quality = Quality.sceneQuality(name)
if not isinstance(name, unicode):
name = unicode(name, 'utf-8')
myDB.action(
"INSERT INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality) VALUES (?,?,?,?,?,?,?)",
[name, season, episodeText, indexer_id, url, curTimestamp, quality])
for season, episodes in convertedEps.items():
episodeText = "|" + "|".join(map(str, episodes)) + "|"
cacheDB.action(
"INSERT INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality) VALUES (?,?,?,?,?,?,?)",
[name, season, episodeText, indexer_id, url, curTimestamp, quality])
def searchCache(self, episode, manualSearch=False):
@ -415,35 +349,34 @@ class TVCache():
curEp = int(curEp)
curQuality = int(curResult["quality"])
# items stored in cache are scene numbered, convert before lookups
epObj = showObj.getEpisode(curSeason, curEp, sceneConvert=True)
# if the show says we want that episode then add it to the list
if not showObj.wantEpisode(epObj.season, epObj.episode, curQuality, manualSearch):
if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch):
logger.log(u"Skipping " + curResult["name"] + " because we don't want an episode that's " +
Quality.qualityStrings[curQuality], logger.DEBUG)
else:
epObj = None
if episode:
epObj = episode
# build a result object
title = curResult["name"]
url = curResult["url"]
if epObj:
# build a result object
title = curResult["name"]
url = curResult["url"]
logger.log(u"Found result " + title + " at " + url)
logger.log(u"Found result " + title + " at " + url)
result = self.provider.getResult([epObj])
result.url = url
result.name = title
result.quality = curQuality
result.content = self.provider.getURL(url) \
if self.provider.providerType == sickbeard.providers.generic.GenericProvider.TORRENT \
and not url.startswith('magnet') else None
result = self.provider.getResult([epObj])
result.url = url
result.name = title
result.quality = curQuality
result.content = self.provider.getURL(url) \
if self.provider.providerType == sickbeard.providers.generic.GenericProvider.TORRENT \
and not url.startswith('magnet') else None
# add it to the list
if epObj not in neededEps:
neededEps[epObj] = [result]
else:
neededEps[epObj].append(result)
# add it to the list
if epObj not in neededEps:
neededEps[epObj] = [result]
else:
neededEps[epObj].append(result)
return neededEps

View file

@ -2064,7 +2064,7 @@ class NewHomeAddShows:
# default to TVDB if indexer was not detected
if show_name and (indexer is None or indexer_id is None):
for idx in sickbeard.indexerApi().indexers:
found_info = helpers.searchIndexerForShowID(show_name, idx, indexer_id)
found_info = helpers.searchIndexerForShowID(show_name, idx, indexer_id, ui=classes.ShowListUI)
if found_info:
# set indexer and indexer_id from found info
if indexer is None:
@ -3414,12 +3414,6 @@ class Home:
if isinstance(ep_obj, str):
return json.dumps({'result': 'failure'})
# figure out what segment the episode is in and remember it so we can backlog it
if ep_obj.show.air_by_date or ep_obj.show.sports:
segment = str(ep_obj.airdate)[:7]
else:
segment = ep_obj.season
# make a queue item for it and put it on the queue
ep_queue_item = search_queue.FailedQueueItem(ep_obj.show, {ep_obj.season: ep_obj.episode})
sickbeard.searchQueueScheduler.action.add_item(ep_queue_item) # @UndefinedVariable
@ -3444,28 +3438,6 @@ class Home:
return json.dumps({'result': 'failure'})
# try:
#
#
# ui.notifications.message('Info', pp.log)
# except exceptions.FailedHistoryNotFoundException:
# ui.notifications.error('Not Found Error', 'Couldn\'t find release in history. (Has it been over 30 days?)\n'
# 'Can\'t mark it as bad.')
# return json.dumps({'result': 'failure'})
# except exceptions.FailedHistoryMultiSnatchException:
# ui.notifications.error('Multi-Snatch Error', 'The same episode was snatched again before the first one was done.\n'
# 'Please cancel any downloads of this episode and then set it back to wanted.\n Can\'t continue.')
# return json.dumps({'result': 'failure'})
# except exceptions.FailedProcessingFailed:
# ui.notifications.error('Processing Failed', pp.log)
# return json.dumps({'result': 'failure'})
# except Exception as e:
# ui.notifications.error('Unknown Error', 'Unknown exception: ' + str(e))
# return json.dumps({'result': 'failure'})
#
# return json.dumps({'result': 'success'})
class UI:
@cherrypy.expose
def add_message(self):