Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def tv():
    response = KinoPubClient("tv/index").get()
    for ch in response["channels"]:
        li = ExtendedListItem(ch["title"].encode("utf-8"),
                              iconImage=ch["logos"]["s"])
        xbmcplugin.addDirectoryItem(request.handle, ch["stream"], li, False)
    xbmcplugin.endOfDirectory(request.handle)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def genres(type):
    response = KinoPubClient("genres").get(data={"type": type})
    add_default_headings(type)
    for genre in response["items"]:
        li = ExtendedListItem(genre["title"].encode("utf-8"))
        link = get_internal_link("items", type=type, genre=genre["id"])
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    xbmcplugin.endOfDirectory(request.handle)
Exemplo n.º 7
0
def show_pagination(pagination, action, **kwargs):
    # Add "next page" button
    if pagination and (int(pagination["current"]) + 1 <= int(
            pagination["total"])):
        kwargs["page"] = int(pagination["current"]) + 1
        li = ExtendedListItem("[COLOR FFFFF000]Вперёд[/COLOR]")
        link = get_internal_link(action, **kwargs)
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    xbmcplugin.endOfDirectory(request.handle)
Exemplo n.º 8
0
def collections(sort=None, page=None):
    response = KinoPubClient("collections/index").get(data={
        "sort": sort,
        "page": page
    })
    xbmcplugin.setContent(request.handle, "movies")
    li = ExtendedListItem("Последние")
    link = get_internal_link("collections", sort="-created")
    xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    li = ExtendedListItem("Просматриваемые")
    link = get_internal_link("collections", sort="-watchers")
    xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    li = ExtendedListItem("Популярные")
    link = get_internal_link("collections", sort="-views")
    xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    for item in response["items"]:
        li = ExtendedListItem(item["title"].encode("utf-8"),
                              thumbnailImage=item["posters"]["medium"])
        link = get_internal_link("collection_view", id=item["id"])
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    show_pagination(response["pagination"], "collections", sort=sort)
Exemplo n.º 9
0
def alphabet(type):
    alpha = [
        "А,Б,В,Г,Д,Е,Ё,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ы,Э,Ю,Я",
        "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
    ]
    for al in alpha:
        letters = al.split(",")
        for letter in letters:
            li = ExtendedListItem(letter)
            link = get_internal_link("items", type=type, letter=letter)
            xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    xbmcplugin.endOfDirectory(request.handle)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
def add_default_headings(type=None, fmt="slp"):
    # fmt - show format
    # s - show search
    # l - show last
    # p - show popular
    # s - show alphabet sorting
    # g - show genres folder
    # h - show hot

    if "s" in fmt:
        li = ExtendedListItem("Поиск")
        link = get_internal_link("search", type=type)
        xbmcplugin.addDirectoryItem(request.handle, link, li, False)
    if "l" in fmt:
        li = ExtendedListItem("Последние")
        link = get_internal_link("items", type=type)
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    if "p" in fmt:
        li = ExtendedListItem("Популярные")
        link = get_internal_link("items", type=type, shortcut="/popular")
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    if "a" in fmt:
        li = ExtendedListItem("По алфавиту")
        link = get_internal_link("alphabet", type=type)
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    if "g" in fmt:
        li = ExtendedListItem("Жанры")
        link = get_internal_link("genres", type=type)
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    if "h" in fmt:
        li = ExtendedListItem("Горячие")
        link = get_internal_link("items", type=type, shortcut="/hot")
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
Exemplo n.º 12
0
def bookmarks(folder_id=None, page=None):
    if folder_id is None:
        li = ExtendedListItem("Создать папку")
        link = get_internal_link("create_bookmarks_folder")
        xbmcplugin.addDirectoryItem(request.handle, link, li, False)
        response = KinoPubClient("bookmarks").get()
        for folder in response["items"]:
            li = ExtendedListItem(folder["title"].encode("utf-8"),
                                  properties={
                                      "folder-id":
                                      str(folder["id"]).encode("utf-8"),
                                      "views":
                                      str(folder["views"]).encode("utf-8")
                                  })
            remove_link = get_internal_link("remove_bookmarks_folder",
                                            folder_id=folder["id"])
            li.addContextMenuItems([
                ("Удалить", "Container.Update({})".format(remove_link))
            ])
            link = get_internal_link("bookmarks", folder_id=folder["id"])
            xbmcplugin.addDirectoryItem(request.handle, link, li, True)
        xbmcplugin.endOfDirectory(request.handle)
    else:
        # Show content of the folder
        response = KinoPubClient(
            "bookmarks/{}".format(folder_id)).get(data={"page": page})
        xbmcplugin.setContent(request.handle, "videos")
        show_items(response["items"])
        show_pagination(response["pagination"],
                        "bookmarks",
                        folder_id=folder_id)
Exemplo n.º 13
0
def index():
    """Main screen - show type list"""
    if not auth.access_token:
        li = ExtendedListItem("Активировать устройство")
        xbmcplugin.addDirectoryItem(request.handle, get_internal_link("login"),
                                    li, False)
    else:
        response = KinoPubClient("types").get()
        li = ExtendedListItem("Профиль")
        xbmcplugin.addDirectoryItem(request.handle,
                                    get_internal_link("profile"), li, False)
        for menu_item in main_menu_items:
            if menu_item.is_displayed:
                li = ExtendedListItem(menu_item.title)
                xbmcplugin.addDirectoryItem(request.handle, menu_item.link, li,
                                            menu_item.is_dir)
        for i in response["items"]:
            if __settings__.getSetting("show_{}".format(i["id"])) != "false":
                li = ExtendedListItem(i["title"].encode("utf-8"))
                link = get_internal_link("item_index", type=i["id"])
                xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    xbmcplugin.endOfDirectory(request.handle)
Exemplo n.º 14
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)
Exemplo n.º 15
0
def watching():
    response = KinoPubClient("watching/serials").get(data={"subscribed": 1})
    xbmcplugin.setContent(request.handle, "tvshows")
    for item in response["items"]:
        title = "{} : [COLOR FFFFF000]+{}[/COLOR]".format(
            item["title"].encode("utf-8"), str(item["new"]))
        li = ExtendedListItem(
            title,
            str(item["new"]),
            poster=item["posters"]["big"],
            properties={
                "id": str(item["id"]),
                "in_watchlist": "1"
            },
            video_info={"mediatype": mediatype_map[item["type"]]},
            addContextMenuItems=True)
        link = get_internal_link("view_seasons", id=item["id"])
        xbmcplugin.addDirectoryItem(request.handle, link, li, True)
    xbmcplugin.endOfDirectory(request.handle)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)