def toggle_language_invoker(): import xml.etree.ElementTree as ET from modules.utils import gen_file_hash kodi_utils.close_all_dialog() kodi_utils.sleep(100) addon_dir = kodi_utils.translate_path( 'special://home/addons/plugin.video.fen') addon_xml = os.path.join(addon_dir, 'addon.xml') tree = ET.parse(addon_xml) root = tree.getroot() try: current_value = [ str(i.text) for i in root.iter('reuselanguageinvoker') ][0] except: return current_setting = get_setting('reuse_language_invoker') new_value = 'false' if current_value == 'true' else 'true' if not kodi_utils.confirm_dialog( text=ls(33018) % (current_value.upper(), new_value.upper())): return if new_value == 'true': if not kodi_utils.confirm_dialog(text=33019, top_space=True): return for item in root.iter('reuselanguageinvoker'): item.text = new_value hash_start = gen_file_hash(addon_xml) tree.write(addon_xml) hash_end = gen_file_hash(addon_xml) if hash_start != hash_end: set_setting('reuse_language_invoker', new_value) else: return kodi_utils.ok_dialog(text=32574, top_space=True) kodi_utils.ok_dialog(text=33020, top_space=True) kodi_utils.execute_builtin('LoadProfile(%s)' % kodi_utils.get_infolabel('system.profilename'))
def set_quality_choice(quality_setting): include = ls(32188) dl = [ '%s SD' % include, '%s 720p' % include, '%s 1080p' % include, '%s 4K' % include ] fl = ['SD', '720p', '1080p', '4K'] try: preselect = [ fl.index(i) for i in get_setting(quality_setting).split(', ') ] except: preselect = [] list_items = [{'line1': item} for item in dl] kwargs = { 'items': json.dumps(list_items), 'heading': 'Fen', 'enumerate': 'false', 'multi_choice': 'true', 'multi_line': 'false', 'preselect': preselect } choice = kodi_utils.select_dialog(fl, **kwargs) if choice is None: return if choice == []: kodi_utils.ok_dialog(text=32574, top_space=True) return set_quality_choice(quality_setting) set_setting(quality_setting, ', '.join(choice))
def run(self): logger('FEN', 'ReuseLanguageInvokerCheck Service Starting') addon_xml = translate_path( 'special://home/addons/plugin.video.fen/addon.xml') tree = ET.parse(addon_xml) root = tree.getroot() current_addon_setting = get_setting('reuse_language_invoker', 'true') try: current_xml_setting = [ str(i.text) for i in root.iter('reuselanguageinvoker') ][0] except: return logger('FEN', 'ReuseLanguageInvokerCheck Service Finished') if current_xml_setting == current_addon_setting: return logger('FEN', 'ReuseLanguageInvokerCheck Service Finished') for item in root.iter('reuselanguageinvoker'): item.text = current_addon_setting hash_start = gen_file_hash(addon_xml) tree.write(addon_xml) hash_end = gen_file_hash(addon_xml) logger('FEN', 'ReuseLanguageInvokerCheck Service Finished') if hash_start != hash_end: if not kodi_utils.confirm_dialog(text='%s\n%s' % (ls(33021), ls(33020))): return current_profile = kodi_utils.get_infolabel( 'system.profilename') kodi_utils.execute_builtin('LoadProfile(%s)' % current_profile) else: kodi_utils.ok_dialog(text=32574, top_space=True)
def search_furk(params): from modules.history import add_to_search_history __handle__ = int(argv[1]) search_title = clean_file_name(params.get('query')) if ( 'query' in params and params.get('query') != 'NA') else None if not search_title: search_title = kodi_utils.dialog.input('Fen') try: search_name = clean_file_name(unquote(search_title)) search_method = 'search' if 'accurate_search' in params else 'direct_search' search_setting = 'furk_video_queries' if params.get( 'db_type') == 'video' else 'furk_audio_queries' list_type = 'video' if params.get('db_type') == 'video' else 'audio' add_to_search_history(search_name, search_setting) files = Furk.direct_search( search_name) if search_method == 'direct_search' else Furk.search( search_name) if not files: return kodi_utils.ok_dialog(text=32760, top_space=True) try: files = [ i for i in files if i.get('is_ready', '0') == '1' and i['type'] == list_type ] except: return kodi_utils.ok_dialog(text=32760, top_space=True) furk_file_browser(files, params, 'search', __handle__) except: pass kodi_utils.set_content(__handle__, 'files') kodi_utils.end_directory(__handle__) kodi_utils.set_view_mode('view.premium')
def revoke_auth(self): set_setting('rd.auth', '') set_setting('rd.client_id', '') set_setting('rd.refresh', '') set_setting('rd.secret', '') set_setting('rd.token', '') set_setting('rd.username', '') ok_dialog(heading=32054, text='%s %s' % (ls(32059), ls(32576)))
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 _return_failed(message=32574, cancelled=False): try: progressDialog.close() except Exception: pass hide_busy_dialog() sleep(500) if cancelled: if confirm_dialog(text=32044, top_space=True): ok_dialog(heading=32733, text=ls(32732) % ls(32054)) else: self.delete_torrent(torrent_id) else: ok_dialog(heading=32733, text=message) return False
def account_info(params): from datetime import datetime from modules.utils import jsondate_to_datetime try: account_info, usage_info = EasyNews.account() if not account_info or not usage_info: return kodi_utils.ok_dialog(text=32574, top_space=True) body = [] append = body.append expires = jsondate_to_datetime(to_utf8(account_info[2]), '%Y-%m-%d') days_remaining = (expires - datetime.today()).days append(ls(32758) % to_utf8(account_info[1])) append(ls(32755) % to_utf8(account_info[0])) append(ls(32757) % to_utf8(account_info[3])) append(ls(32750) % expires) append(ls(32751) % days_remaining) append('%s %s' % (ls(32772), to_utf8(usage_info[2]).replace('years', ls(32472)))) append(ls(32761) % to_utf8(usage_info[0]).replace('Gigs', 'GB')) append(ls(32762) % to_utf8(usage_info[1]).replace('Gigs', 'GB')) return kodi_utils.show_text(ls(32070).upper(), '\n\n'.join(body), font_size='large') except: pass
def auth_loop(self): sleep(1000 * self.auth_step) url = 'client_id=%s&code=%s' % (self.client_ID, self.device_code) url = auth_url + credentials_url % url response = json.loads(requests.get(url, timeout=self.timeout).text) if 'error' in response: return try: progressDialog.close() set_setting('rd.client_id', response['client_id']) set_setting('rd.secret', response['client_secret']) self.secret = response['client_secret'] self.client_ID = response['client_id'] except: ok_dialog(text=ls(32574), top_space=True) self.break_auth_loop = True return
def _return_failed(message=32574, cancelled=False): try: kodi_utils.progressDialog.close() except Exception: pass kodi_utils.hide_busy_dialog() kodi_utils.sleep(500) if cancelled: if kodi_utils.confirm_dialog(text=32044, top_space=True): kodi_utils.ok_dialog(heading=32733, text=ls(32732) % ls(32063), top_space=True) else: self.delete_transfer(transfer_id) else: kodi_utils.ok_dialog(heading=2733, text=message) return False
def auth_loop(self): kodi_utils.sleep(5000) response = requests.get(self.check_url, timeout=self.timeout).json() response = response['data'] if 'error' in response: self.token = 'failed' return kodi_utils.ok_dialog(text=32574, top_space=True) if response['activated']: try: kodi_utils.progressDialog.close() self.token = str(response['apikey']) set_setting('ad.token', self.token) except: self.token = 'failed' self.break_auth_loop = True return kodi_utils.ok_dialog(text=32574, top_space=True) return
def pm_delete(file_type, file_id): if not kodi_utils.confirm_dialog(): return result = Premiumize.delete_object(file_type, file_id) if result == 'success': Premiumize.clear_cache() kodi_utils.execute_builtin('Container.Refresh') else: return kodi_utils.ok_dialog(text=32574, top_space=True)
def auth(self): self.token = '' line = '%s[CR]%s[CR]%s' data = {'response_type': 'device_code', 'client_id': self.client_id} url = 'https://www.premiumize.me/token' response = self._post(url, data) progressDialog.create('Fen', '') progressDialog.update( -1, line % (ls(32517), ls(32700) % response.get('verification_uri'), ls(32701) % response.get('user_code'))) self.device_code = response['device_code'] while self.token == '': self.auth_loop() if self.token is None: return account_info = self.account_info() set_setting('pm.account_id', str(account_info['customer_id'])) ok_dialog(text=32576, top_space=True)
def done(self, title, db_type, downloaded, image): if self.db_type == 'thumb_url': return if self.db_type == 'image_url': if downloaded: kodi_utils.notification('[I]%s[/I]' % ls(32576), 2500, image) else: kodi_utils.notification('[I]%s[/I]' % ls(32691), 2500, image) else: playing = kodi_utils.player.isPlaying() if downloaded: text = '[B]%s[/B] : %s' % (title, '[COLOR forestgreen]%s %s[/COLOR]' % (ls(32107), ls(32576))) else: text = '[B]%s[/B] : %s' % (title, '[COLOR red]%s %s[/COLOR]' % (ls(32107), ls(32490))) if not downloaded or not playing: kodi_utils.ok_dialog(text=text)
def pm_rename(file_type, file_id, current_name): new_name = kodi_utils.dialog.input('Fen', defaultt=current_name) if not new_name: return result = Premiumize.rename_cache_item(file_type, file_id, new_name) if result == 'success': Premiumize.clear_cache() kodi_utils.execute_builtin('Container.Refresh') else: return kodi_utils.ok_dialog(text=32574, top_space=True)
def get_token(self): if self.secret == '': return data = { 'client_id': self.client_ID, 'client_secret': self.secret, 'code': self.device_code, 'grant_type': 'http://oauth.net/grant_type/device/1.0' } url = '%stoken' % auth_url response = requests.post(url, data=data, timeout=self.timeout).text response = json.loads(response) self.token = response['access_token'] self.refresh = response['refresh_token'] username = self.account_info()['username'] set_setting('rd.token', self.token) set_setting('rd.auth', self.token) set_setting('rd.refresh', self.refresh) set_setting('rd.username', username) ok_dialog(text=32576, top_space=True)
def clear_all_cache(): if not kodi_utils.confirm_dialog(): return line = '[CR]%s....[CR]%s' kodi_utils.progressDialog.create('Fen', '') caches = (('meta', '%s %s' % (ls(32527), ls(32524))), ('internal_scrapers', '%s %s' % (ls(32096), ls(32524))), ('external_scrapers', '%s %s' % (ls(32118), ls(32524))), ('trakt', ls(32087)), ('imdb', '%s %s' % (ls(32064), ls(32524))), ('list', '%s %s' % (ls(32815), ls(32524))), ('pm_cloud', '%s %s' % (ls(32061), ls(32524))), ('rd_cloud', '%s %s' % (ls(32054), ls(32524))), ('ad_cloud', '%s %s' % (ls(32063), ls(32524)))) for count, cache_type in enumerate(caches, 1): kodi_utils.progressDialog.update( int(float(count) / float(len(caches)) * 100), line % (ls(32816), cache_type[1])) clear_cache(cache_type[0], silent=True) kodi_utils.sleep(400) kodi_utils.progressDialog.close() kodi_utils.sleep(250) kodi_utils.ok_dialog(text=32576, top_space=True)
def auth_loop(self): if progressDialog.iscanceled(): progressDialog.close() return sleep(5000) url = 'https://www.premiumize.me/token' data = { 'grant_type': 'device_code', 'client_id': self.client_id, 'code': self.device_code } response = self._post(url, data) if 'error' in response: return try: progressDialog.close() self.token = str(response['access_token']) set_setting('pm.token', self.token) except: ok_dialog(text=32574, top_space=True) return
def auth(self): self.token = '' url = base_url + 'pin/get?agent=%s' % user_agent response = requests.get(url, timeout=self.timeout).json() response = response['data'] line = '%s[CR]%s[CR]%s' kodi_utils.progressDialog.create('Fen', '') kodi_utils.progressDialog.update( -1, line % (ls(32517), ls(32700) % response.get('base_url'), ls(32701) % response.get('pin'))) self.check_url = response.get('check_url') kodi_utils.sleep(2000) while not self.token: if self.break_auth_loop: break if kodi_utils.progressDialog.iscanceled(): kodi_utils.progressDialog.close() break self.auth_loop() if self.token in (None, '', 'failed'): return kodi_utils.sleep(2000) account_info = self._get('user') set_setting('ad.account_id', str(account_info['user']['username'])) kodi_utils.ok_dialog(text=32576, top_space=True)
def search_easynews(params): from modules.history import add_to_search_history __handle__ = int(argv[1]) search_title = clean_file_name(params.get('query')) if ( 'query' in params and params.get('query') != 'NA') else None if not search_title: search_title = kodi_utils.dialog.input('Enter search Term') try: if search_title: search_name = clean_file_name(unquote(search_title)) add_to_search_history(search_name, 'easynews_video_queries') files = EasyNews.search(search_name) if not files: return kodi_utils.ok_dialog(text=32760, top_space=True) easynews_file_browser(files, __handle__) except: pass kodi_utils.set_content(__handle__, 'files') kodi_utils.end_directory(__handle__) kodi_utils.set_view_mode('view.premium')
def add_uncached_torrent(self, magnet_url, pack=False): from modules.kodi_utils import show_busy_dialog, hide_busy_dialog from modules.source_utils import supported_video_extensions def _return_failed(message=32574, cancelled=False): try: progressDialog.close() except Exception: pass hide_busy_dialog() sleep(500) if cancelled: if confirm_dialog(text=32044, top_space=True): ok_dialog(heading=32733, text=ls(32732) % ls(32054)) else: self.delete_torrent(torrent_id) else: ok_dialog(heading=32733, text=message) return False show_busy_dialog() try: active_count = self.torrents_activeCount() if active_count['nb'] >= active_count['limit']: return _return_failed() except: pass interval = 5 stalled = ('magnet_error', 'error', 'virus', 'dead') extensions = supported_video_extensions() torrent = self.add_magnet(magnet_url) torrent_id = torrent['id'] if not torrent_id: return _return_failed() torrent_info = self.torrent_info(torrent_id) if 'error_code' in torrent_info: return _return_failed() status = torrent_info['status'] line = '%s[CR]%s[CR]%s' if status == 'magnet_conversion': line1 = ls(32737) line2 = torrent_info['filename'] line3 = ls(32738) % torrent_info['seeders'] timeout = 100 progressDialog.create(ls(32733), line % (line1, line2, line3)) while status == 'magnet_conversion' and timeout > 0: progressDialog.update(timeout, line % (line1, line2, line3)) if monitor.abortRequested() == True: return sysexit() try: if progressDialog.iscanceled(): return _return_failed(32736, cancelled=True) except Exception: pass timeout -= interval sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if any(x in status for x in stalled): return _return_failed() line3 = ls(32738) % torrent_info['seeders'] try: progressDialog.close() except Exception: pass if status == 'downloaded': hide_busy_dialog() return True if status == 'magnet_conversion': return _return_failed() if any(x in status for x in stalled): return _return_failed(str(status)) if status == 'waiting_files_selection': video_files = [] append = video_files.append all_files = torrent_info['files'] for item in all_files: if any(item['path'].lower().endswith(x) for x in extensions): append(item) if pack: try: if len(video_files) == 0: return _return_failed() video_files.sort(key=lambda x: x['path']) torrent_keys = [str(i['id']) for i in video_files] if not torrent_keys: return _return_failed(ls(32736)) torrent_keys = ','.join(torrent_keys) self.add_torrent_select(torrent_id, torrent_keys) ok_dialog(text=ls(32732) % ls(32054)) self.clear_cache() hide_busy_dialog() return True except Exception: return _return_failed() else: try: video = max(video_files, key=lambda x: x['bytes']) file_id = video['id'] except ValueError: return _return_failed() self.add_torrent_select(torrent_id, str(file_id)) sleep(2000) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloaded': hide_busy_dialog() return True file_size = round(float(video['bytes']) / (1000**3), 2) line1 = '%s...' % (ls(32732) % ls(32054)) line2 = torrent_info['filename'] line3 = status progressDialog.create(ls(32733), line % (line1, line2, line3)) while not status == 'downloaded': sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloading': line3 = ls(32739) % ( file_size, round(float(torrent_info['speed']) / (1000**2), 2), torrent_info['seeders'], torrent_info['progress']) else: line3 = status progressDialog.update(int(float(torrent_info['progress'])), line % (line1, line2, line3)) if monitor.abortRequested() == True: return sys.exit() try: if progressDialog.iscanceled(): return _return_failed(32736, cancelled=True) except: pass if any(x in status for x in stalled): return _return_failed() try: progressDialog.close() except: pass hide_busy_dialog() return True hide_busy_dialog() return False
def doDownload(self, url, dest): headers = self.headers file = dest.rsplit(os.sep, 1)[-1] resp = self.getResponse(url, headers, 0) if not resp: kodi_utils.hide_busy_dialog() kodi_utils.ok_dialog(text=32490, top_space=True) return try: content = int(resp.headers['Content-Length']) except: content = 0 try: resumable = 'bytes' in resp.headers['Accept-Ranges'].lower() except: resumable = False if content < 1: kodi_utils.hide_busy_dialog() kodi_utils.ok_dialog(text=32490, top_space=True) return size = 1024 * 1024 mb = content / (1024 * 1024) if content < size: size = content kodi_utils.hide_busy_dialog() if not self.confirmDownload(mb): return if self.action not in ('image', 'meta.pack'): show_notifications = True notification_frequency = 25 else: if self.action == 'meta.pack': kodi_utils.notification(32134, 3500, self.image) show_notifications = False notification_frequency = 0 notify, total, errors, count, resume, sleep_time = 25, 0, 0, 0, 0, 0 f = kodi_utils.open_file(dest, 'w') chunk = None chunks = [] while True: downloaded = total for c in chunks: downloaded += len(c) percent = min(round(float(downloaded) * 100 / content), 100) playing = kodi_utils.player.isPlaying() if show_notifications: if percent >= notify: notify += notification_frequency try: line1 = '%s - [I]%s[/I]' % (str(percent) + '%', self.final_name) if not playing: kodi_utils.notification(line1, 3000, self.image) except: pass chunk = None error = False try: chunk = resp.read(size) if not chunk: if percent < 99: error = True else: while len(chunks) > 0: c = chunks.pop(0) f.write(c) del c f.close() try: progressDialog.close() except: pass return self.done(self.final_name, self.db_type, True, self.image) except Exception as e: error = True sleep_time = 10 errno = 0 if hasattr(e, 'errno'): errno = e.errno if errno == 10035: # 'A non-blocking socket operation could not be completed immediately' pass if errno == 10054: #'An existing connection was forcibly closed by the remote host' errors = 10 #force resume sleep_time = 30 if errno == 11001: # 'getaddrinfo failed' errors = 10 #force resume sleep_time = 30 if chunk: errors = 0 chunks.append(chunk) if len(chunks) > 5: c = chunks.pop(0) f.write(c) total += len(c) del c if error: errors += 1 count += 1 kodi_utils.sleep(sleep_time * 1000) if (resumable and errors > 0) or errors >= 10: if (not resumable and resume >= 50) or resume >= 500: try: progressDialog.close() except: pass return self.done(self.final_name, self.db_type, False, self.image) resume += 1 errors = 0 if resumable: chunks = [] resp = self.getResponse(url, headers, total) else: pass
def revoke_auth(self): set_setting('ad.account_id', '') set_setting('ad.token', '') kodi_utils.ok_dialog(heading=32063, text='%s %s' % (ls(32059), ls(32576)))
def filter_results(self): choices = [(filter_quality, 'quality'), (filter_provider, 'provider'), (filter_title, 'keyword_title'), (filter_extraInfo, 'extra_info')] list_items = [{'line1': item[0]} for item in choices] kwargs = { 'items': json.dumps(list_items), 'heading': filter_str, 'enumerate': 'false', 'multi_choice': 'false', 'multi_line': 'false' } choice = select_dialog([i[1] for i in choices], **kwargs) if choice == None: return if choice in ('quality', 'provider'): if choice == 'quality': choice_sorter = [ '4K', '1080P', '720P', 'SD', 'TELE', 'CAM', 'SCR' ] else: choice_sorter = [ 'FOLDERS', 'EASYNEWS', 'FURK', 'RD_CLOUD', 'PM_CLOUD', 'AD_CLOUD', 'REAL-DEBRID', 'PREMIUMIZE', 'ALLDEBRID' ] filter_property = 'tikiskins.%s' % choice duplicates = set() choices = [i.getProperty(filter_property) for i in self.item_list \ if not (i.getProperty(filter_property) in duplicates or duplicates.add(i.getProperty(filter_property))) and not i.getProperty(filter_property) == ''] choices.sort(key=choice_sorter.index) list_items = [{'line1': item} for item in choices] kwargs = { 'items': json.dumps(list_items), 'heading': filter_str, 'enumerate': 'false', 'multi_choice': 'true', 'multi_line': 'false' } choice = select_dialog(choices, **kwargs) if choice == None: return filtered_list = [ i for i in self.item_list if any(x in i.getProperty(filter_property) for x in choice) ] elif choice == 'keyword_title': keywords = dialog.input( 'Enter Keyword (Comma Separated for Multiple)') if not keywords: return keywords.replace(' ', '') keywords = keywords.split(',') choice = [upper(i) for i in keywords] filtered_list = [ i for i in self.item_list if all(x in i.getProperty('tikiskins.name') for x in choice) ] else: # extra_info choices = (('PACK', '[B]PACK[/B]'), ('HEVC (X265)', '[B]HEVC[/B]'), ('DOLBY VISION', '[B]D/VISION[/B]'), ('HIGH DYNAMIC RANGE (HDR)', '[B]HDR[/B]'), ('REMUX', 'REMUX'), ('BLURAY', 'BLURAY'), ('SDR', 'SDR'), ('3D', '3D'), ('DOLBY ATMOS', 'ATMOS'), ('DOLBY TRUEHD', 'TRUEHD'), ('DOLBY DIGITAL EX', 'DD-EX'), ('DOLBY DIGITAL PLUS', 'DD+'), ('DOLBY DIGITAL', 'DD'), ('DTS-HD MASTER AUDIO', 'DTS-HD MA'), ('DTS-X', 'DTS-X'), ('DTS-HD', 'DTS-HD'), ('DTS', 'DTS'), ('ADVANCED AUDIO CODING (AAC)', 'AAC'), ('MP3', 'MP3'), ('8 CHANNEL AUDIO', '8CH'), ('7 CHANNEL AUDIO', '7CH'), ('6 CHANNEL AUDIO', '6CH'), ('2 CHANNEL AUDIO', '2CH'), ('DVD SOURCE', 'DVD'), ('WEB SOURCE', 'WEB'), ('MULTIPLE LANGUAGES', 'MULTI-LANG'), ('SUBTITLES', 'SUBS')) list_items = [{'line1': item[0]} for item in choices] kwargs = { 'items': json.dumps(list_items), 'heading': filter_str, 'enumerate': 'false', 'multi_choice': 'true', 'multi_line': 'false' } choice = select_dialog(choices, **kwargs) if choice == None: return choice = [i[1] for i in choice] filtered_list = [ i for i in self.item_list if all( x in i.getProperty('tikiskins.extra_info') for x in choice) ] if not filtered_list: return ok_dialog(text=32760, top_space=True) self.filter_applied = True self.win.reset() self.win.addItems(filtered_list) self.setFocusId(self.window_id) self.setProperty('tikiskins.total_results', str(len(filtered_list)))
def add_uncached_torrent(self, magnet_url, pack=False): from modules.kodi_utils import show_busy_dialog, hide_busy_dialog from modules.source_utils import supported_video_extensions def _transfer_info(transfer_id): info = self.transfers_list() if 'status' in info and info['status'] == 'success': for item in info['transfers']: if item['id'] == transfer_id: return item return {} def _return_failed(message=32574, cancelled=False): try: progressDialog.close() except Exception: pass hide_busy_dialog() sleep(500) if cancelled: if confirm_dialog(heading=32733, text=32044, top_space=True): ok_dialog(heading=32733, text=ls(32732) % ls(32061)) else: self.delete_transfer(transfer_id) else: ok_dialog(heading=32733, text=message) return False show_busy_dialog() extensions = supported_video_extensions() transfer_id = self.create_transfer(magnet_url) if not transfer_id['status'] == 'success': return _return_failed(transfer_id.get('message')) transfer_id = transfer_id['id'] transfer_info = _transfer_info(transfer_id) if not transfer_info: return _return_failed() if pack: self.clear_cache() hide_busy_dialog() ok_dialog(text=ls(32732) % ls(32061)) return True interval = 5 line = '%s[CR]%s[CR]%s' line1 = '%s...' % (ls(32732) % ls(32061)) line2 = transfer_info['name'] line3 = transfer_info['message'] progressDialog.create(ls(32733), line % (line1, line2, line3)) while not transfer_info['status'] == 'seeding': sleep(1000 * interval) transfer_info = _transfer_info(transfer_id) line3 = transfer_info['message'] progressDialog.update(int(float(transfer_info['progress']) * 100), line % (line1, line2, line3)) if monitor.abortRequested() == True: return sysexit() try: if progressDialog.iscanceled(): return _return_failed(ls(32736), cancelled=True) except Exception: pass if transfer_info.get('status') == 'stalled': return _return_failed() sleep(1000 * interval) try: progressDialog.close() except Exception: pass hide_busy_dialog() return True
def add_uncached_torrent(self, magnet_url, pack=False): def _return_failed(message=32574, cancelled=False): try: kodi_utils.progressDialog.close() except Exception: pass kodi_utils.hide_busy_dialog() kodi_utils.sleep(500) if cancelled: if kodi_utils.confirm_dialog(text=32044, top_space=True): kodi_utils.ok_dialog(heading=32733, text=ls(32732) % ls(32063), top_space=True) else: self.delete_transfer(transfer_id) else: kodi_utils.ok_dialog(heading=2733, text=message) return False kodi_utils.show_busy_dialog() transfer_id = self.create_transfer(magnet_url) if not transfer_id: return _return_failed() transfer_info = self.list_transfer(transfer_id) if not transfer_info: return _return_failed() if pack: self.clear_cache() kodi_utils.hide_busy_dialog() kodi_utils.ok_dialog(text=ls(32732) % ls(32063)) return True interval = 5 line = '%s[CR]%s[CR]%s' line1 = '%s...' % (ls(32732) % ls(32063)) line2 = transfer_info['filename'] line3 = transfer_info['status'] kodi_utils.progressDialog.create(ls(32733), line % (line1, line2, line3)) while not transfer_info['statusCode'] == 4: kodi_utils.sleep(1000 * interval) transfer_info = self.list_transfer(transfer_id) file_size = transfer_info['size'] line2 = transfer_info['filename'] if transfer_info['statusCode'] == 1: download_speed = round( float(transfer_info['downloadSpeed']) / (1000**2), 2) progress = int( float(transfer_info['downloaded']) / file_size * 100) if file_size > 0 else 0 line3 = ls(32734) % (download_speed, transfer_info['seeders'], progress, round(float(file_size) / (1000**3), 2)) elif transfer_info['statusCode'] == 3: upload_speed = round( float(transfer_info['uploadSpeed']) / (1000**2), 2) progress = int( float(transfer_info['uploaded']) / file_size * 100) if file_size > 0 else 0 line3 = ls(32735) % (upload_speed, progress, round(float(file_size) / (1000**3), 2)) else: line3 = transfer_info['status'] progress = 0 kodi_utils.progressDialog.update(progress, line % (line1, line2, line3)) if kodi_utils.monitor.abortRequested() == True: return sysexit() try: if kodi_utils.progressDialog.iscanceled(): return _return_failed(32736, cancelled=True) except Exception: pass if 5 <= transfer_info['statusCode'] <= 10: return _return_failed() kodi_utils.sleep(1000 * interval) try: kodi_utils.progressDialog.close() except Exception: pass kodi_utils.hide_busy_dialog() return True
def clean_settings(): import xml.etree.ElementTree as ET def _make_content(dict_object): content = '<settings version="2">' for item in dict_object: _id = item['id'] if _id in active_settings: if 'default' in item and 'value' in item: content += '\n <setting id="%s" default="%s">%s</setting>' % ( _id, item['default'], item['value']) elif 'default' in item: content += '\n <setting id="%s" default="%s"></setting>' % ( _id, item['default']) elif 'value' in item: content += '\n <setting id="%s">%s</setting>' % ( _id, item['value']) else: content += '\n <setting id="%s"></setting>' else: removed_append(item) content += '\n</settings>' return content kodi_utils.close_all_dialog() kodi_utils.sleep(200) kodi_utils.progressDialog.create(ls(32577), '') kodi_utils.progressDialog.update(0) addon_ids = [ 'plugin.video.fen', 'script.module.fenomscrapers', 'script.module.myaccounts' ] addon_names = [ kodi_utils.ext_addon(i).getAddonInfo('name') for i in addon_ids ] addon_dirs = [ kodi_utils.translate_path( kodi_utils.ext_addon(i).getAddonInfo('path')) for i in addon_ids ] profile_dirs = [ kodi_utils.translate_path( kodi_utils.ext_addon(i).getAddonInfo('profile')) for i in addon_ids ] active_settings_xmls = [ os.path.join( kodi_utils.translate_path( kodi_utils.ext_addon(i).getAddonInfo('path')), 'resources', 'settings.xml') for i in addon_ids ] params = list(zip(addon_names, profile_dirs, active_settings_xmls)) for addon in params: try: try: if kodi_utils.progressDialog.iscanceled(): break except: pass current_progress = params.index(addon) + 1 removed_settings = [] active_settings = [] current_user_settings = [] removed_append = removed_settings.append active_append = active_settings.append current_append = current_user_settings.append root = ET.parse(addon[2]).getroot() for item in root.findall('./category/setting'): setting_id = item.get('id') if setting_id: active_append(setting_id) settings_xml = os.path.join(addon[1], 'settings.xml') root = ET.parse(settings_xml).getroot() for item in root: dict_item = {} setting_id = item.get('id') setting_default = item.get('default') setting_value = item.text dict_item['id'] = setting_id if setting_value: dict_item['value'] = setting_value if setting_default: dict_item['default'] = setting_default current_append(dict_item) new_content = _make_content(current_user_settings) xml_file = kodi_utils.open_file(settings_xml, 'w') xml_file.write(new_content) xml_file.close() percent = int((current_progress / float(len(params))) * 100) line2 = ls(32812) % addon[0] line3 = ls(32813) % len(removed_settings) kodi_utils.progressDialog.update(percent, '[CR]%s[CR]%s' % (line2, line3)) except: kodi_utils.notification(32574, 2000) kodi_utils.sleep(800) try: kodi_utils.progressDialog.close() except: pass kodi_utils.ok_dialog(text=32576, top_space=True)
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 revoke_auth(self): set_setting('pm.account_id', '') set_setting('pm.token', '') ok_dialog(heading=32061, text='%s %s' % (ls(32059), ls(32576)))