def play(id, title, season_number=None, episode_number=None, video_data=None): if not video_data: response = KinoPubClient("items/{}".format(id)).get() video_data = response["item"]["videos"][0] else: video_data = json.loads(video_data) if "files" not in video_data: notice("Видео обновляется и временно не доступно!", "Видео в обработке", time=8000) return li = xbmcgui.ListItem(title) subtitles = [subtitle["url"] for subtitle in video_data["subtitles"]] if subtitles: li.setSubtitles(subtitles) url = get_mlink(video_data, quality=__settings__.getSetting("video_quality"), stream_type=__settings__.getSetting("stream_type"), ask_quality=__settings__.getSetting("ask_quality")) KinoPubClient("watching/marktime").get( data={ "id": id, "video": video_data["number"], "time": video_data.get("duration"), "season": season_number }) li.setPath(url) xbmcplugin.setResolvedUrl(request.handle, True, li)
def actionPlay(qp): response = api('items/%s' % qp['id']) if response['status'] == 200: item = response['item'] videoObject = None liObject = None season_number = 0 if 'season' in qp: # process episode for season in item['seasons']: if int(qp['season']) != int(season['number']): continue season_number = season['number'] for episode_number, episode in enumerate(season['episodes']): episode_number+=1 if episode_number == int(qp['episode']): videoObject = episode episode_title = "s%02de%02d" % (season['number'], episode_number) episode_title = "%s | %s" % (episode_title, episode['title']) if episode['title'] else episode_title liObject = xbmcgui.ListItem(episode_title) liObject.setInfo("video", { 'season': season['number'], 'episode': episode_number, 'duration': videoObject['duration'] if 'duration' in videoObject else None }) elif 'video' in qp: # process video for video_number, video in enumerate(item['videos']): video_number+=1 if video_number == int(qp['video']): videoObject = video if len(item['videos']) > 1: episode_title = "e%02d" % (video_number) episode_title = "%s | %s" % (episode_title, video['title']) if video['title'] else episode_title liObject = xbmcgui.ListItem(episode_title) liObject.setInfo("video", { 'season': 1, 'episode': video_number }) else: liObject = xbmcgui.ListItem(item['title']) else: pass subtitles = list() for subtitle in videoObject['subtitles']: subtitles.append(subtitle['url']) if len(subtitles) > 0: liObject.setSubtitles(subtitles) if 'files' not in videoObject: notice("Видео обновляется и временно не доступно!", "Видео в обработке", time=8000) return url = addonutils.get_mlink(videoObject, quality=DEFAULT_QUALITY, streamType=DEFAULT_STREAM_TYPE) api("watching/marktime", {'id': qp['id'], 'video': videoObject['number'], 'time': videoObject['duration'], 'season': season_number}) liObject.setPath(url) xbmcplugin.setResolvedUrl(handle, True, liObject)
def actionTrailer(qp): response = api('items/trailer', params={'id': qp['id']}) if response['status'] == 200: trailer = None trailer = response['trailer'] url = addonutils.get_mlink(trailer, quality=DEFAULT_QUALITY, streamType=DEFAULT_STREAM_TYPE) liObject = xbmcgui.ListItem('Трейлер') liObject.setPath(url) xbmcplugin.setResolvedUrl(handle, True, liObject)
def trailer(id, sid=None): response = KinoPubClient("items/trailer").get(data={"id": id}) trailer = response["trailer"] if "files" in trailer: url = get_mlink(trailer, quality=__settings__.getSetting("video_quality"), streamType=__settings__.getSetting("stream_type")) elif sid is not None: url = "plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid={}" url = url.format(sid) li = ExtendedListItem("Трейлер", path=url) xbmcplugin.setResolvedUrl(request.handle, True, li)
def episodes(id): item = KinoPubClient("items/{}".format(id)).get()["item"] watching_info = KinoPubClient("watching").get(data={"id": id})["item"] xbmcplugin.setContent(request.handle, "episodes") for video in item["videos"]: watching_episode = watching_info["videos"][video["number"] - 1] episode_title = "e{:02d}".format(video["number"]) if video["title"]: episode_title = "{} | {}".format(episode_title, video["title"].encode("utf-8")) info = extract_video_info( item, { "episode": video["number"], "time": watching_episode["time"], "duration": watching_episode["duration"], "playcount": video["watched"], "mediatype": "episode" }) li = ExtendedListItem(episode_title, thumbnailImage=video["thumbnail"], video_info=info, poster=item["posters"]["big"], properties={ "id": item["id"], "isPlayable": "true" }, addContextMenuItems=True) info = { "episode": video["number"], "time": watching_episode["time"], "duration": watching_episode["duration"], "playcount": video["watched"], "mediatype": "episode" } video_data = {'subtitles': video.get('subtitles', []), 'files': []} url = get_mlink(video, quality=__settings__.getSetting("video_quality"), stream_type=__settings__.getSetting("stream_type"), ask_quality=__settings__.getSetting("ask_quality")) link = get_internal_link("play", id=item["id"], title=episode_title, video_data=json.dumps(video_data), video_info=json.dumps(info), poster=item["posters"]["big"], url=url) xbmcplugin.addDirectoryItem(request.handle, link, li, False) xbmcplugin.endOfDirectory(request.handle)
def play(id, index): properties = {} if ("hls" in __settings__.getSetting("stream_type") and __settings__.getSetting("inputstream_helper_enabled") == "true"): 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 = KinoPubClient("items/{}".format(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=__settings__.getSetting("video_quality"), stream_type=__settings__.getSetting("stream_type"), ask_quality=__settings__.getSetting("ask_quality")) properties.update({ "id": 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 = ExtendedListItem( 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(request.handle, True, li) while player.is_playing: player.set_marktime() xbmc.sleep(1000)
def actionTrailer(qp): response = api('items/trailer', params={'id': qp['id']}) if response['status'] == 200: trailer = None trailer = response['trailer'] if 'files' in trailer: url = addonutils.get_mlink(trailer, quality=DEFAULT_QUALITY, streamType=DEFAULT_STREAM_TYPE) elif 'sid' in qp: url = 'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=%s' % qp[ 'sid'] liObject = xbmcgui.ListItem('Трейлер') liObject.setPath(url) xbmcplugin.setResolvedUrl(handle, True, liObject)
def play(id, title, video_info, video_data=None, poster=None, url=None): if not video_data: response = KinoPubClient("items/{}".format(id)).get() video_data = response["item"]["videos"][0] video_info = extract_video_info(response["item"], json.loads(video_info)) video_data = json.loads(video_data) if isinstance(video_data, str) else video_data video_info = json.loads(video_info) if isinstance(video_info, str) else video_info if "files" not in video_data: notice("Видео обновляется и временно не доступно!", "Видео в обработке", time=8000) return if not url: url = get_mlink(video_data, quality=__settings__.getSetting("video_quality"), stream_type=__settings__.getSetting("stream_type"), ask_quality=__settings__.getSetting("ask_quality")) li = ExtendedListItem( title, path=url, properties={ "id": 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"] }, poster=poster, subtitles=[subtitle["url"] for subtitle in video_data["subtitles"]], ) player = Player(list_item=li) xbmcplugin.setResolvedUrl(request.handle, True, li) while player.is_playing: player.set_marktime() xbmc.sleep(1000)
def season_episodes(id, season_number): item = KinoPubClient("items/{}".format(id)).get()["item"] watching_info = KinoPubClient("watching").get(data={"id": id})["item"] season_number = int(season_number) season = item["seasons"][season_number - 1] watching_season = watching_info["seasons"][season_number - 1] watching_episode_numbers = [ episode["number"] for episode in watching_season["episodes"] ] selectedEpisode = False xbmcplugin.setContent(request.handle, "episodes") for episode in season["episodes"]: # In tvshow season could be a case when some episodes are not available, but episode numbers # in response payload are set correctly. if episode["number"] not in watching_episode_numbers: continue watching_episode = watching_season["episodes"][episode["number"] - 1] episode_title = "s{:02d}e{:02d}".format(season_number, episode["number"]) if episode["title"]: episode_title = "{} | {}".format(episode_title, episode["title"].encode("utf-8")) info = extract_video_info( item, { "season": season_number, "episode": episode["number"], "time": watching_episode["time"], "duration": watching_episode["duration"], "playcount": watching_episode["status"], "mediatype": "episode", "title": episode["title"] }) li = ExtendedListItem(episode_title, thumbnailImage=episode["thumbnail"], poster=item["posters"]["big"], video_info=info, properties={ "id": item["id"], "isPlayable": "true" }, addContextMenuItems=True) if watching_episode["status"] < 1 and not selectedEpisode: selectedEpisode = True li.select(selectedEpisode) info = { "season": season_number, "episode": episode["number"], "time": watching_episode["time"], "duration": watching_episode["duration"], "playcount": watching_episode["status"], "mediatype": "episode" } video_data = {'subtitles': episode.get('subtitles', []), 'files': []} url = get_mlink(episode, quality=__settings__.getSetting("video_quality"), stream_type=__settings__.getSetting("stream_type"), ask_quality=__settings__.getSetting("ask_quality")) link = get_internal_link( "play", id=item["id"], title=episode_title, video_info=json.dumps(info), video_data=json.dumps(video_data), poster=item["posters"]["big"], url=url, ) xbmcplugin.addDirectoryItem(request.handle, link, li, False) xbmcplugin.endOfDirectory(request.handle)
def actionPlay(qp): response = api('items/%s' % qp['id']) if response['status'] == 200: item = response['item'] videoObject = None liObject = None season_number = 0 if 'season' in qp: # process episode for season in item['seasons']: if int(qp['season']) != int(season['number']): continue season_number = season['number'] for episode_number, episode in enumerate(season['episodes']): episode_number += 1 if episode_number == int(qp['episode']): videoObject = episode episode_title = "s%02de%02d" % (season['number'], episode_number) episode_title = "%s | %s" % ( episode_title, episode['title'] ) if episode['title'] else episode_title liObject = xbmcgui.ListItem(episode_title) liObject.setInfo( "video", { 'season': season['number'], 'episode': episode_number, 'duration': videoObject['duration'] if 'duration' in videoObject else None }) elif 'video' in qp: # process video for video_number, video in enumerate(item['videos']): video_number += 1 if video_number == int(qp['video']): videoObject = video if len(item['videos']) > 1: episode_title = "e%02d" % (video_number) episode_title = "%s | %s" % ( episode_title, video['title'] ) if video['title'] else episode_title liObject = xbmcgui.ListItem(episode_title) liObject.setInfo("video", { 'season': 1, 'episode': video_number }) else: liObject = xbmcgui.ListItem(item['title']) else: pass subtitles = list() for subtitle in videoObject['subtitles']: subtitles.append(subtitle['url']) if len(subtitles) > 0: liObject.setSubtitles(subtitles) if 'files' not in videoObject: notice("Видео обновляется и временно не доступно!", "Видео в обработке", time=8000) return url = addonutils.get_mlink(videoObject, quality=DEFAULT_QUALITY, streamType=DEFAULT_STREAM_TYPE) api( "watching/marktime", { 'id': qp['id'], 'video': videoObject['number'], 'time': videoObject['duration'], 'season': season_number }) liObject.setPath(url) xbmcplugin.setResolvedUrl(handle, True, liObject)