示例#1
0
def seasons(item_id):
    item = plugin.client("items/{}".format(item_id)).get()["item"]
    watching_info = plugin.client("watching").get(
        data={"id": item["id"]})["item"]
    selectedSeason = False
    xbmcplugin.setContent(plugin.handle, "tvshows")
    for season in item["seasons"]:
        season_title = "Сезон {}".format(season["number"])
        watching_season = watching_info["seasons"][season["number"] - 1]
        li = plugin.list_item(
            season_title,
            video_info=extract_video_info(
                item,
                {
                    "season": season["number"],
                    "playcount": watching_season["status"],
                    "mediatype": "season",
                },
            ),
            poster=item["posters"]["big"],
            fanart=item["posters"]["wide"],
            properties={"id": item["id"]},
            addContextMenuItems=True,
        )
        if watching_season["status"] < 1 and not selectedSeason:
            selectedSeason = True
            li.select(selectedSeason)
        url = plugin.routing.build_url("season_episodes", item_id,
                                       season["number"])
        xbmcplugin.addDirectoryItem(plugin.handle, url, li, True)
    xbmcplugin.endOfDirectory(plugin.handle, cacheToDisc=False)
示例#2
0
def season_episodes(item_id, season_number):
    item = plugin.client("items/{}".format(item_id)).get()["item"]
    watching_info = plugin.client("watching").get(data={"id": item_id})["item"]
    season_number = int(season_number)
    season = item["seasons"][season_number - 1]
    watching_season = watching_info["seasons"][season_number - 1]
    selectedEpisode = False
    xbmcplugin.setContent(plugin.handle, "episodes")
    playback_data = {}
    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.
        try:
            watching_episode = watching_season["episodes"][episode["number"] -
                                                           1]
        except IndexError:
            continue
        episode_title = "s{:02d}e{:02d}".format(season_number,
                                                episode["number"])
        if episode["title"]:
            episode_title = u"{} | {}".format(episode_title, episode["title"])
        info = extract_video_info(
            item,
            {
                "season": season_number,
                "episode": episode["number"],
                "tvshowtitle": episode["title"],
                "time": watching_episode["time"],
                "duration": watching_episode["duration"],
                "playcount": watching_episode["status"],
                "mediatype": "episode",
            },
        )
        li = plugin.list_item(
            episode_title,
            thumbnailImage=episode["thumbnail"],
            poster=item["posters"]["big"],
            fanart=item["posters"]["wide"],
            video_info=info,
            properties={
                "id": item["id"],
                "isPlayable": "true"
            },
            addContextMenuItems=True,
        )
        if watching_episode["status"] < 1 and not selectedEpisode:
            selectedEpisode = True
            li.select(selectedEpisode)
        url = plugin.routing.build_url("play", item["id"], episode["number"])
        playback_data[episode["number"]] = {
            "video_data": episode,
            "video_info": info,
            "poster": item["posters"]["big"],
            "title": episode_title,
        }
        xbmcplugin.addDirectoryItem(plugin.handle, url, li, False)
    set_window_property(playback_data)
    xbmcplugin.endOfDirectory(plugin.handle, cacheToDisc=False)
示例#3
0
def show_items(items, content_type, add_indexes=False):
    xbmcplugin.setContent(plugin.handle,
                          content_type_map[content_type.rstrip("s")])
    playback_data = {}
    # Fill list with items
    for index, item in enumerate(items, 1):
        title = item["title"]
        title = u"{}. {}".format(index, title) if add_indexes else title
        li = plugin.list_item(
            title,
            poster=item["posters"]["big"],
            fanart=item["posters"]["wide"],
            properties={"id": item["id"]},
        )
        if "in_watchlist" in item:
            li.setProperty("in_watchlist", str(int(item["in_watchlist"])))
        video_info = extract_video_info(
            item, {
                "trailer": trailer_link(item),
                "mediatype": content_type_map[item["type"]]
            })
        # If not serials or multiseries movie, create a playable item
        if item["type"] not in ["serial", "docuserial", "tvshow"
                                ] and not item["subtype"]:
            watching_info = plugin.client("watching").get(
                data={"id": item["id"]})["item"]["videos"][0]
            video_info.update({
                "time": watching_info["time"],
                "duration": watching_info["duration"],
                "playcount": watching_info["status"],
            })
            link = plugin.routing.build_url("play", item["id"], index)
            li.setProperty("isPlayable", "true")
            li.setResumeTime(watching_info["time"], watching_info["duration"])
            isdir = False
            playback_data[index] = {
                "video_info": video_info,
                "poster": item["posters"]["big"],
                "title": title,
            }
            set_window_property(playback_data)
        elif item["subtype"] == "multi":
            watching_info = plugin.client("watching").get(
                data={"id": item["id"]})["item"]
            li.setProperty("subtype", "multi")
            video_info.update({"playcount": watching_info["status"]})
            link = plugin.routing.build_url("episodes", item["id"])
            isdir = True
        else:
            link = plugin.routing.build_url("seasons", item["id"])
            isdir = True
        li.setInfo("video", video_info)
        li.addPredefinedContextMenuItems()
        li.markAdvert(item["advert"])
        xbmcplugin.addDirectoryItem(plugin.handle, link, li, isdir)
示例#4
0
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)
示例#5
0
def episodes(item_id):
    item = plugin.client("items/{}".format(item_id)).get()["item"]
    watching_info = plugin.client("watching").get(data={"id": item_id})["item"]
    xbmcplugin.setContent(plugin.handle, "episodes")
    playback_data = {}
    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 = u"{} | {}".format(episode_title, video["title"])
        info = extract_video_info(
            item,
            {
                "episode": video["number"],
                "tvshowtitle": video["title"],
                "time": watching_episode["time"],
                "duration": watching_episode["duration"],
                "playcount": video["watched"],
                "mediatype": "episode",
            },
        )
        li = plugin.list_item(
            episode_title,
            thumbnailImage=video["thumbnail"],
            video_info=info,
            poster=item["posters"]["big"],
            fanart=item["posters"]["wide"],
            properties={
                "id": item["id"],
                "isPlayable": "true"
            },
            addContextMenuItems=True,
        )
        url = plugin.routing.build_url("play", item["id"], video["number"])
        playback_data[video["number"]] = {
            "video_data": video,
            "video_info": info,
            "poster": item["posters"]["big"],
            "title": episode_title,
        }
        xbmcplugin.addDirectoryItem(plugin.handle, url, li, False)
    set_window_property(playback_data)
    xbmcplugin.endOfDirectory(plugin.handle, cacheToDisc=False)
示例#6
0
def watching_movies():
    xbmcplugin.setContent(plugin.handle, "movies")
    playback_data = {}
    for i, item in enumerate(plugin.client("watching/movies").get()["items"]):
        li = plugin.list_item(
            item["title"],
            poster=item["posters"]["big"],
            properties={"id": item["id"]},
            video_info={"mediatype": content_type_map[item["type"].lower()]},
            addContextMenuItems=True,
        )
        if item["subtype"] == "multi":
            url = plugin.routing.build_url("episodes", item["id"])
            isdir = True
        else:
            response = plugin.client("items/{}".format(item["id"])).get()
            watching_info = plugin.client("watching").get(
                data={"id": item["id"]})["item"]["videos"]
            watching_info = watching_info[0]
            video_info = extract_video_info(
                response["item"],
                {
                    "time": watching_info["time"],
                    "duration": watching_info["duration"],
                    "playcount": watching_info["status"],
                },
            )
            li.setInfo("video", video_info)
            li.setProperty("isPlayable", "true")
            li.setResumeTime(watching_info["time"])
            url = plugin.routing.build_url("play", item["id"], i)
            playback_data[i] = {
                "video_info": video_info,
                "poster": item["posters"]["big"],
                "title": item["title"],
            }
            isdir = False
        xbmcplugin.addDirectoryItem(plugin.handle, url, li, isdir)
    set_window_property(playback_data)
    xbmcplugin.endOfDirectory(plugin.handle, cacheToDisc=False)