Ejemplo n.º 1
0
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)
Ejemplo n.º 2
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)
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)
        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)
Ejemplo n.º 4
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.º 5
0
def update_device_info(force=False):
    from client import KinoPubClient
    # Update device info
    deviceInfoUpdate = __settings__.getSetting("device_info_update")
    if force or not deviceInfoUpdate or int(deviceInfoUpdate) + 1800 < int(time.time()):
        infoLabels = [
            '"System.BuildVersion"',
            '"System.FriendlyName"',
            '"System.KernelVersion"'
        ]
        result = "Busy"
        payload = {
            "jsonrpc": "2.0",
            "method": "XBMC.GetInfoLabels",
            "id": 1,
            "params": {"labels": [",".join(infoLabels)]}
        }
        while "Busy" in result:
            result = xbmc.executeJSONRPC(json.dumps(payload))
        result = json.loads(result)["result"]
        title = result.get("System.FriendlyName")
        hardware = result.get("System.KernelVersion")
        software = "Kodi/{}".format(result.get("System.BuildVersion"))
        KinoPubClient("device/notify").post(data={
            "title": title,
            "hardware": hardware,
            "software": software
        })
        __settings__.setSetting("device_info_update", str(int(float(time.time()))))
Ejemplo n.º 6
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.º 7
0
def update_device_info(force=False):
    from client import KinoPubClient
    # Update device info
    deviceInfoUpdate = __settings__.getSetting("device_info_update")
    if force or not deviceInfoUpdate or int(deviceInfoUpdate) + 1800 < int(
            time.time()):
        result = {"build_version": "Busy", "friendly_name": "Busy"}
        while "Busy" in result.values():
            result = {
                "build_version": xbmc.getInfoLabel("System.BuildVersion"),
                "friendly_name": xbmc.getInfoLabel("System.FriendlyName")
            }
        software = "Kodi {}".format(result["build_version"].split()[0])
        KinoPubClient("device/notify").post(
            data={
                "title": result["friendly_name"],
                "hardware": platform.machine(),
                "software": software
            })
        __settings__.setSetting("device_info_update",
                                str(int(float(time.time()))))
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 def markAdvert(self, has_advert):
     if __settings__.getSetting("mark_advert") == "true" and has_advert:
         self.setLabel("{} (!)".format(self.getLabel()))
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-
from collections import namedtuple

from addonutils import get_internal_link
from data import __settings__

MainMenuItem = namedtuple("MainMenuItem",
                          ["title", "link", "is_dir", "is_displayed"])

main_menu_items = [
    MainMenuItem("Поиск", get_internal_link("search", type=None), False,
                 eval(__settings__.getSetting("show_search").title())),
    MainMenuItem("Закладки", get_internal_link("bookmarks"), True, True),
    MainMenuItem("Я смотрю", get_internal_link("watching"), True, True),
    MainMenuItem("Недосмотренные", get_internal_link("watching_movies"), True,
                 True),
    MainMenuItem("Последние", get_internal_link("items", type=None), True,
                 eval(__settings__.getSetting("show_last").title())),
    MainMenuItem("Популярные",
                 get_internal_link("items", type=None, shortcut="/popular"),
                 True, eval(__settings__.getSetting("show_popular").title())),
    MainMenuItem("Горячие",
                 get_internal_link("items", type=None, shortcut="/hot"), True,
                 eval(__settings__.getSetting("show_hot").title())),
    MainMenuItem("ТВ", get_internal_link("tv"), True,
                 eval(__settings__.getSetting("show_tv").title())),
    MainMenuItem("Подборки", get_internal_link("collections"), True,
                 eval(__settings__.getSetting("show_collections").title()))
]