def __init__(self): """ Initialise object """ self._auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) self._api = ContentApi(self._auth, cache_path=kodiutils.get_cache_path())
def __init__(self): """ Initialise object """ self._auth = VtmGoAuth(kodiutils.get_setting('username'), kodiutils.get_setting('password'), 'VTM', kodiutils.get_setting('profile'), kodiutils.get_tokens_path()) self._api = VtmGo(self._auth)
def __init__(self): Monitor.__init__(self) self.update_interval = 24 * 3600 # Every 24 hours self.cache_expiry = 30 * 24 * 3600 # One month self._auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path())
def __init__(self): """ Initialise object """ self._auth = Auth(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_setting('loginprovider'), kodiutils.get_setting('profile'), kodiutils.get_tokens_path())
def index(): """ Ask to login, or go to the main menu. """ if not kodiutils.has_credentials(): if not kodiutils.yesno_dialog(message=kodiutils.localize( 30701)): # You need to configure your credentials... # We have no credentials, return to the Home Menu kodiutils.end_of_directory() kodiutils.execute_builtin('ActivateWindow(Home)') return kodiutils.open_settings() try: # Try authentication AuthApi(username=kodiutils.get_setting('username'), password=kodiutils.get_setting('password'), tenant=kodiutils.get_setting('tenant'), token_path=kodiutils.get_tokens_path()) except InvalidLoginException: kodiutils.ok_dialog(message=kodiutils.localize( 30203)) # Your credentials are not valid! kodiutils.open_settings() kodiutils.execute_builtin('ActivateWindow(Home)') kodiutils.end_of_directory() return except HTTPError as exc: kodiutils.ok_dialog(message=kodiutils.localize( 30702, code='HTTP %d' % exc.response.status_code) ) # Unknown error while logging in: {code} kodiutils.end_of_directory() return show_main_menu()
def onClick(self, controlID): if controlID == 9100: self.ClearAllListviews() sHost = kodiutils.get_setting('host') iPort = kodiutils.get_setting_as_int('port') bUseSSL = kodiutils.get_setting_as_bool('usessl') #Show error if we don't have any port or host if len(sHost) == 0: kodiutils.dialogok(__language__(30008), __language__(30009), __language__(30010), "") kodiutils.show_settings() return self.getControl(9002).setLabel( kodiutils.get_setting('host')) #print the host we connect to log("Connecting to: " + sHost) self.WS.ConnectTo(sHost, iPort, bUseSSL, "directory") if controlID == 9102: self.ClearAllListviews() self.WS.terminate() if controlID == 6000: self.CleanUp() self.close() if controlID == 9500: self.SetSorting("NAME", True) if controlID == 9501: self.SetSorting("MODIFY", True) if controlID == 9502: self.SetSorting("SIZE", True) if controlID == 9503: self.SetCleanFilename( self.getControl(9503).isSelected() == 1, True) if controlID == 100: self.onClickDirectory() if controlID == 500: self.onClickFilelist() if controlID == 9101: kodiutils.show_settings() self.getControl(9002).setLabel(kodiutils.get_setting('host')) if controlID == 600: self.onClickQueue() if controlID == 601: if kodiutils.dialogyesno(__language__(30011), __language__(30012)) == True: self.WS.SendMOTRCommand( "QUEUEMANAGEMENT", "-1;clear-finished" ) #QueueID = -1 when default commands are used if controlID == 602: if kodiutils.dialogyesno(__language__(30011), __language__(30013)) == True: self.WS.SendMOTRCommand( "QUEUEMANAGEMENT", "-1;stop-all-running" ) #QueueID = -1 when default commands are used if controlID == 603: if kodiutils.dialogyesno(__language__(30011), __language__(30014)) == True: self.WS.SendMOTRCommand( "QUEUEMANAGEMENT", "-1;remove-all" ) #QueueID = -1 when default commands are used
def __init__(self): """ Initialise object. """ auth = AuthApi(username=kodiutils.get_setting('username'), password=kodiutils.get_setting('password'), tenant=kodiutils.get_setting('tenant'), token_path=kodiutils.get_tokens_path()) self._search_api = SearchApi(auth)
def show_ui(): client_id = kodiutils.get_setting('client_id') if not client_id: xbmcgui.Dialog().ok('Error', 'Google Client ID is missing. ', 'Please update it in the settings and restart!') return client_secret = kodiutils.get_setting('client_secret') if not client_secret: xbmcgui.Dialog().ok('Error', 'Google Client secret is missing. ', 'Please update it in the settings and restart!') return sheet_id = kodiutils.get_setting('sheet_id') if not sheet_id: xbmcgui.Dialog().ok('Error', 'Google Sheet ID is missing. ', 'Please update it in the settings and restart!') return _sheet = sheet.GoogleSheets(client_id, client_secret, sheet_id) select_sheet_window = SelectSheetWindow('select-sheet-window.xml', CWD, 'default', '1080i', True, sheet=_sheet) select_sheet_window.doModal() del select_sheet_window
def _resolve_stream(uuid): """ Resolve the stream for the requested item :type uuid: string """ try: # Check if we have credentials if not kodiutils.get_setting('username') or not kodiutils.get_setting('password'): confirm = kodiutils.yesno_dialog( message=kodiutils.localize(30701)) # To watch a video, you need to enter your credentials. Do you want to enter them now? if confirm: kodiutils.open_settings() kodiutils.end_of_directory() return None # Fetch an auth token now try: auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) # Get stream information resolved_stream = ContentApi(auth).get_stream_by_uuid(uuid) return resolved_stream except (InvalidLoginException, AuthenticationException) as ex: _LOGGER.exception(ex) kodiutils.ok_dialog(message=kodiutils.localize(30702, error=str(ex))) kodiutils.end_of_directory() return None except GeoblockedException: kodiutils.ok_dialog(message=kodiutils.localize(30710)) # This video is geo-blocked... return None except UnavailableException: kodiutils.ok_dialog(message=kodiutils.localize(30712)) # The video is unavailable... return None
def __init__(self): """ Initialise object """ auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) self._api = ContentApi(auth, cache_path=kodiutils.get_cache_path()) # Workaround for Raspberry Pi 3 and older kodiutils.set_global_setting('videoplayer.useomxplayer', True)
def DownloadLink(self, sDirectory): sHost = kodiutils.get_setting('host') sPort = kodiutils.get_setting('port') bUseSSL = kodiutils.get_setting_as_bool('usessl') sWebConnect = 'http://' if bUseSSL == True: sWebConnect = 'https://' return sWebConnect + sHost + ":" + sPort + "/" + sDirectory + "/"
def is_loggedin(): if kodiutils.get_setting('api_token'): now = time() expires = kodiutils.get_setting("api_token_expiry") if expires <= now: if not login(): return return True
def __init__(self, port): """ Initialize IPTV Manager object. """ self.port = port self._auth = AuthApi(username=kodiutils.get_setting('username'), password=kodiutils.get_setting('password'), tenant=kodiutils.get_setting('tenant'), token_path=kodiutils.get_tokens_path())
def __init__(self): """ Initialise object. """ auth = AuthApi(username=kodiutils.get_setting('username'), password=kodiutils.get_setting('password'), tenant=kodiutils.get_setting('tenant'), token_path=kodiutils.get_tokens_path()) self._entitlements = auth.list_entitlements() self._channel_api = ChannelApi(auth) self._epg_api = EpgApi(auth)
def __init__(self): """ Initialise object """ try: self._auth = VtmGoAuth(kodiutils.get_setting('username'), kodiutils.get_setting('password'), 'VTM', kodiutils.get_setting('profile'), kodiutils.get_tokens_path()) except NoLoginException: self._auth = None self._vtm_go = VtmGo(self._auth)
def __init__(self, port): """ Initialise object :type port: int """ self._auth = VtmGoAuth(kodiutils.get_setting('username'), kodiutils.get_setting('password'), 'VTM', kodiutils.get_setting('profile'), kodiutils.get_tokens_path()) self._vtm_go = VtmGo(self._auth) self._vtm_go_epg = VtmGoEpg() self.port = port
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 onWebsocketConnected(self): self.getControl(9100).setEnabled( True) #Enable the connect button when we try to connect kodiutils.notification(__language__(30015), __language__(30017), time=1000) self.GUIOnConnection(True) SessionID = kodiutils.get_setting('SessionID') AuthID = kodiutils.get_setting('AuthID') Username = kodiutils.get_setting('username') self.WS.SendMOTRCommand("SESSIONRESTORE", SessionID + ";" + AuthID + ";" + Username)
def play(item): """ Play the requested item. :type item: string """ # Workaround for Raspberry Pi 3 and older omxplayer = kodiutils.get_global_setting('videoplayer.useomxplayer') if omxplayer is False: kodiutils.set_global_setting('videoplayer.useomxplayer', True) try: # Check if we have credentials if not kodiutils.get_setting( 'username') or not kodiutils.get_setting('password'): confirm = kodiutils.yesno_dialog( message=kodiutils.localize(30701) ) # To watch a video, you need to enter your credentials. Do you want to enter them now? if confirm: kodiutils.open_settings() kodiutils.end_of_directory() return # Fetch an auth token now try: auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) # Get stream information resolved_stream = ContentApi(auth).get_stream_by_uuid(item) except (InvalidLoginException, AuthenticationException) as ex: _LOGGER.error(ex) kodiutils.ok_dialog( message=kodiutils.localize(30702, error=str(ex))) kodiutils.end_of_directory() return except GeoblockedException: kodiutils.ok_dialog(heading=kodiutils.localize(30709), message=kodiutils.localize( 30710)) # This video is geo-blocked... return except UnavailableException: kodiutils.ok_dialog(heading=kodiutils.localize(30711), message=kodiutils.localize( 30712)) # The video is unavailable... return # Play this item kodiutils.play(resolved_stream)
def check_credentials(): from resources.lib import vtmgoauth auth = vtmgoauth.VtmGoAuth(username=get_setting('email'), password=get_setting('password')) try: auth.login() show_ok_dialog(message='Credentials are correct!') except Exception: # FIXME: This ought to be more specific show_ok_dialog(message='Your credentials are not valid!') raise show_settings()
def _has_credentials_changed(): """ Check if credentials have changed """ old_hash = kodiutils.get_setting('credentials_hash') new_hash = '' if kodiutils.get_setting('username') or kodiutils.get_setting( 'password'): new_hash = hashlib.md5((kodiutils.get_setting('username') + kodiutils.get_setting('password') ).encode('utf-8')).hexdigest() if new_hash != old_hash: kodiutils.set_setting('credentials_hash', new_hash) return True return False
def get_wishlist(): # Getting wishlist path = os.path.join(kodiutils.get_setting("wlPath"), kodiutils.get_setting("wlFilename")) if kodiutils.get_setting("wlPath") == "": kodiutils.notification("Warning", "Please set a path where to store a wishlist", time=5000, icon=ADDON.getAddonInfo('icon'), sound=True) path = os.path.join(xbmc.translatePath(ADDON.getAddonInfo('profile')), kodiutils.get_setting("wlFilename")) logger.debug(path) if os.path.exists(path): mode = 'r' else: mode = 'w+' with open(path, mode) as f: f_ch = f.read() return f_ch
def download(name,url): file_name = urllib.unquote(name) file_url = urllib.unquote(url) dst_file = file_name + "." + file_url.split("/")[-1].split(".")[-1] #Download file downloader = Downloader() downloader.downloadall(os.path.join(kodiutils.get_setting("downloadPath"),dst_file),file_url,file_name)
def downloads(): if kodiutils.get_setting_as_bool("folder") and kodiutils.get_setting("downloadPath") and xbmcvfs.exists(kodiutils.get_setting("downloadPath")): dirs, files = xbmcvfs.listdir(kodiutils.get_setting("downloadPath")) if files: items = [] for file_ in files: cm = [] liz = ListItem(file_.split(".")[0]) liz.setPath(os.path.join(kodiutils.get_setting("downloadPath"),file_)) liz.setProperty('IsPlayable', 'true') cm.append((kodiutils.get_string(32055), 'XBMC.RunPlugin(plugin://%s/delete_file/%s)' % (ADDON.getAddonInfo("id"),urllib.quote(os.path.join(kodiutils.get_setting("downloadPath"),file_), safe='')) )) liz.addContextMenuItems(cm, replaceItems=False) items.append((liz.getPath(), liz, False)) if items: addDirectoryItems(plugin.handle, items, totalItems=len(items)) endOfDirectory(plugin.handle)
def get_product(): """ Return the product that is currently selected. """ profile = kodiutils.get_setting('profile') try: return profile.split(':')[1] except (IndexError, AttributeError): return None
def __init__(self, proxy): self.proxy = proxy p = urlparse(proxy.path) self.path = p.path self.params = parse_qs(p.query) play_url = self.path.endswith('master.m3u8') m3u8_url = self.path.endswith('.m3u8') ts_url = self.path.endswith('.ts') key_url = self.path.endswith('.key') self.channel_name = self.path.split('/')[2] self.ishls = 'hls' in self.params self.maxq = 'maxq' in self.params and int(self.params['maxq'][0]) self.hlsrx = '' if not self.ishls else '/' + self.params['hls'][0] self.quality = qmap[kodiutils.get_setting('quality')] try: if play_url: self.getMaster() elif m3u8_url: self.getM3U8() elif key_url: self.getKey() elif ts_url: self.resolveTS() else: self.proxy.send_response(404, "Not Found") except Exception, e: log(str(e), LOGNOTICE) if (self.proxy): self.proxy.send_response(500, "Internal Server Error")
def periodical_check(self): if monitor.can_check(): # try: # player.periodical_check() # except: # debug('player err: {}'.format(traceback.format_exc())) # pass try: monitor.periodical_check() except: debug('monitor err: {}'.format(traceback.format_exc())) pass try: if self.atv: self.atv.run() except: debug('android tv err: {}'.format(traceback.format_exc())) pass if get_setting('trakt.user'): try: from resources.lib.trakt.Trakt import trakt trakt.check_trakt() except: debug('trakt err: {}'.format(traceback.format_exc())) pass try: self.next_ep.run() except: debug('nextep err: {}'.format(traceback.format_exc())) pass
def run(self): path = get_setting('androidtv.path') cur = int(time()) if path and self.last_run + 3600 < cur: self.last_run = time() items = self.list.get() for i in items: path_name = make_legal_filename('{}/{}/'.format( path, i.get(SC.ITEM_ID))) debug('android: {} {}'.format(i, path_name)) mkdir(path_name) files = xbmcvfs.listdir(path_name) debug('files {}'.format(files)) for f in files: if len(f): debug('file: {}'.format(f)) xbmcvfs.delete(f[0]) res = Sc.get(i.get('url')) menu = res.get('menu', {}) if len(menu): debug('Mame menu polozky') for pos, s in enumerate(menu): if pos < 30: url = create_plugin_url({ SC.ITEM_ID: '{}'.format(s.get('id', 0)), SC.ITEM_URL: s.get('url', '') }) base_name = '{}{:04d}'.format(path_name, pos) fn = make_legal_filename( '{}.strm'.format(base_name)) # debug('{} -> {} {} {}'.format(pos, fn, url, s.get(SC.ITEM_UIDS))) fs = xbmcvfs.File(fn, 'w') fs.write('{}'.format(url)) fs.close() nfo = SCNFO(s) # debug('NFO: {}'.format(encode(nfo.xml()))) fs = xbmcvfs.File( make_legal_filename( '{}.nfo'.format(base_name)), 'w') fs.write('{}'.format(encode(nfo.xml()))) fs.close() playlist_base = make_legal_filename( 'special://profile/playlists/video/') xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>' \ '<smartplaylist type="movies">' \ ' <name>{}</name>' \ ' <match>all</match>' \ ' <rule field="path" operator="contains"><value>{}</value></rule>' \ '</smartplaylist>' xbmcvfs.mkdirs(playlist_base) filename = make_legal_filename('{}{}.xsp'.format( playlist_base, i.get(SC.ITEM_ID))) fs = xbmcvfs.File(filename, 'w') fs.write(xml.format(i.get(SC.ITEM_ID), path_name)) fs.close() self.cleanup_library_path(path) exec_build_in('UpdateLibrary(video,{})'.format(path))
def getClientId(self): clientId = kodiutils.get_setting('clientId') if not clientId: clientId = uuid.uuid4() kodiutils.set_setting('clientId', clientId) return clientId
def translate_path(self, path): import re found = re.search('sc://(?P<typ>[^\(]+)\((?P<param1>[^\s,\)]+)\)', path) if found.group('typ') == 'config': path = make_legal_filename( translate_path(get_setting(found.group('param1')))) return path
def delete_file(file_): file_ = urllib.unquote(file_) #check if the file is in the download folder if xbmcvfs.exists(os.path.join(kodiutils.get_setting("downloadPath"),file_.split("/")[-1])): xbmcvfs.delete(file_) dialog.notification(kodiutils.get_string(32058),kodiutils.get_string(32056),icon=revision_icon) xbmc.executebuiltin("Container.Refresh") else: dialog.notification(kodiutils.get_string(32058),kodiutils.get_string(32057),icon=revision_icon)
def get_uuid(): uuid = kodiutils.get_setting('uuid') if not uuid: stringLength = 10 letters = string.ascii_lowercase uuid = ''.join(random.choice(letters) for i in range(stringLength)) logger.info('Setting Shiri X-UUID to: ' + uuid) kodiutils.set_setting('uuid', uuid) return uuid
def run(self): debug( 'START SERVICE....................................................................' ) last_changelog = get_setting('system.changelog') update_addon() if last_changelog != ADDON.getAddonInfo('version'): debug('SYSTEM.CHANGELOG: {}'.format( ADDON.getAddonInfo('changelog'))) set_setting('system.changelog', '{}'.format(ADDON.getAddonInfo('version'))) dtextviewer('', ADDON.getAddonInfo('changelog')) if get_setting_as_bool('system.autoexec'): try: exec_build_in( 'ActivateWindow(videos,plugin://{})'.format(ADDON_ID)) except: pass if get_setting('kraska.user'): kra = Kraska() kra.check_user() if get_setting_as_bool('system.ws.remote.enable'): ws = websocket.WS() ws.reconnect() self.next_ep = NextEp() clean_textures() from threading import Thread w = Thread(target=player.run) w.start() while not monitor.abortRequested(): try: self.periodical_check() except: debug('error: {}'.format(traceback.format_exc())) pass sleep(1000 * 5)
def index(): #Build default menu items #0) Downloads folder if kodiutils.get_setting_as_bool("download") and kodiutils.get_setting_as_bool("folder") and kodiutils.get_setting("downloadPath") and xbmcvfs.exists(kodiutils.get_setting("downloadPath")): liz = ListItem("["+kodiutils.get_string(32012)+"]") liz.setInfo( type="Video", infoLabels={"plot":kodiutils.get_string(32012)}) liz.setArt({"thumb":downloads_thumb, "fanart": fanart_bg}) addDirectoryItem(plugin.handle, plugin.url_for(downloads), liz, True) #1) Most Recent liz = ListItem("["+kodiutils.get_string(32013)+"]") liz.setInfo( type="Video", infoLabels={"plot":kodiutils.get_string(32013)}) liz.setArt({"thumb":recent_thumb, "fanart": fanart_bg}) addDirectoryItem(plugin.handle, plugin.url_for(show_episodes, urllib.quote('%sgetEpisodes%s&grouping=latest' % (BASE, KEY), safe=''), 0, urllib.quote(fanart_bg, safe='')), liz, True) #2) Featured liz = ListItem("["+kodiutils.get_string(32023)+"]") liz.setInfo( type="Video", infoLabels={"plot":kodiutils.get_string(32023)}) liz.setArt({"thumb":featured_thumb, "fanart": fanart_bg}) addDirectoryItem(plugin.handle, plugin.url_for(show_episodes, urllib.quote('%sgetEpisodes%s&grouping=featured' % (BASE, KEY), safe=''), 0, urllib.quote(fanart_bg, safe='')), liz, True) #3) Archive shows liz = ListItem("["+kodiutils.get_string(32014)+"]") liz.setInfo( type="Video", infoLabels={"plot":kodiutils.get_string(32014)}) liz.setArt({"thumb":archived_thumb, "fanart": fanart_bg}) addDirectoryItem(plugin.handle, plugin.url_for(list_shows, urllib.quote("%sgetShows%s&grouping=archived" % (BASE,KEY), safe='')), liz, True) #List shows list_shows(urllib.quote("%sgetShows%s" % (BASE,KEY), safe=''))