def dispatch(self, response): if response['apiVersion'] != self.apiVersion: icon = self.plugin.addon.getAddonInfo('icon') xbmcgui.Dialog().notification( 'Polonium-210', 'API version mismatch. Please update your plugin.', icon=icon, ) if response['kind'] == 'pluginList': return self.plugin_list(response['data']) if response['kind'] == 'itemList': return self.item_list(response['data']) if response['kind'] == 'itemPlay': return self.item_play(response['data']) if response['kind'] == 'globalSettings': return self.global_settings(response['data']) icon = self.plugin.addon.getAddonInfo('icon') xbmcgui.Dialog().notification('Polonium-210', 'Unexpected API response kind', icon=icon)
def enter_url(): mubi_url = xbmcgui.Dialog().input("Enter URL") film = mubi.get_film_id_by_web_url(mubi_url) reel_id = -1 if "reels" in film and len(film["reels"]) > 0: reel_id = reels[xbmcgui.Dialog().select( "Select Audio Language", [r['audio_language']['name'] for r in film.reels])]['id'] return play_film(film["film_id"]) #, reel_id)
def item_play(self, data): progress = xbmcgui.DialogProgress() try: progress.create('Polonium-210', 'Stream is starting ...') progress.update(25) item = data['item'].copy() item['is_playable'] = True if 'streams' not in data: icon = self.plugin.addon.getAddonInfo('icon') xbmcgui.Dialog().notification('Polonium-210', 'No stream', icon=icon) streams_qualities = data['streams'].keys() original_streams_qualities = list( filter(lambda x: x not in ['best', 'worst'], streams_qualities)) original_streams_qualities_len = len(original_streams_qualities) if original_streams_qualities_len > 1: selected = self._select_dialog("Select stream", streams_qualities) if selected < 0: return else: selected = 0 progress.update(50) selected_quality = streams_qualities[selected] stream = data['streams'][selected_quality] if stream['type'] in ('http', 'hls'): item['path'] = stream['url'] elif stream['type'] == 'rtmp': params = stream['params'].copy() url = params.pop('rtmp') args = " ".join( ["=".join([k, str(v)]) for k, v in params.items()]) item['path'] = " ".join([url, args]) else: icon = self.plugin.addon.getAddonInfo('icon') xbmcgui.Dialog().notification( 'Polonium-210', "Unsupported stream type {0}".format(stream['type']), icon=icon, ) self.plugin.play_video(item) # self.plugin.set_resolved_url(item) progress.update(75) finally: if progress: progress.close()
def AddPlaylist(tracking_string="Add Playlist"): sheet_url = plugin.keyboard( heading= 'Nhập URL của Google Spreadsheet (có hỗ trợ link rút gọn như bit.ly, goo.gl)' ) if sheet_url: if not re.match("^https*://", sheet_url): sheet_url = "https://" + sheet_url try: resp, content = http.request(sheet_url, "HEAD") sid, gid = re.compile("/d/(.+?)/.+?gid=(\d+)").findall( resp["content-location"])[0] match_passw = re.search('passw=(.+?)($|&)', resp["content-location"]) playlists = plugin.get_storage('playlists') name = plugin.keyboard(heading='Đặt tên cho Playlist') item = "[[COLOR yellow]%s[/COLOR]] %s@%s" % (name, gid, sid) if match_passw: item += "@@" + match_passw.group(1) if 'sections' in playlists: playlists["sections"] = [item] + playlists["sections"] else: playlists["sections"] = [item] xbmc.executebuiltin('Container.Refresh') except: line1 = "Vui lòng nhập URL hợp lệ. Ví dụ dạng đầy đủ:" line2 = "http://docs.google.com/spreadsheets/d/xxx/edit#gid=###" line3 = "Hoặc rút gọn: http://bit.ly/xxxxxx hoặc http://goo.gl/xxxxx" dlg = xbmcgui.Dialog() dlg.ok("URL không hợp lệ!!!", line1, line2, line3)
def GetFShareCred(): try: _hash = get_fshare_setting("hash") uname = get_fshare_setting("Ufacebook") pword = get_fshare_setting("Upassword") if _hash != (uname + pword): plugin.set_setting("cred", "") cred = json.loads(get_fshare_setting("cred")) user = GetFShareUser(cred) LoginOKNoti(user["email"], user["level"]) return cred except: try: uname = get_fshare_setting("Ufacebook") pword = get_fshare_setting("Upassword") cred = LoginFShare(uname, pword) user = GetFShareUser(cred) LoginOKNoti(user["email"], user["level"]) return cred except: dialog = xbmcgui.Dialog() yes = dialog.yesno('Đăng nhập không thành công!\n', '[COLOR yellow]Nhập VIP Fshare của bạn[/COLOR]', yeslabel='OK, nhập ngay', nolabel='Bỏ qua') if yes: plugin.open_settings() return GetFShareCred() return None
def GetFShareCred(): try: _hash = plugin.get_setting("hash") uname = plugin.get_setting("usernamefshare") pword = plugin.get_setting("passwordfshare") if _hash != (uname + pword): plugin.set_setting("cred", "") cred = json.loads(plugin.get_setting("cred")) user = GetFShareUser(cred) LoginOKNoti(user["email"], user["level"]) return cred except: try: uname = plugin.get_setting("usernamefshare") pword = plugin.get_setting("passwordfshare") cred = LoginFShare(uname, pword) user = GetFShareUser(cred) LoginOKNoti(user["email"], user["level"]) return cred except: dialog = xbmcgui.Dialog() yes = dialog.yesno( 'Đăng nhập không thành công!\n', '[COLOR yellow]Bạn muốn nhập tài khoản FShare VIP bây giờ không?[/COLOR]', yeslabel='OK, nhập ngay', nolabel='Bỏ qua') if yes: plugin.open_settings() return GetFShareCred() return None
def GetFShareCred(): try: _hash = get_fshare_setting("hash") uname = get_fshare_setting("usernamefshare") pword = get_fshare_setting("passwordfshare") if _hash != (uname+pword): plugin.set_setting("cred","") cred = json.loads(get_fshare_setting("cred")) user = GetFShareUser(cred) LoginOKNoti(user["email"], user["level"]) return cred except: try: uname = get_fshare_setting("usernamefshare") pword = get_fshare_setting("passwordfshare") cred = LoginFShare(uname,pword) user = GetFShareUser(cred) LoginOKNoti(user["email"], user["level"]) return cred except: dialog = xbmcgui.Dialog() yes = dialog.yesno( 'Đăng nhập không thành công!\n', '[COLOR yellow]Bạn cần nhập tài khoản VIP FShare để xem! Liên hệ qua**Facebook: TRAN HUY HOANG HOẶC ZALO:0974 090 325 để đăng ký tài khoản VIP ngay bây giờ![/COLOR]', yeslabel='OK, Nhập Ngay', nolabel='Bỏ Qua' ) if yes: plugin.open_settings() return GetFShareCred() return None
def get_storage(self, name='main', file_format='pickle', ttl=None): """Returns a storage for the given name. The returned storage is a fully functioning python dictionary and is designed to be used that way. It is usually not necessary for the caller to load or save the storage manually. If the storage does not already exist, it will be created. See Also: :class:`kodiswift.TimedStorage` for more details. Args: name (str): The name of the storage to retrieve. file_format (str): Choices are 'pickle', 'csv', and 'json'. Pickle is recommended as it supports python objects. Notes: If a storage already exists for the given name, the file_format parameter is ignored. The format will be determined by the existing storage file. ttl (int): The time to live for storage items specified in minutes or None for no expiration. Since storage items aren't expired until a storage is loaded form disk, it is possible to call get_storage() with a different TTL than when the storage was created. The currently specified TTL is always honored. Returns: kodiswift.storage.TimedStorage: """ if not hasattr(self, '_unsynced_storage'): self._unsynced_storage = {} filename = os.path.join(self.storage_path, name) try: storage = self._unsynced_storage[filename] log.debug('Loaded storage "%s" from memory', name) except KeyError: if ttl: ttl = timedelta(minutes=ttl) try: storage = TimedStorage(filename, ttl, file_format=file_format) storage.load() except UnknownFormat: # Thrown when the storage file is corrupted and can't be read. # Prompt user to delete storage. choices = ['Clear storage', 'Cancel'] ret = xbmcgui.Dialog().select( 'A storage file is corrupted. It' ' is recommended to clear it.', choices) if ret == 0: os.remove(filename) storage = TimedStorage(filename, ttl, file_format=file_format) else: raise Exception('Corrupted storage file at %s' % filename) self._unsynced_storage[filename] = storage log.debug('Loaded storage "%s" from disk', name) return storage
def decorated(*args, **kwargs): try: return func(*args, **kwargs) except requests.exceptions.HTTPError as exc: if exc.response.status_code == 401: self.authenticate() return func(*args, **kwargs) logger.log.warning("Request failed: %s", exc) raise except requests.exceptions.ConnectionError as exc: icon = self.plugin.addon.getAddonInfo('icon') xbmcgui.Dialog().notification('Polonium-210', 'API connection error', icon=icon) except requests.exceptions.SSLError as exc: icon = self.plugin.addon.getAddonInfo('icon') xbmcgui.Dialog().notification('Polonium-210', 'SSL certificate error', icon=icon)
def remove_playlist(self, playlist): '''Deletes a user specified playlist. If the playlist is not empty, the user will be presented with a yes/no confirmation dialog before deletion. ''' my_playlists = self.plugin.get_storage('my_playlists') num_items = len(my_playlists[playlist]) delete = True if num_items > 0: dialog = xbmcgui.Dialog() delete = dialog.yesno(self.plugin.name, 'Are you sure you wish to delete?') if delete: del my_playlists[playlist] my_playlists.sync() xbmc.executebuiltin('Container.Refresh')
def InstallRepo(path="0", tracking_string=""): ''' Cài đặt repo Parameters ---------- path : string Nếu truyền "gid" của Repositories sheet: Cài tự động toàn bộ repo trong Repositories sheet Nếu truyền link download zip repo Download và cài zip repo đó tracking_string : string Tên dễ đọc của view ''' GA( # tracking "Install Repo - %s" % tracking_string, "/install-repo/%s" % path) if path.isdigit(): # xác định GID pDialog = xbmcgui.DialogProgress() pDialog.create('Vui lòng đợi', 'Bắt đầu cài repo', 'Đang tải...') items = getItems(path) total = len(items) i = 0 failed = [] installed = [] for item in items: done = int(100 * i / total) pDialog.update(done, 'Đang tải', item["label"] + '...') if ":/" not in item["label2"]: result = xbmc.executeJSONRPC( '{"jsonrpc":"2.0","method":"Addons.GetAddonDetails", "params":{"addonid":"%s", "properties":["version"]}, "id":1}' % item["label"]) json_result = json.loads(result) if "version" in result and version_cmp( json_result["result"]["addon"]["version"], item["label2"]) >= 0: pass else: try: item["path"] = "http" + item["path"].split("http")[-1] download(urllib.unquote_plus(item["path"]), item["label"]) installed += [item["label"].encode("utf-8")] except: failed += [item["label"].encode("utf-8")] else: if not os.path.exists(xbmc.translatePath(item["label2"])): try: item["path"] = "http" + item["path"].split("http")[-1] download(urllib.unquote_plus(item["path"]), item["label2"]) installed += [item["label"].encode("utf-8")] except: failed += [item["label"].encode("utf-8")] if pDialog.iscanceled(): break i += 1 pDialog.close() if len(failed) > 0: dlg = xbmcgui.Dialog() s = "Không thể cài các rep sau:\n[COLOR orange]%s[/COLOR]" % "\n".join( failed) dlg.ok('Chú ý: Không cài đủ repo!', s) else: dlg = xbmcgui.Dialog() s = "Tất cả repo đã được cài thành công\n%s" % "\n".join(installed) dlg.ok('Cài Repo thành công!', s) else: # cài repo riêng lẻ try: download(path, "") dlg = xbmcgui.Dialog() s = "Repo %s đã được cài thành công" % tracking_string dlg.ok('Cài Repo thành công!', s) except: dlg = xbmcgui.Dialog() s = "Vùi lòng thử cài lại lần sau" dlg.ok('Cài repo thất bại!', s) xbmc.executebuiltin("XBMC.UpdateLocalAddons()") xbmc.executebuiltin("XBMC.UpdateAddonRepos()")
def _select_dialog(self, title, choices): dialog = xbmcgui.Dialog() return dialog.select(title, choices)
def enter_url(): mubi_url = xbmcgui.Dialog().input("Enter URL") film_id = mubi.get_film_id_by_web_url(mubi_url) return play_film(film_id)
def action_ok_dialog(title, text): ret = xbmcgui.Dialog().ok(title, text)