def sort_sources(self, torrents=None, hosters=None, cloud=None): """Takes in multiple optional lists of sources and sorts them according to Seren's sort settings :param torrents: list of torrent sources :type torrents: list :param hosters: list of hoster sources :type hosters: list :param cloud: list of cloud sources :type cloud: list :return: sorted list of sources :rtype: list """ torrents = torrents if torrents else [] hosters = hosters if hosters else [] cloud = cloud if cloud else [] self.torrent_list = deepcopy(torrents) self.hoster_list = deepcopy(hosters) self.cloud_files = deepcopy(cloud) self._do_filters() if (len(self.torrent_list + self.hoster_list + self.cloud_files) == 0 and len(torrents + hosters + cloud) > 0): response = None if not g.get_bool_runtime_setting('tempSilent'): response = xbmcgui.Dialog().yesno(g.ADDON_NAME, g.get_language_string(30510)) if response or g.get_bool_runtime_setting('tempSilent'): self.torrent_list = deepcopy(torrents) self.hoster_list = deepcopy(hosters) self.cloud_files = deepcopy(cloud) return self._do_sorts()
def get_list_items(self): arguments = g.REQUEST_PARAMS['action_args'] media_type = g.REQUEST_PARAMS.get('media_type', arguments.get('type')) ignore_cache = True if g.REQUEST_PARAMS.get('from_widget') and g.REQUEST_PARAMS.get( 'from_widget').lower() == "true": widget_loaded_setting = "widget_loaded.{}.{}".format( media_type, arguments) if not g.get_bool_runtime_setting(widget_loaded_setting): ignore_cache = False g.set_runtime_setting(widget_loaded_setting, True) list_items = self.lists_database.get_list_content( arguments['username'], arguments['trakt_id'], self._backwards_compatibility(media_type), ignore_cache=ignore_cache, page=g.PAGE, no_paging=self.no_paging) if not list_items: g.log( 'Failed to pull list {} from Trakt/Database'.format( arguments['trakt_id']), 'error') g.cancel_directory() return if media_type in ['tvshow', 'shows']: self.builder.show_list_builder(list_items, no_paging=self.no_paging) elif media_type in ['movie', 'movies']: self.builder.movie_menu_builder(list_items, no_paging=self.no_paging)
def do_cleanup(self): if self._exit or g.abort_requested(): return if g.get_bool_runtime_setting(self._create_key("db.clean.busy")): return g.set_runtime_setting(self._create_key("db.clean.busy"), True) query = "DELETE FROM {} where expires < ?".format(self.cache_table_name) self.execute_sql(query, (self._get_timestamp(),)) g.clear_runtime_setting(self._create_key("db.clean.busy"))
def _decorated(*args, **kwargs): method_class = args[0] for a in args[1:]: if isinstance(a, types.GeneratorType): raise UnsupportedCacheParamException("generator") for k, v in kwargs.items(): if isinstance(v, types.GeneratorType): raise UnsupportedCacheParamException("generator") if func.__name__ == "get_sources": overwrite_cache = kwargs.get("overwrite_cache", False) kwargs_cache_value = { k: v for k, v in kwargs.items() if not k == "overwrite_cache" } else: overwrite_cache = kwargs.pop("overwrite_cache", False) kwargs_cache_value = kwargs hours = kwargs.pop("cache_hours", cache_hours) global_cache_ignore = g.get_bool_runtime_setting( "ignore.cache", False) ignore_cache = kwargs.pop("ignore_cache", False) if ignore_cache or global_cache_ignore: return func(*args, **kwargs) checksum = _get_checksum(method_class.__class__.__name__, func.__name__) cache_str = "{}.{}.{}.{}".format( method_class.__class__.__name__, func.__name__, tools.md5_hash(args[1:]), tools.md5_hash(kwargs_cache_value)) cached_data = g.CACHE.get( cache_str, checksum=checksum ) if not overwrite_cache else CacheBase.NOT_CACHED if cached_data == CacheBase.NOT_CACHED: fresh_result = func(*args, **kwargs) if func.__name__ == "get_sources" and (not fresh_result or len( fresh_result[1]) == 0): return fresh_result try: g.CACHE.set( cache_str, fresh_result, expiration=datetime.timedelta(hours=hours), checksum=checksum, ) except TypeError: g.log_stacktrace() pass return fresh_result else: return cached_data
def do_cleanup(self): busy_key = "torrentcache.db.clean.busy" if g.get_bool_runtime_setting(busy_key): return g.set_runtime_setting(busy_key, True) self.execute_sql([ "DELETE FROM {} where expires < ?".format(MOVIE_CACHE_TYPE), "DELETE FROM {} where expires < ?".format(TV_CACHE_TYPE) ], (time.time(), )) g.clear_runtime_setting(busy_key)
def do_cleanup(self): if self._exit or g.abort_requested(): return if g.get_bool_runtime_setting(self._create_key("clean.busy")): return g.set_runtime_setting(self._create_key("clean.busy"), True) self._db_cache.do_cleanup() self._mem_cache.do_cleanup() g.set_runtime_setting(self._create_key("clean.lastexecuted"), CacheBase._get_timestamp()) g.clear_runtime_setting(self._create_key("clean.busy"))
def __init__(self, item_information, scraper_sclass): self.trakt_id = 0 self.silent = g.get_bool_runtime_setting('tempSilent') try: self.display_style = g.get_int_setting('general.scrapedisplay') except ValueError: self.display_style = 0 self.item_information = item_information self.media_type = self.item_information['info']['mediatype'] self.background_dialog = None self.dialog = None self.scraper_class = scraper_sclass
def do_cleanup(self): if self._exit or g.abort_requested(): return cur_timestamp = self._get_timestamp() if g.get_bool_runtime_setting(self._create_key("mem.clean.busy")): return g.set_runtime_setting(self._create_key("mem.clean.busy"), True) self._get_index() for cache_id, expires in self._index: if expires < cur_timestamp: g.clear_runtime_setting(cache_id) g.clear_runtime_setting(self._create_key("mem.clean.busy"))
def sort_sources(self, sources_list): """Takes in a list of sources and filters and sorts them according to Seren's sort settings :param sources_list: list of sources :type sources_list: list :return: sorted list of sources :rtype: list """ filtered_sources = list(self.filter_sources(sources_list)) if ( len(filtered_sources) == 0 and len(sources_list) > 0 ): response = None if not g.get_bool_runtime_setting('tempSilent'): response = xbmcgui.Dialog().yesno( g.ADDON_NAME, g.get_language_string(30474) ) if response or g.get_bool_runtime_setting('tempSilent'): return self._sort_sources(sources_list) else: return [] return self._sort_sources(filtered_sources)
def resolve_silent_or_visible(self, sources, item_information, pack_select=False, overwrite_cache=False): """ Method to handle automatic background or foreground resolving :param sources: list of sources to handle :param item_information: information on item to play :param pack_select: True if you want to perform a manual file selection :param overwrite_cache: Set to true if you wish to overwrite the current cached return value :return: None if unsuccessful otherwise a playable object """ if g.get_bool_runtime_setting('tempSilent'): return Resolver().resolve_multiple_until_valid_link(sources, item_information, pack_select, True) else: window = ResolverWindow(*SkinManager().confirm_skin_path('resolver.xml'), item_information=item_information) results = window.doModal(sources, item_information, pack_select) del window return results
def resolve_silent_or_visible(self, sources, item_information, pack_select=False, from_source_select=False, overwrite_cache=False): """ Method to handle automatic background or foreground resolving :param sources: list of sources to handle :param item_information: information on item to play :param pack_select: True if you want to perform a manual file selection :param from_source_select: True if we were called from SS screen :param overwrite_cache: Set to true if you wish to overwrite the current cached return value :return: None if unsuccessful otherwise a playable object """ stream_link = "" release_title = "" if g.get_bool_runtime_setting('tempSilent'): stream_link, release_title = Resolver( ).resolve_multiple_until_valid_link(sources, item_information, pack_select, True) else: try: window = ResolverWindow( *SkinManager().confirm_skin_path('resolver.xml'), item_information=item_information) stream_link, release_title = window.doModal( sources, pack_select, from_source_select=from_source_select, ) finally: del window if item_information['info'][ 'mediatype'] == g.MEDIA_EPISODE and release_title: g.set_runtime_setting( "last_resolved_release_title.{}".format( item_information['info']['trakt_show_id']), release_title) return stream_link
def __init__(self, item_information): self.hash_regex = re.compile(r'btih:(.*?)(?:&|$)') self.canceled = False self.torrent_cache = TorrentCache() self.torrent_threads = ThreadPool() self.hoster_threads = ThreadPool() self.adaptive_threads = ThreadPool() self.item_information = item_information self.media_type = self.item_information['info']['mediatype'] self.torrent_providers = [] self.hoster_providers = [] self.adaptive_providers = [] self.running_providers = [] self.duration = 0 self.language = 'en' self.sources_information = { "adaptiveSources": [], "torrentCacheSources": {}, "hosterSources": {}, "cloudFiles": [], "remainingProviders": [], "allTorrents": {}, "torrents_quality": [0, 0, 0, 0], "hosters_quality": [0, 0, 0, 0], "cached_hashes": [] } self.hoster_domains = {} self.progress = 1 self.runtime = 0 self.host_domains = [] self.host_names = [] self.timeout = g.get_int_setting('general.timeout') self.window = SourceWindowAdapter(self.item_information, self) self.session = requests.Session() self.silent = g.get_bool_runtime_setting('tempSilent')
def _still_processing(self): return any( g.get_bool_runtime_setting(self._create_key(i)) for i in self._trakt_ids)
def _run(self): self._running_ids = [ self._run_id(i) for i in self._trakt_ids if not g.get_bool_runtime_setting(self._create_key(i)) ]
def _check_ran_once_already(self): if g.get_bool_runtime_setting(self._create_key("RunOnce")) and \ g.get_runtime_setting(self._create_key("CheckSum")) == self._check_sum: g.clear_runtime_setting(self._create_key("Running")) raise RanOnceAlready("Lock name: {}, Checksum: {}".format(self._lock_name, self._check_sum))
def _running(self): return g.get_bool_runtime_setting(self._create_key("Running"))