def toggle_watchlist(item_id): added = int(plugin.kwargs["added"]) plugin.client("watching/togglewatchlist").get(data={"id": item_id}) if added: notice('Сериал добавлен в список "Буду смотреть"') else: notice('Сериал удалён из списка "Буду смотреть"')
def _make_request(self, payload): self.plugin.logger.notice( "sending payload {} to oauth api".format(payload)) try: response = urllib2.urlopen(urllib2.Request(self.OAUTH_API_URL), urllib.urlencode(payload)).read() return json.loads(response) except urllib2.HTTPError as e: if e.code == 400: response = json.loads(e.read()) error = response.get("error") if error and error in [ "code_expired", "authorization_expired" ]: raise AuthExpiredException if error and error == "authorization_pending": raise AuthPendingException if error: notice("Ошибка аутентификации") raise AuthException(error) return response # server can respond with 429 status, so we just wait until it gives a correct response elif e.code == 429: for _ in range(2): time.sleep(3) return self.request(payload) else: self.plugin.logger.fatal( "oauth request error; status: {}; message: {}".format( e.code, e.message)) notice("Код ответа сервера {}".format(response["status"]), "Неизвестная ошибка") raise
def _make_request(self, payload): self.plugin.logger.info(f"sending payload {payload} to oauth api") try: response = urllib.request.urlopen( urllib.request.Request(self.OAUTH_API_URL), urllib.parse.urlencode(payload).encode("utf-8"), ).read() return json.loads(response) except urllib.error.HTTPError as e: if e.code == 400: response = json.loads(e.read()) error = response.get("error") if error and error in [ "code_expired", "authorization_expired" ]: raise AuthExpiredException if error and error == "authorization_pending": raise AuthPendingException if error: notice("Ошибка аутентификации") raise AuthException(error) return response # server can respond with 429 status, so we just wait until it gives a correct response elif e.code == 429: for _ in range(2): time.sleep(3) return self._make_request(payload) else: self._auth_dialog.close(cancel=True) self.plugin.logger.fatal( f"oauth request error; status: {e.code}; message: {e.message}" ) notice(f"Server status code {e.code}", "Activation error") sys.exit()
def edit_bookmarks(item_id): item_folders_resp = plugin.client("bookmarks/get-item-folders").get(data={"item": item_id}) all_folders_resp = plugin.client("bookmarks").get() all_folders = [f["title"] for f in all_folders_resp["items"]] item_folders = [f["title"] for f in item_folders_resp["folders"]] preselect = [all_folders.index(f) for f in item_folders] dialog = xbmcgui.Dialog() indexes = dialog.multiselect("Папки закладок", all_folders, preselect=preselect) # Cancel button was pressed if indexes is None: return chosen_folders = [all_folders[i] for i in indexes] folders_to_add = list(set(chosen_folders) - set(item_folders)) folders_to_remove = list(set(item_folders) - set(chosen_folders)) # Ok button was pressed but nothing changed if not folders_to_add and not folders_to_remove: return def get_folder_id(title): for folder in all_folders_resp["items"]: if folder["title"] == title: return folder["id"] for folder in folders_to_add: plugin.client("bookmarks/add").post(data={"item": item_id, "folder": get_folder_id(folder)}) for folder in folders_to_remove: plugin.client("bookmarks/remove-item").post( data={"item": item_id, "folder": get_folder_id(folder)} ) notice("Закладки для видео изменены")
def toggle_watchlist(item_id): added = int(plugin.kwargs["added"]) plugin.client("watching/togglewatchlist").get(data={"id": item_id}) if added: notice('Сериал добавлен в список "Буду смотреть"') else: notice('Сериал удалён из списка "Буду смотреть"') plugin.clear_window_property() xbmc.executebuiltin("Container.Refresh")
def hls_properties(self): if self.plugin.is_hls_enabled: helper = inputstreamhelper.Helper("hls") if not helper.check_inputstream(): notice("HLS поток не поддерживается") return {} else: return { "inputstream": helper.inputstream_addon, "inputstream.adaptive.manifest_type": "hls", } return {}
def play(item_id, index): properties = {} if ("hls" in plugin.settings.stream_type and plugin.settings.inputstream_adaptive_enabled == "true" and inputstreamhelper): helper = inputstreamhelper.Helper("hls") if not helper.check_inputstream(): return else: properties.update({ "inputstreamaddon": helper.inputstream_addon, "inputstream.adaptive.manifest_type": "hls", }) playback_data = get_window_property(index) video_data = playback_data.get("video_data") video_info = playback_data["video_info"] if not video_data: response = plugin.client("items/{}".format(item_id)).get() video_data = response["item"]["videos"][0] video_info = extract_video_info(response["item"], video_info) if "files" not in video_data: notice("Видео обновляется и временно не доступно!", "Видео в обработке", time=8000) return url = get_mlink( video_data, quality=plugin.settings.video_quality, stream_type=plugin.settings.stream_type, ask_quality=plugin.settings.ask_quality, ) properties.update({ "item_id": item_id, "play_duration": video_info["duration"], "play_resumetime": video_info["time"], "video_number": video_info.get("episode", 1), "season_number": video_info.get("season", ""), "playcount": video_info["playcount"], "imdbnumber": video_info["imdbnumber"], }) li = plugin.list_item( playback_data["title"], path=url, properties=properties, poster=playback_data["poster"], subtitles=[subtitle["url"] for subtitle in video_data["subtitles"]], ) player = Player(list_item=li) xbmcplugin.setResolvedUrl(plugin.handle, True, li) while player.is_playing: player.set_marktime() xbmc.sleep(1000)
def hls_properties(self): if ("hls" in self.plugin.settings.stream_type and self.plugin.settings.inputstream_adaptive_enabled == "true" and inputstreamhelper): helper = inputstreamhelper.Helper("hls") if not helper.check_inputstream(): notice("HLS поток не поддерживается") return {} else: return { "inputstream": helper.inputstream_addon, "inputstream.adaptive.manifest_type": "hls", } return {}
def _make_request(self, request, timeout=600): self.plugin.logger.info( f"sending {request.get_method()} request to {request.get_full_url()}" ) request.add_header("Authorization", f"Bearer {self.plugin.settings.access_token}") try: response = urllib.request.urlopen(request, timeout=timeout) except urllib.error.HTTPError as e: self.plugin.logger.error(f"HTTPError. Code: {e.code}") if e.code == 401: self.plugin.auth.get_token() if self.plugin.settings.access_token: return self._make_request(request) sys.exit() else: notice(f"Код ответа сервера {e.code}", "Ошибка") sys.exit() except Exception as e: self.plugin.logger.error( f"{type(e).__name__}. Message: {e.message}") notice(e.message, "Ошибка") else: response = json.loads(response.read()) if response["status"] == 200: return response else: self.plugin.logger.error( f"Unknown error. Code: {response['status']}") notice(f"Код ответа сервера {response['status']}", "Ошибка")
def _make_request(self, request, timeout=600): self.plugin.logger.notice("sending {} request to {}".format( request.get_method(), request.get_full_url())) request.add_header( "Authorization", "Bearer {}".format(self.plugin.settings.access_token)) try: response = urllib2.urlopen(request, timeout=timeout) except urllib2.HTTPError as e: self.plugin.logger.error("HTTPError. Code: {}.".format(e.code)) if e.code == 401: self.plugin.auth.get_token() if self.plugin.settings.access_token: return self._make_request(request) sys.exit() else: notice("Код ответа сервера {}".format(e.code), "Ошибка") sys.exit() except Exception as e: self.plugin.logger.error("{}. Message: {}".format( type(e).__name__, e.message)) notice(e.message, "Ошибка") else: response = json.loads(response.read()) if response["status"] == 200: return response else: self.plugin.logger.error("Unknown error. Code: {}".format( response["status"])) notice("Код ответа сервера {}".format(response["status"]), "Неизвестная ошибка")
def install_inputstream_helper(): try: xbmcaddon.Addon("script.module.inputstreamhelper") notice("inputstream helper установлен") except RuntimeError: xbmc.executebuiltin("InstallAddon(script.module.inputstreamhelper)")