def _builder(): for count, item in enumerate(my_cloud_files, 1): try: cm = [] cm_append = cm.append folder_name = item['filename'] normalized_folder_name = normalize(folder_name) string = 'FEN_RD_%s' % normalized_folder_name link_folders_add = { 'mode': 'link_folders', 'service': 'RD', 'folder_name': normalized_folder_name, 'action': 'add' } link_folders_remove = { 'mode': 'link_folders', 'service': 'RD', 'folder_name': normalized_folder_name, 'action': 'remove' } current_link = main_cache.get(string) if current_link: ending = '[COLOR=limegreen][B][I]\n %s[/I][/B][/COLOR]' % ( linkedto_str % current_link) else: ending = '' display = '%02d | [B]%s[/B] | [I]%s [/I]%s' % ( count, folder_str, clean_file_name(normalized_folder_name).upper(), ending) url_params = { 'mode': 'real_debrid.browse_rd_cloud', 'id': item['id'] } delete_params = { 'mode': 'real_debrid.delete', 'id': item['id'], 'cache_type': 'torrent' } url = build_url(url_params) cm_append( ('[B]%s %s[/B]' % (delete_str, folder_str.capitalize()), 'RunPlugin(%s)' % build_url(delete_params))) cm_append((addlink_str, 'RunPlugin(%s)' % build_url(link_folders_add))) cm_append((clearlink_str, 'RunPlugin(%s)' % build_url(link_folders_remove))) listitem = make_listitem() listitem.setLabel(display) listitem.addContextMenuItems(cm) listitem.setArt({ 'icon': default_rd_icon, 'poster': default_rd_icon, 'thumb': default_rd_icon, 'fanart': fanart, 'banner': default_rd_icon }) yield (url, listitem, True) except: pass
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 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 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)
def _assigned_content(self, raw_name): try: string = 'FEN_AD_%s' % raw_name return main_cache.get(string) except: return False
def search_history(params): def _builder(): for h in history: try: cm = [] query = unquote(h) url_params = {'mode': 'get_search_term', 'db_type': 'movie', 'query': query} if action == 'movie' \ else {'mode': 'get_search_term', 'db_type': 'tv_show', 'query': query} if action == 'tvshow' \ else {'mode': 'people_search.search', 'actor_name': query} if action == 'people' \ else {'mode': 'furk.search_furk', 'db_type': 'video', 'query': query} if action == 'furk_video' \ else {'mode': 'furk.search_furk', 'db_type': 'audio', 'music': True, 'query': query} if action == 'furk_audio' \ else {'mode': 'easynews.search_easynews', 'query': query} if action == 'easynews_video' \ else {'mode': 'get_search_term', 'search_type': 'imdb_keyword', 'db_type': 'movie', 'query': query} if action == 'imdb_keyword_movie' \ else {'mode': 'get_search_term', 'search_type': 'imdb_keyword', 'db_type': 'tvshow', 'query': query} if action == 'imdb_keyword_tvshow' \ else '' isFolder = False if action in folder_actions else True display = '[B]%s %s : [/B]' % (display_title, sear_str) + query url = build_url(url_params) cm.append( (remove_str, 'RunPlugin(%s)' % build_url({ 'mode': 'remove_from_history', 'setting_id': search_setting, 'query': query }))) listitem = make_listitem() listitem.setLabel(display) listitem.setArt({ 'icon': icon, 'poster': icon, 'thumb': icon, 'fanart': fanart, 'banner': icon }) listitem.addContextMenuItems(cm) yield (url, listitem, isFolder) except: pass try: __handle__ = int(argv[1]) sear_str, mov_str, tv_str, peop_str = ls(32450).upper(), ls( 32028).upper(), ls(32029).upper(), ls(32507).upper() furkvid_str = '%s %s' % (ls(32069).upper(), ls(32491).upper()) furkaud_str = '%s %s' % (ls(32069).upper(), ls(32492).upper()) imdb_key_mov_str, imdb_key_tv_str = '%s %s %s' % ( ls(32064).upper(), ls(32092).upper(), mov_str), '%s %s %s' % ( ls(32064).upper(), ls(32092).upper(), tv_str) remove_str, easy_str = ls(32786), ls(32070).upper() action = params['action'] search_setting, display_title = { 'movie': ('movie_queries', mov_str), 'tvshow': ('tvshow_queries', tv_str), 'people': ('people_queries', peop_str), 'furk_video': ('furk_video_queries', furkvid_str), 'furk_audio': ('furk_audio_queries', furkaud_str), 'easynews_video': ('easynews_video_queries', easy_str), 'imdb_keyword_movie': ('imdb_keyword_movie_queries', imdb_key_mov_str), 'imdb_keyword_tvshow': ('imdb_keyword_tvshow_queries', imdb_key_tv_str) }[action] history = main_cache.get(search_setting) __handle__ = int(argv[1]) kodi_utils.add_items(__handle__, list(_builder())) except: pass kodi_utils.set_content(__handle__, '') kodi_utils.end_directory(__handle__) kodi_utils.set_view_mode('view.main', '')