mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
d3a7f0ff5e
Add newznab smart logic to avoid missing releases when there are a great many recent releases. Change improve performance by using newznab server advertised capabilities. Change config/providers newznab to display only non-default categories. Change use scene season for wanted segment in backlog if show is scene numbering. Change combine Manage Searches / Backlog Search / Limited and Full to Force. Change consolidate limited and full backlog. Change config / Search / Backlog search frequency to instead spread backlog searches over a number of days. Change migrate minimum used value for search frequency into new minimum 7 for search spread. Change restrict nzb providers to 1 backlog batch run per day. Add to Config/Search/Unaired episodes/Allow episodes that are released early. Add to Config/Search/Unaired episodes/Use specific api requests to search for early episode releases. Add use related ids for newznab searches to increase search efficiency. Add periodic update of related show ids. Change terminology Edit Show/"Post processing" tab name to "Other". Add advanced feature "Related show IDs" to Edit Show/Other used for finding episodes and TV info. Add search info source image links to those that have zero id under Edit Show/Other/"Related show IDs". Add "set master" button to Edit Show/Other/"Related show IDs" for info source that can be changed. Change terminology displayShow "Indexers" to "Links" to cover internal and web links. Change add related show info sources on displayShow page. Change don't display "temporarily" defunct TVRage image link on displayShow pages unless it is master info source. Change if a defunct info source is the master of a show then present a link on displayShow to edit related show IDs. Change simplify the next backlog search run time display in the page footer. Change try ssl when fetching data thetvdb, imdb, trakt, scene exception. Change improve reliability to Trakt notifier by using show related id support. Change improve config/providers newznab categories layout. Change show loaded log message at start up and include info source. Change if episode has no airdate then set status to unaired (was skipped). Technical Change move scene_exceptions table from cache.db to sickbeard.db. Add related ids to show obj. Add use of mapped indexer ids for newznab. Add indexer to sql in wanted_eps. Add aired in (scene) season for wanted episodes. Add need_anime, need_sports, need_sd, need_hd, need_uhd to wanted episodes and added as parameter to update_providers. Add fix for lib lockfile/mkdirlockfile. Add set master TV info source logic. Change harden ui input validation. Add per action dialog confirmation. Change to reload page under more events. Change implement "Mark all added episodes Wanted to search for releases" when setting new info source.
251 lines
No EOL
7.3 KiB
Python
251 lines
No EOL
7.3 KiB
Python
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
#
|
|
# This file is part of SickGear.
|
|
#
|
|
# SickGear is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# SickGear is distributed in the hope that it will be useful,
|
|
# 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 SickGear. If not, see <http://www.gnu.org/licenses/>.
|
|
import re
|
|
import datetime
|
|
|
|
import sickbeard
|
|
from lib.dateutil import parser
|
|
from sickbeard.common import Quality
|
|
|
|
try:
|
|
from collections import OrderedDict
|
|
except ImportError:
|
|
from requests.compat import OrderedDict
|
|
|
|
|
|
class SearchResult:
|
|
"""
|
|
Represents a search result from an indexer.
|
|
"""
|
|
|
|
def __init__(self, episodes):
|
|
self.provider = -1
|
|
|
|
# release show object
|
|
self.show = None
|
|
|
|
# URL to the NZB/torrent file
|
|
self.url = ''
|
|
|
|
# used by some providers to store extra info associated with the result
|
|
self.extraInfo = []
|
|
|
|
# list of TVEpisode objects that this result is associated with
|
|
self.episodes = episodes
|
|
|
|
# quality of the release
|
|
self.quality = Quality.UNKNOWN
|
|
|
|
# release name
|
|
self.name = ''
|
|
|
|
# size of the release (-1 = n/a)
|
|
self.size = -1
|
|
|
|
# release group
|
|
self.release_group = ''
|
|
|
|
# version
|
|
self.version = -1
|
|
|
|
def __str__(self):
|
|
|
|
if self.provider is None:
|
|
return 'Invalid provider, unable to print self'
|
|
|
|
myString = '%s @ %s\n' % (self.provider.name, self.url)
|
|
myString += 'Extra Info:\n'
|
|
for extra in self.extraInfo:
|
|
myString += ' %s\n' % extra
|
|
myString += 'Episode: %s\n' % self.episodes
|
|
myString += 'Quality: %s\n' % Quality.qualityStrings[self.quality]
|
|
myString += 'Name: %s\n' % self.name
|
|
myString += 'Size: %s\n' % str(self.size)
|
|
myString += 'Release Group: %s\n' % self.release_group
|
|
|
|
return myString
|
|
|
|
def fileName(self):
|
|
return self.episodes[0].prettyName() + '.' + self.resultType
|
|
|
|
|
|
class NZBSearchResult(SearchResult):
|
|
"""
|
|
Regular NZB result with an URL to the NZB
|
|
"""
|
|
resultType = 'nzb'
|
|
|
|
|
|
class NZBDataSearchResult(SearchResult):
|
|
"""
|
|
NZB result where the actual NZB XML data is stored in the extraInfo
|
|
"""
|
|
resultType = 'nzbdata'
|
|
|
|
|
|
class TorrentSearchResult(SearchResult):
|
|
"""
|
|
Torrent result with an URL to the torrent
|
|
"""
|
|
resultType = 'torrent'
|
|
|
|
# torrent hash
|
|
content = None
|
|
hash = None
|
|
|
|
|
|
class AllShowsListUI:
|
|
"""
|
|
This class is for indexer api. Instead of prompting with a UI to pick the
|
|
desired result out of a list of shows it tries to be smart about it
|
|
based on what shows are in SB.
|
|
"""
|
|
|
|
def __init__(self, config, log=None):
|
|
self.config = config
|
|
self.log = log
|
|
|
|
def selectSeries(self, allSeries):
|
|
searchResults = []
|
|
seriesnames = []
|
|
|
|
# get all available shows
|
|
if allSeries:
|
|
if 'searchterm' in self.config:
|
|
searchterm = self.config['searchterm']
|
|
# try to pick a show that's in my show list
|
|
for curShow in allSeries:
|
|
if curShow in searchResults:
|
|
continue
|
|
|
|
if 'seriesname' in curShow:
|
|
seriesnames.append(curShow['seriesname'])
|
|
if 'aliasnames' in curShow:
|
|
seriesnames.extend(curShow['aliasnames'].split('|'))
|
|
|
|
for name in seriesnames:
|
|
if searchterm.lower() in name.lower():
|
|
if 'firstaired' not in curShow:
|
|
curShow['firstaired'] = str(datetime.date.fromordinal(1))
|
|
curShow['firstaired'] = re.sub('([-]0{2}){1,}', '', curShow['firstaired'])
|
|
fixDate = parser.parse(curShow['firstaired'], fuzzy=True).date()
|
|
curShow['firstaired'] = fixDate.strftime('%Y-%m-%d')
|
|
|
|
if curShow not in searchResults:
|
|
searchResults += [curShow]
|
|
|
|
return searchResults
|
|
|
|
|
|
class ShowListUI:
|
|
"""
|
|
This class is for tvdb-api. Instead of prompting with a UI to pick the
|
|
desired result out of a list of shows it tries to be smart about it
|
|
based on what shows are in SB.
|
|
"""
|
|
|
|
def __init__(self, config, log=None):
|
|
self.config = config
|
|
self.log = log
|
|
|
|
def selectSeries(self, allSeries):
|
|
try:
|
|
# try to pick a show that's in my show list
|
|
for curShow in allSeries:
|
|
if filter(lambda x: int(x.indexerid) == int(curShow['id']), sickbeard.showList):
|
|
return curShow
|
|
except:
|
|
pass
|
|
|
|
# if nothing matches then return first result
|
|
return allSeries[0]
|
|
|
|
|
|
class Proper:
|
|
def __init__(self, name, url, date, show, parsed_show=None):
|
|
self.name = name
|
|
self.url = url
|
|
self.date = date
|
|
self.provider = None
|
|
self.quality = Quality.UNKNOWN
|
|
self.release_group = None
|
|
self.version = -1
|
|
|
|
self.parsed_show = parsed_show
|
|
self.show = show
|
|
self.indexer = None
|
|
self.indexerid = -1
|
|
self.season = -1
|
|
self.episode = -1
|
|
self.scene_season = -1
|
|
self.scene_episode = -1
|
|
|
|
def __str__(self):
|
|
return str(self.date) + ' ' + self.name + ' ' + str(self.season) + 'x' + str(self.episode) + ' of ' + str(
|
|
self.indexerid) + ' from ' + str(sickbeard.indexerApi(self.indexer).name)
|
|
|
|
|
|
class ErrorViewer():
|
|
"""
|
|
Keeps a static list of UIErrors to be displayed on the UI and allows
|
|
the list to be cleared.
|
|
"""
|
|
|
|
errors = []
|
|
|
|
def __init__(self):
|
|
ErrorViewer.errors = []
|
|
|
|
@staticmethod
|
|
def add(error):
|
|
ErrorViewer.errors.append(error)
|
|
|
|
@staticmethod
|
|
def clear():
|
|
ErrorViewer.errors = []
|
|
|
|
|
|
class UIError():
|
|
"""
|
|
Represents an error to be displayed in the web UI.
|
|
"""
|
|
|
|
def __init__(self, message):
|
|
self.message = message
|
|
self.time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
class OrderedDefaultdict(OrderedDict):
|
|
def __init__(self, *args, **kwargs):
|
|
if not args:
|
|
self.default_factory = None
|
|
else:
|
|
if not (args[0] is None or callable(args[0])):
|
|
raise TypeError('first argument must be callable or None')
|
|
self.default_factory = args[0]
|
|
args = args[1:]
|
|
super(OrderedDefaultdict, self).__init__(*args, **kwargs)
|
|
|
|
def __missing__ (self, key):
|
|
if self.default_factory is None:
|
|
raise KeyError(key)
|
|
self[key] = default = self.default_factory()
|
|
return default
|
|
|
|
def __reduce__(self): # optional, for pickle support
|
|
args = (self.default_factory,) if self.default_factory else ()
|
|
return self.__class__, args, None, None, self.iteritems() |