class ZooqleProvider(TorrentProvider): def __init__(self): """Initialize the class.""" super(ZooqleProvider, self).__init__('Zooqle', 'https://zooqle.com', False) # URLs self.urls.update({ 'search': '{base_url}/search'.format(**self.urls), 'api': '{base_url}/api/media/%s'.format(**self.urls), }) # Proper Strings self.proper_strings = ['PROPER', 'REPACK', 'REAL'] # Miscellaneous Options # Torrent Stats self.minseed = None self.minleech = None # Cache self.cache = TVCache(self, min_time=15) def _get_season_search_strings(self, episode): search_string = {'Season': []} for show_name in set(show_names.allPossibleShowNames(episode.show)): for sep in ' ', ' - ': season_string = show_name + sep + 'Series ' if episode.show.air_by_date or episode.show.sports: season_string += str(episode.airdate).split('-')[0] elif episode.show.anime: season_string += '%d' % episode.scene_absolute_number else: season_string += '%d' % int(episode.scene_season) search_string['Season'].append( re.sub(r'\s+', ' ', season_string.replace('.', ' ').strip())) return [search_string] def _get_episode_search_strings(self, episode, add_string=''): search_string = {'Episode': []} if not episode: return [] for show_name in set(show_names.allPossibleShowNames(episode.show)): for sep in ' ', ' - ': ep_string = sanitizeSceneName(show_name) + sep if episode.show.air_by_date: ep_string += str(episode.airdate) elif episode.show.sports: ep_string += str( episode.airdate) + '|' + episode.airdate.strftime('%b') elif episode.show.anime: ep_string += '%i' % int(episode.scene_absolute_number) else: ep_string += sickrage.app.naming_ep_type[4] % { 'seasonnumber': episode.scene_season, 'episodenumber': episode.scene_episode } if add_string: ep_string += ' %s' % add_string search_string['Episode'].append( re.sub(r'\s+', ' ', ep_string.replace('.', ' ').strip())) return [search_string] def _get_torrent_info(self, torrent_hash): try: return self.session.get(self.urls['api'] % torrent_hash).json() except Exception: return {} def search(self, search_strings, age=0, ep_obj=None, **kwargs): """ Search a provider and parse the results. :param search_strings: A dict with mode (key) and the search value (value) :param age: Not used :param ep_obj: Not used :returns: A list of search results (structure) """ results = [] # Search Params search_params = { 'q': '* category:TV', 's': 'dt', 'v': 't', 'sd': 'd', } for mode in search_strings: sickrage.app.log.debug('Search mode: {}'.format(mode)) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.app.log.debug( 'Search string: {}'.format(search_string)) search_params['q'] = '{} category:TV'.format(search_string) search_params['fmt'] = 'rss' search_params['pg'] = 1 while search_params['pg'] < 11: data = self.cache.get_rss_feed(self.urls['search'], params=search_params) if not data or not data.get('feed'): sickrage.app.log.debug( 'No data returned from provider') break results += self.parse(data, mode) total_results = try_int( data['feed'].get('opensearch_totalresults')) start_index = try_int( data['feed'].get('opensearch_startindex')) items_per_page = try_int( data['feed'].get('opensearch_itemsperpage')) if not total_results or start_index + items_per_page > total_results: break search_params['pg'] += 1 return results def parse(self, data, mode): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] if not data.get('entries'): sickrage.app.log.debug( 'Data returned from provider does not contain any torrents') return results for item in data['entries']: try: title = item.get('title') download_url = item.get('torrent_magneturi') if not all([title, download_url]): continue seeders = try_int(item['torrent_seeds']) leechers = try_int(item['torrent_peers']) size = try_int(item['torrent_contentlength'], -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
class NyaaProvider(TorrentProvider): def __init__(self): super(NyaaProvider, self).__init__("NyaaTorrents", 'https://nyaa.si', False) self.supports_absolute_numbering = True self.anime_only = True self.confirmed = False self.minseed = None self.minleech = None self.cache = TVCache(self, min_time=20) def search(self, search_strings, age=0, ep_obj=None, **kwargs): """ Search a provider and parse the results. :param search_strings: A dict with mode (key) and the search value (value) :param age: Not used :param ep_obj: Not used :returns: A list of search results (structure) """ results = [] # Search Params search_params = { 'page': 'rss', 'c': '1_0', # All Anime 'f': 0, # No filter 'q': '', } for mode in search_strings: sickrage.app.log.debug('Search mode: {}'.format(mode)) if self.confirmed: search_params['f'] = 2 # Trusted only sickrage.app.log.debug('Searching only confirmed torrents') for search_string in search_strings[mode]: if mode != 'RSS': sickrage.app.log.debug( 'Search string: {}'.format(search_string)) search_params['q'] = search_string data = self.cache.get_rss_feed(self.urls['base_url'], params=search_params) if not data: sickrage.app.log.debug('No data returned from provider') continue if not data.get('entries'): sickrage.app.log.debug( 'Data returned from provider does not contain any {}torrents' .format('confirmed ' if self.confirmed else '')) continue results += self.parse(data['entries'], mode) return results def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] for item in data: try: title = item['title'] download_url = item['link'] if not all([title, download_url]): continue seeders = try_int(item['nyaa_seeders']) leechers = try_int(item['nyaa_leechers']) size = convert_size( item['nyaa_size'], -1, units=['B', 'KIB', 'MIB', 'GIB', 'TIB', 'PIB']) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
class ZooqleProvider(TorrentProvider): def __init__(self): """Initialize the class.""" super(ZooqleProvider, self).__init__('Zooqle', 'https://zooqle.com', False) # URLs self.urls.update({ 'search': '{base_url}/search'.format(**self.urls), 'api': '{base_url}/api/media/%s'.format(**self.urls), }) # Proper Strings self.proper_strings = ['PROPER', 'REPACK', 'REAL'] # Miscellaneous Options # Torrent Stats self.minseed = None self.minleech = None # Cache self.cache = TVCache(self, min_time=15) def _get_season_search_strings(self, episode): search_string = {'Season': []} for show_name in set(show_names.allPossibleShowNames(episode.show)): for sep in ' ', ' - ': season_string = show_name + sep + 'Series ' if episode.show.air_by_date or episode.show.sports: season_string += str(episode.airdate).split('-')[0] elif episode.show.anime: season_string += '%d' % episode.scene_absolute_number else: season_string += '%d' % int(episode.scene_season) search_string['Season'].append(re.sub(r'\s+', ' ', season_string.replace('.', ' ').strip())) return [search_string] def _get_episode_search_strings(self, episode, add_string=''): search_string = {'Episode': []} if not episode: return [] for show_name in set(show_names.allPossibleShowNames(episode.show)): for sep in ' ', ' - ': ep_string = sanitizeSceneName(show_name) + sep if episode.show.air_by_date: ep_string += str(episode.airdate) elif episode.show.sports: ep_string += str(episode.airdate) + '|' + episode.airdate.strftime('%b') elif episode.show.anime: ep_string += '%i' % int(episode.scene_absolute_number) else: ep_string += sickrage.app.naming_ep_type[4] % {'seasonnumber': episode.scene_season, 'episodenumber': episode.scene_episode} if add_string: ep_string += ' %s' % add_string search_string['Episode'].append(re.sub(r'\s+', ' ', ep_string.replace('.', ' ').strip())) return [search_string] def _get_torrent_info(self, torrent_hash): try: return self.session.get(self.urls['api'] % torrent_hash).json() except Exception: return {} def search(self, search_strings, age=0, ep_obj=None, **kwargs): """ Search a provider and parse the results. :param search_strings: A dict with mode (key) and the search value (value) :param age: Not used :param ep_obj: Not used :returns: A list of search results (structure) """ results = [] # Search Params search_params = { 'q': '* category:TV', 's': 'dt', 'v': 't', 'sd': 'd', } for mode in search_strings: sickrage.app.log.debug('Search mode: {}'.format(mode)) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.app.log.debug('Search string: {}'.format(search_string)) search_params['q'] = '{} category:TV'.format(search_string) search_params['fmt'] = 'rss' search_params['pg'] = 1 while search_params['pg'] < 11: data = self.cache.get_rss_feed(self.urls['search'], params=search_params) if not data or not data.get('feed'): sickrage.app.log.debug('No data returned from provider') break results += self.parse(data, mode) total_results = try_int(data['feed'].get('opensearch_totalresults')) start_index = try_int(data['feed'].get('opensearch_startindex')) items_per_page = try_int(data['feed'].get('opensearch_itemsperpage')) if not total_results or start_index + items_per_page > total_results: break search_params['pg'] += 1 return results def parse(self, data, mode): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] if not data.get('entries'): sickrage.app.log.debug('Data returned from provider does not contain any torrents') return results for item in data['entries']: try: title = item.get('title') download_url = item.get('torrent_magneturi') if not all([title, download_url]): continue seeders = try_int(item['torrent_seeds']) leechers = try_int(item['torrent_peers']) size = try_int(item['torrent_contentlength'], -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
class NyaaProvider(TorrentProvider): def __init__(self): super(NyaaProvider, self).__init__("NyaaTorrents", 'https://nyaa.si', False) self.supports_absolute_numbering = True self.anime_only = True self.confirmed = False self.minseed = None self.minleech = None self.cache = TVCache(self, min_time=20) def search(self, search_strings, age=0, ep_obj=None, **kwargs): """ Search a provider and parse the results. :param search_strings: A dict with mode (key) and the search value (value) :param age: Not used :param ep_obj: Not used :returns: A list of search results (structure) """ results = [] # Search Params search_params = { 'page': 'rss', 'c': '1_0', # All Anime 'f': 0, # No filter 'q': '', } for mode in search_strings: sickrage.app.log.debug('Search mode: {}'.format(mode)) if self.confirmed: search_params['f'] = 2 # Trusted only sickrage.app.log.debug('Searching only confirmed torrents') for search_string in search_strings[mode]: if mode != 'RSS': sickrage.app.log.debug('Search string: {}'.format(search_string)) search_params['q'] = search_string data = self.cache.get_rss_feed(self.urls['base_url'], params=search_params) if not data: sickrage.app.log.debug('No data returned from provider') continue if not data.get('entries'): sickrage.app.log.debug('Data returned from provider does not contain any {}torrents'.format( 'confirmed ' if self.confirmed else '')) continue results += self.parse(data['entries'], mode) return results def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] for item in data: try: title = item['title'] download_url = item['link'] if not all([title, download_url]): continue seeders = try_int(item['nyaa_seeders']) leechers = try_int(item['nyaa_leechers']) size = convert_size(item['nyaa_size'], -1, units=['B', 'KIB', 'MIB', 'GIB', 'TIB', 'PIB']) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
class ZooqleProvider(TorrentProvider): def __init__(self): """Initialize the class.""" super(ZooqleProvider, self).__init__('Zooqle', 'https://zooqle.com', False) # URLs self._urls.update({ 'search': '{base_url}/search'.format(**self._urls), 'api': '{base_url}/api/media/%s'.format(**self._urls), }) # Proper Strings self.proper_strings = ['PROPER', 'REPACK', 'REAL'] # Miscellaneous Options # Torrent Stats self.minseed = None self.minleech = None # Cache self.cache = TVCache(self, min_time=15) def _get_torrent_info(self, torrent_hash): try: return self.session.get(self.urls['api'] % torrent_hash).json() except Exception: return {} def search(self, search_strings, age=0, show_id=None, season=None, episode=None, **kwargs): """ Search a provider and parse the results. :param search_strings: A dict with mode (key) and the search value (value) :param age: Not used :param ep_obj: Not used :returns: A list of search results (structure) """ results = [] # Search Params search_params = { 'q': '* category:TV', 's': 'dt', 'v': 't', 'sd': 'd', } for mode in search_strings: sickrage.app.log.debug('Search mode: {}'.format(mode)) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.app.log.debug( 'Search string: {}'.format(search_string)) search_params['q'] = '{} category:TV'.format(search_string) search_params['fmt'] = 'rss' search_params['pg'] = 1 while search_params['pg'] < 11: data = self.cache.get_rss_feed(self.urls['search'], params=search_params) if not data or not data.get('feed'): sickrage.app.log.debug( 'No data returned from provider') break results += self.parse(data, mode) total_results = try_int( data['feed'].get('opensearch_totalresults')) start_index = try_int( data['feed'].get('opensearch_startindex')) items_per_page = try_int( data['feed'].get('opensearch_itemsperpage')) if not total_results or start_index + items_per_page > total_results: break search_params['pg'] += 1 return results def parse(self, data, mode): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] if not data.get('entries'): sickrage.app.log.debug( 'Data returned from provider does not contain any torrents') return results for item in data['entries']: try: title = item.get('title') download_url = item.get('torrent_magneturi') if not all([title, download_url]): continue seeders = try_int(item['torrent_seeds']) leechers = try_int(item['torrent_peers']) size = try_int(item['torrent_contentlength'], -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results