def torrent_status_browser(files): def _builder(): for count, item in enumerate(files, 1): try: display = '%02d | %s | [COLOR=grey][I]%s | %sGB | %s %% | %s: %s kB/s | (S:%s P:%s)[/I][/COLOR]' \ % (count, item['name'].replace('magnet:', '').upper(), item['dl_status'].upper(), str(round(float(item['size'])/1048576000, 1)), item['have'], ls(32775), str(round(float(item['speed'])/1024, 1)), item['seeders'], item['peers']) url_params = { 'mode': 'furk.remove_from_downloads', 'item_id': item['id'] } url = build_url(url_params) listitem = make_listitem() listitem.setLabel(display) listitem.setArt({ 'icon': default_furk_icon, 'poster': default_furk_icon, 'thumb': default_furk_icon, 'fanart': fanart, 'banner': default_furk_icon }) yield (url, listitem, True) except: pass kodi_utils.add_items(__handle__, list(_builder())) main_cache.set('furk_active_downloads', [i['info_hash'] for i in files], expiration=EXPIRES_1_HOUR)
def get_active_downloads(): cache = main_cache.get('furk_active_downloads') if cache != None: result = cache else: active_downloads = Furk.file_get_active() result = [i['info_hash'] for i in active_downloads] main_cache.set('furk_active_downloads', result, expiration=EXPIRES_1_HOUR) return result
def remove_from_search_history(params): try: result = main_cache.get(params['setting_id']) result.remove(params.get('query')) main_cache.set(params['setting_id'], result, expiration=EXPIRES_365_DAYS) kodi_utils.notification(32576, 3500) kodi_utils.execute_builtin('Container.Refresh') except: return
def add_to_search_history(search_name, search_list): try: result = [] cache = main_cache.get(search_list) if cache: result = cache if search_name in result: result.remove(search_name) result.insert(0, search_name) result = result[:10] main_cache.set(search_list, result, expiration=EXPIRES_365_DAYS) except: return
def remove_from_downloads(item_id): if not kodi_utils.confirm_dialog(): return response = Furk.download_unlink(item_id) if Furk.check_status(response): main_cache.set('furk_active_downloads', None, expiration=EXPIRES_1_HOUR) kodi_utils.notification(32576, 3500) else: kodi_utils.notification(32574, 3500) return (None, None)
def add_uncached_file(item_id): if not kodi_utils.confirm_dialog(): return try: response = Furk.add_uncached(item_id) if Furk.check_status(response): main_cache.set('furk_active_downloads', None, expiration=EXPIRES_1_HOUR) return kodi_utils.ok_dialog(text=32576, top_space=True) elif response['status'] == 'error': return kodi_utils.ok_dialog(text=32574, top_space=True) except: return
def set_history(db_type, name, query): from caches.main_cache import main_cache from datetime import timedelta string = 'fen_discover_%s_%s' % (db_type, query) cache = main_cache.get(string) if cache: return if db_type == 'movie': mode = 'build_movie_list' action = 'tmdb_movies_discover' else: mode = 'build_tvshow_list' action = 'tmdb_tv_discover' data = {'mode': mode, 'action': action, 'name': name, 'query': query} main_cache.set(string, data, expiration=timedelta(days=7)) return
def search(self, query, imdb_id, language, season=None, episode=None): cache_name = 'opensubtitles_%s_%s' % (imdb_id, language) if season: cache_name += '_%s_%s' % (season, episode) cache = main_cache.get(cache_name) if cache: response = cache else: url = '/imdbid-%s/query-%s' % (imdb_id, quote(query)) if season: url += '/season-%d/episode-%d' % (season, episode) url += '/sublanguageid-%s' % language url = base_url + url response = self._get(url, retry=True) response = to_utf8(json.loads(response.text)) main_cache.set(cache_name, response, expiration=timedelta(hours=24)) return response
def clear_search_history(): delete_str, search_str, hist_str, vid_str, mov_str, key_str = ls( 32785), ls(32450), ls(32486), ls(32491), ls(32028), ls(32092) tv_str, aud_str, furk_str, easy_str, peop_str, imdb_str = ls(32029), ls( 32492), ls(32069), ls(32070), ls(32507), ls(32064) choice_list = [ ('%s %s %s %s' % (delete_str, mov_str, search_str, hist_str), 'movie_queries'), ('%s %s %s %s' % (delete_str, tv_str, search_str, hist_str), 'tvshow_queries'), ('%s %s %s %s' % (delete_str, peop_str, search_str, hist_str), 'people_queries'), ('%s %s %s %s %s' % (delete_str, imdb_str, key_str, mov_str, hist_str), 'imdb_keyword_movie_queries'), ('%s %s %s %s %s' % (delete_str, imdb_str, key_str, tv_str, hist_str), 'imdb_keyword_tvshow_queries'), ('%s %s %s %s %s' % (delete_str, furk_str, vid_str, search_str, hist_str), 'furk_video_queries'), ('%s %s %s %s %s' % (delete_str, furk_str, aud_str, search_str, hist_str), 'furk_audio_queries'), ('%s %s %s %s' % (delete_str, easy_str, search_str, hist_str), 'easynews_video_queries') ] try: list_items = [{'line1': item[0], 'icon': icon} for item in choice_list] kwargs = { 'items': json.dumps(list_items), 'heading': 'Fen', 'enumerate': 'false', 'multi_choice': 'false', 'multi_line': 'false' } setting = kodi_utils.select_dialog([item[1] for item in choice_list], **kwargs) if setting == None: return main_cache.set(setting, '', expiration=EXPIRES_365_DAYS) kodi_utils.notification(32576, 3500) except: return
def link_folders(service, folder_name, action): import json from caches.main_cache import main_cache def _get_media_type(): media_type_list = [('movie', ls(32028), 'movies.png'), ('tvshow', ls(32029), 'tv.png')] list_items = [{ 'line1': item[1], 'line2': ls(32693) % item[1], 'icon': os.path.join(theme_folder, item[2]) } for item in media_type_list] kwargs = { 'items': json.dumps(list_items), 'heading': 'Fen', 'enumerate': 'false', 'multi_choice': 'false', 'multi_line': 'true' } chosen_media_type = kodi_utils.select_dialog( [i[0] for i in media_type_list], **kwargs) return chosen_media_type theme_folder = kodi_utils.translate_path( 'special://home/addons/script.tikiart/resources/media') string = 'FEN_%s_%s' % (service, folder_name) current_link = main_cache.get(string) if action == 'remove': if not current_link: return if not kodi_utils.confirm_dialog(text=ls(32694) % current_link, top_space=True): return import sqlite3 as database cache_file = kodi_utils.translate_path( 'special://profile/addon_data/plugin.video.fen/maincache.db') dbcon = database.connect(cache_file) dbcur = dbcon.cursor() dbcur.execute("DELETE FROM maincache WHERE id=?", (string, )) dbcon.commit() dbcon.close() kodi_utils.clear_property(string) if service == 'FOLDER': clear_cache('folders', silent=True) kodi_utils.execute_builtin('Container.Refresh') return kodi_utils.ok_dialog(text=32576, top_space=True) if current_link: if not kodi_utils.confirm_dialog(text='%s[CR][B]%s[/B][CR]%s' % (ls(32695), current_link, ls(32696))): return media_type = _get_media_type() if media_type == None: return title = kodi_utils.dialog.input(ls(32228)).lower() if not title: return from apis.tmdb_api import tmdb_movies_title_year, tmdb_tv_title_year year = kodi_utils.dialog.input('%s (%s)' % (ls(32543), ls(32669)), type=kodi_utils.numeric_input) function = tmdb_movies_title_year if media_type == 'movie' else tmdb_tv_title_year results = function(title, year)['results'] if len(results) == 0: return kodi_utils.ok_dialog(text=32490, top_space=True) name_key = 'title' if media_type == 'movie' else 'name' released_key = 'release_date' if media_type == 'movie' else 'first_air_date' function_list = [] function_list_append = function_list.append def _builder(): for item in results: title = item[name_key] try: year = item[released_key].split('-')[0] except: year = '' if year: rootname = '%s (%s)' % (title, year) else: rootname = title icon = 'https://image.tmdb.org/t/p/w780%s' % item['poster_path'] if item.get('poster_path') \ else kodi_utils.translate_path('special://home/addons/plugin.video.fen/icon.png') function_list_append(rootname) yield {'line1': rootname, 'line2': item['overview'], 'icon': icon} list_items = list(_builder()) kwargs = { 'items': json.dumps(list_items), 'heading': 'Fen', 'enumerate': 'false', 'multi_choice': 'false', 'multi_line': 'true' } rootname = kodi_utils.select_dialog(function_list, **kwargs) if rootname == None: return from datetime import timedelta main_cache.set(string, rootname, expiration=timedelta(days=365)) if service == 'FOLDER': clear_cache('folders', silent=True) kodi_utils.execute_builtin('Container.Refresh') return kodi_utils.ok_dialog(text=32576, top_space=True)