Ejemplo n.º 1
0
def watching_movies():
    xbmcplugin.setContent(request.handle, "movies")
    for item in KinoPubClient("watching/movies").get()["items"]:
        li = ExtendedListItem(
            item["title"].encode("utf-8"),
            poster=item["posters"]["big"],
            properties={"id": item["id"]},
            video_info={"mediatype": mediatype_map[item["type"]]},
            addContextMenuItems=True)
        if item["subtype"] == "multi":
            link = get_internal_link("view_episodes", id=item["id"])
            isdir = True
        else:
            response = KinoPubClient("items/{}".format(item["id"])).get()
            watching_info = KinoPubClient("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"])
            link = get_internal_link("play",
                                     id=item["id"],
                                     title=item["title"].encode("utf-8"),
                                     poster=item["posters"]["big"],
                                     video_info=json.dumps(video_info))
            isdir = False
        xbmcplugin.addDirectoryItem(request.handle, link, li, isdir)
    xbmcplugin.endOfDirectory(request.handle)
Ejemplo n.º 2
0
def seasons(id):
    item = KinoPubClient("items/{}".format(id)).get()["item"]
    watching_info = KinoPubClient("watching").get(
        data={"id": item["id"]})["item"]
    selectedSeason = False
    xbmcplugin.setContent(request.handle, "tvshows")
    for season in item["seasons"]:
        season_title = "Сезон {}".format(season["number"])
        watching_season = watching_info["seasons"][season["number"] - 1]
        li = ExtendedListItem(season_title,
                              video_info=extract_video_info(
                                  item, {
                                      "season": season["number"],
                                      "playcount": watching_season["status"],
                                      "mediatype": "season"
                                  }),
                              poster=item["posters"]["big"],
                              properties={"id": item["id"]},
                              addContextMenuItems=True)
        if watching_season["status"] < 1 and not selectedSeason:
            selectedSeason = True
            li.select(selectedSeason)
        link = get_internal_link("view_season_episodes",
                                 id=id,
                                 season_number=season["number"])
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    xbmcplugin.endOfDirectory(request.handle)
Ejemplo n.º 3
0
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)
        link = get_internal_link("play",
                                 id=item["id"],
                                 title=episode_title,
                                 video_data=json.dumps(video),
                                 video_info=json.dumps(info),
                                 poster=item["posters"]["big"])
        xbmcplugin.addDirectoryItem(request.handle, link, li, False)
    xbmcplugin.endOfDirectory(request.handle)
Ejemplo n.º 4
0
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")
    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.
        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"],
                "tvshowtitle": episode["title"],
                "time": watching_episode["time"],
                "duration": watching_episode["duration"],
                "playcount": watching_episode["status"],
                "mediatype": "episode"
            })
        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)
        link = get_internal_link("play",
                                 id=item["id"],
                                 index=episode["number"])
        playback_data[episode["number"]] = {
            "video_data": episode,
            "video_info": info,
            "poster": item["posters"]["big"],
            "title": episode_title
        }
        xbmcplugin.addDirectoryItem(request.handle, link, li, False)
    set_window_property(playback_data)
    xbmcplugin.endOfDirectory(request.handle, cacheToDisc=False)
Ejemplo n.º 5
0
def show_items(items, add_indexes=False):
    xbmc.log("{} : show_items. Total items: {}".format(__plugin__,
                                                       str(len(items))))
    # Fill list with items
    for index, item in enumerate(items, 1):
        title = item["title"].encode("utf-8")
        title = "{}. {}".format(index, title) if add_indexes else title
        li = ExtendedListItem(title,
                              poster=item["posters"]["big"],
                              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": mediatype_map[item["type"]]
            })
        # If not serials or multiseries movie, create playable item
        if item["type"] not in ["serial", "docuserial", "tvshow"
                                ] and not item["subtype"]:
            watching_info = KinoPubClient("watching").get(
                data={"id": item["id"]})["item"]["videos"][0]
            video_info.update({
                "time": watching_info["time"],
                "duration": watching_info["duration"],
                "playcount": watching_info["status"],
            })
            video_info = {
                "time": watching_info["time"],
                "duration": watching_info["duration"],
                "playcount": watching_info["status"],
            }
            link = get_internal_link("play",
                                     id=item["id"],
                                     title=title,
                                     video_info=json.dumps(video_info),
                                     poster=item["posters"]["big"])
            li.setProperty("isPlayable", "true")
            li.setResumeTime(watching_info["time"], watching_info["duration"])
            isdir = False
        elif item["subtype"] == "multi":
            watching_info = KinoPubClient("watching").get(
                data={"id": item["id"]})["item"]
            li.setProperty("subtype", "multi")
            video_info.update({"playcount": watching_info["status"]})
            link = get_internal_link("view_episodes", id=item["id"])
            isdir = True
        else:
            link = get_internal_link("view_seasons", id=item["id"])
            isdir = True
        li.setInfo("video", video_info)
        li.addPredefinedContextMenuItems()
        xbmcplugin.addDirectoryItem(request.handle, link, li, isdir)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)