Пример #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)
Пример #2
0
def toggle_watchlist(**kwargs):
    added = int(kwargs.pop("added"))
    KinoPubClient("watching/togglewatchlist").get(data=kwargs)
    if added:
        notice('Сериал добавлен в список "Буду смотреть"')
    else:
        notice('Сериал удалён из списка "Буду смотреть"')
Пример #3
0
def toggle_watchlist(**kwargs):
    added = int(kwargs.pop("added"))
    KinoPubClient("watching/togglewatchlist").get(data=kwargs)
    if added:
        notice('Сериал добавлен в список "Буду смотреть"')
    else:
        notice('Сериал удалён из списка "Буду смотреть"')
    xbmc.executebuiltin("Container.Refresh")
Пример #4
0
def search(type=None):
    kbd = xbmc.Keyboard()
    kbd.setHeading("Поиск")
    kbd.doModal()
    if kbd.isConfirmed():
        title = kbd.getText()
        if len(title.decode("utf-8")) >= 3:
            nav_internal_link("items", title=title, type=type)
        else:
            notice("Введите больше символов для поиска", "Поиск")
Пример #5
0
def search(page=None, type=None):
    kbd = xbmc.Keyboard()
    kbd.setDefault("")
    kbd.setHeading("Поиск")
    kbd.doModal()
    out = ""
    if kbd.isConfirmed():
        out = kbd.getText()
        if len(out.decode("utf-8")) >= 3:
            if "page" is not None:
                page = 1
            nav_internal_link("items", page=page, title=out, type=type)
        else:
            notice("Введите больше символов для поиска", "Поиск")
Пример #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)
Пример #7
0
 def do_login(self):
     xbmc.log("{}: No access_token. Show modal auth".format(__plugin__))
     status, resp = self.get_device_code()
     if status == self.ERROR:
         notice("Код ответа сервера {}".format(resp["status"]),
                heading="Неизвестная ошибка")
         nav_internal_link("/")
         return
     self.window.show("\n".join([
         "Откройте [B]{}[/B]".format(
             resp["verification_uri"].encode("utf-8")),
         "и введите следующий код: [B]{}[/B]".format(
             resp["user_code"].encode("utf-8"))
     ]))
     self.verify_device_code(int(resp["interval"]))
     xbmc.log("{}: Close modal auth".format(__plugin__))
Пример #8
0
def edit_bookmarks(item_id=None):
    item_folders_resp = KinoPubClient("bookmarks/get-item-folders").get(
        data={"item": item_id})
    all_folders_resp = KinoPubClient("bookmarks").get()
    all_folders = [f["title"] for f in all_folders_resp["items"]]
    item_folders = [f["title"] for f in item_folders_resp["folders"]]
    preselect = [all_folders.index(f) for f in item_folders]
    dialog = xbmcgui.Dialog()
    indexes = dialog.multiselect("Папки закладок",
                                 all_folders,
                                 preselect=preselect)
    # Cancel button was pressed
    if indexes is None:
        return
    chosen_folders = [all_folders[i] for i in indexes]
    folders_to_add = list(set(chosen_folders) - set(item_folders))
    folders_to_remove = list(set(item_folders) - set(chosen_folders))
    # Ok button was pressed but nothing changed
    if not folders_to_add and not folders_to_remove:
        return

    def get_folder_id(title):
        for folder in all_folders_resp["items"]:
            if folder["title"] == title:
                return folder["id"]

    for folder in folders_to_add:
        KinoPubClient("bookmarks/add").post(data={
            "item": item_id,
            "folder": get_folder_id(folder)
        })
    for folder in folders_to_remove:
        KinoPubClient("bookmarks/remove-item").post(
            data={
                "item": item_id,
                "folder": get_folder_id(folder)
            })
    notice("Закладки для видео изменены")
    xbmc.executebuiltin("Container.Refresh")
Пример #9
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)
Пример #10
0
 def _make_request(self, request, timeout=600):
     request.add_header("Authorization",
                        "Bearer {}".format(auth.access_token))
     try:
         response = urllib2.urlopen(request, timeout=timeout)
     except urllib2.HTTPError as e:
         xbmc.log("{}. HTTPError. Code: {}. Message: {}".format(
             __plugin__, e.code, e.message),
                  level=xbmc.LOGERROR)
         if e.code in [400, 401]:
             status, __ = auth.get_token(refresh=True)
             if status != auth.SUCCESS:
                 # reset access_token
                 auth.reauth()
             if auth.access_token:
                 return self._make_request(request)
             sys.exit()
         else:
             notice("Код ответа сервера {}".format(e.code),
                    "Неизвестная ошибка")
     except Exception as e:
         xbmc.log("{}. {}. Message: {}".format(__plugin__,
                                               e.__class__.__name__,
                                               e.message),
                  level=xbmc.LOGERROR)
         notice(e.message, "Ошибка")
     else:
         response = json.loads(response.read())
         if response["status"] == 200:
             return response
         else:
             xbmc.log("{}. Unknown error. Code: {}".format(
                 __plugin__, response["status"]),
                      level=xbmc.LOGERROR)
             notice("Код ответа сервера {}".format(response["status"]),
                    "Неизвестная ошибка")