def on_authenticated(self, token): self.authorization = token set_setting('trakt.authorization', dumps(self.authorization)) debug('TRAKT Authentication complete: %r' % token) self.authDialog.close() dok('Trakt', 'Autorizacia uspesna') self.update_user()
def login(self): with Trakt.configuration.http(timeout=90): code = Trakt['oauth/device'].code() if not code: debug('TRAKT Error can not reach trakt') dok('ERROR', 'Trakt.tv error') else: # Construct device authentication poller poller = Trakt['oauth/device'].poll(**code) \ .on('aborted', self.on_aborted) \ .on('authenticated', self.on_authenticated) \ .on('expired', self.on_expired) \ .on('poll', self.on_poll) debug( 'TRAKT Enter the code "%s" at %s to authenticate your account' % (code.get('user_code'), code.get('verification_url'))) self.authDialog = dprogress() self.authDialog.create( 'Trakt', '{} -> {}'.format(code.get('verification_url'), code.get('user_code'))) self.authPollProgress = [ float(code.get('expires_in')), float(code.get('interval')), 0 ] # Start polling for authentication token poller.start(daemon=False)
def action_last(self): lid = get_history_item_name(self.args.get(SC.ITEM_ID)) st = List(lid) if len(st.get()) > 0: self.url = '/Last' self.payload = {"ids": dumps(st.get())} self.call_url_and_response() else: if SC.ITEM_WIDGET not in self.args: dok(Strings.txt(Strings.EMPTY_HISTORY_H1), Strings.txt(Strings.EMPTY_HISTORY_L1))
def intro(step=None, credentials_only=False): info('Step: {}'.format(step)) auto_close = 60 if step is None and get_setting('kraska.user') != '': info('Uz nieje treba intro....') return elif step is None: step = 1 if step == 1: start = dyesno(Strings.txt(Strings.INTRO_STEP1_H1), Strings.txt(Strings.INTRO_STEP1_L1), autoclose=auto_close) info('RET: [{}] [{}]'.format(start, 'Ano' if start else 'Nie')) return intro(step + 1, credentials_only) if start == 1 else 0 if step == 2: user = dinput(Strings.txt(Strings.INTRO_STEP2_H1), get_setting('kraska.user')) info(Strings.INTRO_STEP1_H1) info(Strings.txt(Strings.INTRO_STEP1_H1)) info('RET: {}'.format(user)) settings.set_setting('kraska.user', user) if user != settings.get_setting('kraska.user'): _remove_settings_file() debug('Zmazanie nastaveni') return 0 return intro(step + 1, credentials_only) if user != '' else 0 if step == 3: password = dinput(Strings.txt(Strings.INTRO_STEP3_H1), '') info('RET: {}'.format(password)) settings.set_setting('kraska.pass', password) if password != settings.get_setting('kraska.pass'): debug('skusam znova zapisat heslo...') settings.set_setting('kraska.pass', password) kr = Kraska(p=password) data = kr.user_info() return intro(step + 1, credentials_only) if data is False else intro(step + 2) if step == 4: dok(Strings.txt(Strings.INTRO_STEP4_H1), Strings.txt(Strings.INTRO_STEP4_L1)) return intro(step - 2, credentials_only) if step == 5 and credentials_only is False: res = dyesno(Strings.txt(Strings.INTRO_STEP5_H1), Strings.txt(Strings.INTRO_STEP5_L1)) if res: open_settings('1.0')
def check_set_debug(toggle=False): cur_system = get_system_debug() if toggle: cur_system = not cur_system set_system_debug(cur_system) from resources.lib.gui.dialog import dok from resources.lib.language import Strings if cur_system: dok(Strings.txt(Strings.SYSTEM_H1), Strings.txt(Strings.SYSTEM_DEBUG_ENABLED)) else: upload_log_file() dok(Strings.txt(Strings.SYSTEM_H1), Strings.txt(Strings.SYSTEM_DEBUG_DISABLED))
def play(self): try: item = SCItem(self.response) url, li, status, selected = item.get() if SC.ACTION in self.args and SC.ACTION_DOWNLOAD in self.args[ SC.ACTION]: filename = selected.get('stream_info', {}).get('filename') if filename is None: dok(Strings.txt(Strings.RESOLVE_ERROR_H1), Strings.txt(Strings.RESOLVE_ERROR_L1)) return from threading import Thread worker = Thread(target=download, args=(url, get_setting('download.path'), filename)) worker.start() return debug( '----------------------------------------------------------------------------------------------------' ) debug('play url: {}'.format(self.url)) debug('play selected: {}'.format(dumps(selected))) # debug('play response: {}'.format(dumps(self.response))) # debug('play item: {}'.format(li)) debug( '----------------------------------------------------------------------------------------------------' ) self.response['strms'] = selected home_win.setProperty('SC.play_item', dumps(self.response)) if params.handle == -1: debug('HANDLE -1') xbmc.Player().play(url, li) else: debug('HANDLE {}'.format(params.handle)) self.succeeded = True self.cache_to_disc = False xbmcplugin.setResolvedUrl(params.handle, True, li) self.end_of_directory() except: # dok('ERROR', 'Chyba pri prehravani') info("ERR: {}".format(str(traceback.format_exc()))) self.end_of_directory()
def set_kodi_cache_size(): free_mem = xbmc.getInfoLabel('System.FreeMemory') free_mem = int(free_mem) / 1e6 if 'MB' not in free_mem else int(free_mem.replace('MB', '')) msg = Strings.txt(Strings.SETUP_VIDEO_CACHE_MSG1) user_input = dinput(msg.format(free_mem), '80', type=INPUT_NUMERIC) debug('user input: {}'.format(user_input)) if user_input == '': return coefficient = int('{}'.format(user_input).replace('%', '')) coefficient = 80 if coefficient is None or 1 < coefficient > 80 else coefficient filename = translate_path('special://userdata/advancedsettings.xml') debug('cache size: {} * {}% / 3 = {}, '.format(free_mem, coefficient, int(free_mem / 3 * (coefficient/100)))) if xbmcvfs.exists(filename): res = dyesno('WARNING', Strings.txt(Strings.SETUP_VIDEO_CACHE_MSG2)) if not res: return False cache_size = int(min(500, int(free_mem / 3 * (coefficient/100))) * 1e6) debug('Nova cache {}'.format(cache_size)) advanced_settings = '<advancedsettings>' \ '<cache><memorysize>{}</memorysize>' \ '<buffermode>1</buffermode>' \ '<readfactor>20</readfactor></cache>' \ '</advancedsettings>'.format(cache_size) debug('Nove advanced settings: {}'.format(advanced_settings)) f = xbmcvfs.File(filename, 'w') f.write(advanced_settings) f.close() platform = get_system_platform() if platform in ['linux', 'windows']: res = dyesno('INFO', Strings.txt(Strings.SETUP_VIDEO_CACHE_MSG3)) if res: jsonrpc(method="RestartApp") else: dok('INFO', Strings.txt(Strings.SETUP_VIDEO_CACHE_MSG4)) pass
def msg_error(self): if SC.ITEM_WIDGET in self.args: debug('Mame error hlasku, ale sme z widgetu, tak ju nezobrazujeme') return if 'msgERROR' in self.response.get('system', {}): debug('ERR REPOSNSE: {}'.format(self.response)) data = self.response.get('system').get('msgERROR') if isinstance(data, dict): lang = SYSTEM_LANG_CODE i18n = data.get('i18n', {}) if lang not in i18n: debug('err pre jazyk {} nemame, tak nastavujem cs'.format( lang)) lang = SC.DEFAULT_LANG dok(Strings.txt(Strings.SYSTEM_H1), '{}'.format(data['i18n'][lang])) pass else: dok(Strings.txt(Strings.SYSTEM_H1), '{}'.format(data)) else: debug('ERROR response: {}'.format(self.response)) dok(Strings.txt(Strings.SYSTEM_H1), Strings.txt(Strings.SYSTEM_API_ERROR_L1))
def resolve(self): data = self.data del (data[SC.ITEM_URL]) self.streams = self.input.get(SC.ITEM_STRMS) self.filter() items = [] matrix = [] for s in self.streams: debug('ideme vytvorit listItems zo streamov') s.update(data) itm = SCStreamSelect(s) x = itm.get() title_items = [ '[B]{}[/B] - '.format(s.get(SC.ITEM_LANG)), '[B]{}[/B] '.format(s.get(SC.ITEM_QUALITY)), '{} '.format(s.get(SC.ITEM_SIZE)), '{}{}'.format(s.get(SC.ITEM_VIDEO_INFO), s.get(SC.ITEM_AUDIO_INFO)), ] matrix.append(title_items) items.append(x[1]) # matrix = make_table(matrix) # info('matrix: {}'.format(matrix)) for i, itm in enumerate(items): itm.setProperty('old_title', itm.getLabel()) itm.setLabel(' '.join(matrix[i])) if len( items ) > 1 or SC.ACTION_SELECT_STREAM in self.params or SC.ACTION_DOWNLOAD in self.params: pos = dselect(items, heading=items[0].getProperty('old_title'), use_details=True) # info('post: {} | {}'.format(pos, json.dumps(self.data))) if pos is False or pos == -1: raise BaseException res = items[pos] self.selected = self.streams[pos] elif len(items) == 1: res = items[0] self.selected = self.streams[ 0] if self.selected is None else self.selected else: raise BaseException url = res.getPath() # info('vybrany stream: {} / {}'.format(res.getPath(), self.selected)) if res.getProperty(SC.ITEM_PROVIDER) == SC.PROVIDER: resp = Sc.get(res.getPath()) kr = Kraska() try: ident = resp.get(SC.ITEM_IDENT) debug('ideme resolvovat ident {} na kra.sk'.format(ident)) url = kr.resolve(ident) except ResolveException as e: dok(Strings.txt(Strings.RESOLVE_ERROR_H1), Strings.txt(Strings.RESOLVE_ERROR_L1)) raise BaseException except: raise BaseException if res.getProperty(SC.ITEM_SUBS): debug('subor ma titulky, tak ich natahujem') part = res.getProperty(SC.ITEM_SUBS).split('/file/') self.item.setSubtitles([kr.resolve(part[1])]) else: info('nemame titulky') info('resolve: {}'.format(url)) if 'lid' in data: lid = 'p-{}'.format( data.get('lid')) if parental_history() else data.get('lid') st = List(lid, max_items=20) st.add(res.getProperty(SC.ITEM_ID)) self.item.setPath(url) self.item.setLabel(res.getProperty('original_title')) # home_win.setProperty('SC-lite-item', '{}'.format(res.getProperty(SC.ITEM_ID))) if 'unique_ids' in self.input.get(SC.ITEM_INFO): unique_ids = self.input.get(SC.ITEM_INFO).get('unique_ids') home_win.setProperty('script.trakt.ids', '{}'.format(dumps(unique_ids))) home_win.setProperty('{}.ids'.format(ADDON_ID), '{}'.format(dumps(unique_ids)))
def enable_auto_update(self): if not self.check_repo(): from resources.lib.language import Strings dok(Strings.txt(Strings.SYSTEM_H1), Strings.txt(Strings.SYSTEM_NOT_INSTALLED_FROM_REPOSITORY)) query = 'delete from update_rules where addonID=?' self._db.execute(query, ADDON_ID)