# Author: Nic Wolfe # 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 . from collections import OrderedDict from sickbeard.common import Quality from unidecode import unidecode import datetime import os import re import sickbeard class SearchResult(object): """ 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 = [] # assign function to get the data for the download self.get_data_func = None # 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 # proper level self._properlevel = 0 # is a repack self.is_repack = False # provider unique id self.puid = None @property def properlevel(self): return self._properlevel @properlevel.setter def properlevel(self, v): if isinstance(v, (int, long)): self._properlevel = v def __str__(self): if self.provider is None: return 'Invalid provider, unable to print self' return '\n'.join([ '%s @ %s' % (self.provider.name, self.url), 'Extra Info:', '\n'.join([' %s' % x for x in self.extraInfo]), 'Episode: %s' % self.episodes, 'Quality: %s' % Quality.qualityStrings[self.quality], 'Name: %s' % self.name, 'Size: %s' % self.size, 'Release Group: %s' % self.release_group]) def get_data(self): if None is not self.get_data_func: try: return self.get_data_func(self.url) except (StandardError, Exception): pass if self.extraInfo and 0 < len(self.extraInfo): return self.extraInfo[0] return None 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 ShowFilter(object): def __init__(self, config, log=None): self.config = config self.log = log self.bad_names = [re.compile('(?i)%s' % r) for r in ( '[*]+\s*(?:403:|do not add|dupli[^s]+\s*(?:\d+|