Example #1
0
def section():
    # type: () -> None
    """Show section menus and playable items"""
    idx = get_arg("idx", False)
    href = get_arg("href", False)
    category = get_arg("category")
    offset = get_arg("offset", 0)
    if idx:
        # Section menu
        url = locs.get_search_url(idx, page=offset)
        data = locs.get_json(url)
        paginate(data.get("pagination"), category, idx)
        for data in data.get("facets", [{}])[0].get("filters"):
            title = data.get("title").title()
            count = data.get("count")
            add_menu_item(section, "{} [{} items]".format(title, count), {
                "href": data.get("on"),
                "category": title
            })
    if href:
        # Playable items
        data = locs.get_json(href)
        parse_search_results(data, category)
        xbmcplugin.setContent(plugin.handle, "videos")
    xbmcplugin.setPluginCategory(plugin.handle, category)
    xbmcplugin.endOfDirectory(plugin.handle)
Example #2
0
def section():
    # type: () -> None
    """Show section menus and playable items"""
    idx = get_arg("idx")
    category = get_arg("category")
    page = int(get_arg("page", 1))
    offset = int(get_arg("offset", 0))
    url = pas.get_list_url(idx)
    data = pas.get_json(url)
    results = data.get("options")
    # Section paging
    if len(results) > pas.SEARCH_MAX_RESULTS:
        np = page + 1
        logger.warning("FOOOO start:{} end:{}".format(offset, pas.SEARCH_MAX_RESULTS + offset))
        add_menu_item(section, "[{} {}]".format(ku.localize(32011), np),
                      args={"idx": idx, "page": np, "offset": page * pas.SEARCH_MAX_RESULTS, "category": category})
        results = results[offset:pas.SEARCH_MAX_RESULTS + offset]
    # Section menu
    for data in results:
        val = data.get("val")
        title = data.get("txt", str(val)) \
            if isinstance(val, int) \
            else val.title().encode("utf-8")
        total = data.get("n")
        add_menu_item(search,
                      "{} [{} items]".format(title, total),
                      args={"href": pas.get_section_url(idx, val), "category": title, "total": total})
    xbmcplugin.setPluginCategory(plugin.handle, category)
    xbmcplugin.endOfDirectory(plugin.handle)
Example #3
0
def recent():
    # type: () -> None
    """Show recently viewed films"""
    data = locs.recents.retrieve()
    for href in data:
        data = locs.get_json(href)
        add_menu_item(play_film,
                      data.get("item",
                               {}).get("title").title(), {"href": href},
                      locs.get_art(data), locs.get_info(data), False)
    xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32005))  # Recent
    xbmcplugin.endOfDirectory(plugin.handle)
Example #4
0
def play_film():
    # type: () -> None
    """Show playable item"""
    href = get_arg("href")
    data = locs.get_json(href)
    url = locs.get_video_url(data)
    if not url:
        logger.debug("play_film error: {}".format(href))
        return
    locs.recents.append(href)
    list_item = ListItem(path=url)
    list_item.setInfo("video", locs.get_info(data))
    xbmcplugin.setResolvedUrl(plugin.handle, True, list_item)
def search():
    # type: () -> Optional[bool]
    """Search the archive"""
    query = get_arg("q")
    category = get_arg("category", ku.localize(32007))  # Search
    # Remove saved search item
    if bool(get_arg("delete", False)):
        nfpfs.searches.remove(query)
        xbmc.executebuiltin("Container.Refresh()")
        return True
    # View saved search menu
    if bool(get_arg("menu", False)):
        add_menu_item(search,
                      "[{}]".format(ku.localize(32016)),
                      args={"new": True})  # [New Search]
        for item in nfpfs.searches.retrieve():
            text = item.encode("utf-8")
            add_menu_item(search,
                          text,
                          args={
                              "q":
                              text,
                              "category":
                              "{} '{}'".format(ku.localize(32007), text)
                          })
        xbmcplugin.setPluginCategory(plugin.handle, category)
        xbmcplugin.endOfDirectory(plugin.handle)
        return True
    # New look-up
    if bool(get_arg("new", False)):
        query = ku.user_input()
        if not query:
            return False
        category = "{} '{}'".format(ku.localize(32007), query)
        if nfpfs.SEARCH_SAVED:
            nfpfs.searches.append(query)
    # Process search
    parse_search_results(nfpfs.get_json(nfpfs.NFPF_VIDEOS_URI), query)
    xbmcplugin.addSortMethod(plugin.handle,
                             xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_GENRE)
    xbmcplugin.setPluginCategory(plugin.handle, category)
    xbmcplugin.endOfDirectory(plugin.handle)
Example #6
0
def search():
    # type: () -> Optional[bool]
    """Search the archive"""
    query = get_arg("q")
    offset = int(get_arg("offset", 0))
    # remove saved search item
    if bool(get_arg("delete", False)):
        bfis.searches.remove(query)
        xbmc.executebuiltin("Container.Refresh()")
        return True
    # View saved search menu
    if bool(get_arg("menu", False)):
        add_menu_item(search,
                      "[{}]".format(ku.localize(32016)),
                      args={"new": True})  # [New Search]
        for item in bfis.searches.retrieve():
            add_menu_item(search, item, args={"q": item})
        xbmcplugin.setPluginCategory(plugin.handle,
                                     ku.localize(32007))  # Search
        xbmcplugin.endOfDirectory(plugin.handle)
        return True
    # look-up
    if bool(get_arg("new", False)):
        query = ku.user_input()
        if not query:
            return False
        if bfis.SEARCH_SAVED:
            bfis.searches.append(query)
    # process results
    search_url = bfis.get_search_url(query, offset)
    data = bfis.get_json(search_url)
    parse_search_results(data, query, offset)
    xbmcplugin.setPluginCategory(
        plugin.handle, "{} '{}'".format(ku.localize(32007),
                                        bfis.query_decode(query)))
    xbmcplugin.setContent(plugin.handle, "videos")
    xbmcplugin.addSortMethod(plugin.handle,
                             xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_GENRE)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
    xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION)
    xbmcplugin.endOfDirectory(plugin.handle)
Example #7
0
def search():
    # type: () -> Optional[bool]
    """Search the archive"""
    query = get_arg("q")
    category = get_arg("category", ku.localize(32007))  # Search
    # Remove saved search item
    if bool(get_arg("delete", False)):
        locs.searches.remove(query)
        xbmc.executebuiltin("Container.Refresh()")
        return True
    # View saved search menu
    if bool(get_arg("menu", False)):
        add_menu_item(search, "[{}]".format(ku.localize(32016)),
                      {"new": True})  # [New Search]
        for item in locs.searches.retrieve():
            text = item.encode("utf-8")
            add_menu_item(
                search, text, {
                    "q": text,
                    "category": "{} '{}'".format(ku.localize(32007), text)
                })
        xbmcplugin.setPluginCategory(plugin.handle, category)
        xbmcplugin.endOfDirectory(plugin.handle)
        return True
    # New look-up
    if bool(get_arg("new", False)):
        query = ku.user_input()
        if not query:
            return False
        category = "{} '{}'".format(ku.localize(32007), query)
        if locs.SEARCH_SAVED:
            locs.searches.append(query)
    # Process search
    url = locs.get_search_url(query=query)
    data = locs.get_json(url)
    parse_search_results(data, category)
    xbmcplugin.setPluginCategory(plugin.handle, category)
    xbmcplugin.endOfDirectory(plugin.handle)
Example #8
0
def search():
    query = get_arg("q")
    offset = int(get_arg("offset", 0))
    # remove saved search item
    if bool(get_arg("delete", False)):
        bfis.remove(query)
        xbmc.executebuiltin("Container.Refresh()")
        return True

    # View saved search menu
    if bool(get_arg("menu", False)):
        add_menu_item(search, "[{}]".format(ku.get_string(32016)),
                      {"new": True})  # [New Search]
        for item in bfis.retrieve():
            text = item.encode("utf-8")
            add_menu_item(search, text, {"q": text})
        xp.setPluginCategory(plugin.handle, ku.get_string(32007))  # Search
        xp.endOfDirectory(plugin.handle)
        return True

    # look-up
    if bool(get_arg("new", False)):
        query = ku.user_input()
        bfis.append(query)
        if not query:
            return False

    search_url = bfis.get_search_url(query, offset)
    data = bfis.get_json(search_url)
    if data is None:
        return False

    hits = data.get("hits", False)
    if not hits:
        return False

    # Results
    results = hits.get("hits", [])
    paginate(query, len(results), int(hits.get("total", 0)), offset)
    for element in results:
        data = element.get("_source", False)
        if not data:
            continue

        title = data.get("title", "")
        duration = data.get("duration", 0)  # can still be NoneType *
        info = {
            "originaltitle": data.get("original_title", ""),
            "plot": bfis.html_to_text(data.get("standfirst", "")),
            "genre": data.get("genre", ""),
            "cast": data.get("cast", ""),
            "director": data.get("director", ""),
            "year": int(data.get("release_date", 0)),
            "duration": 0 if duration is None else int(duration) * 60,  # *
            "mediatype": "video"
        }
        add_menu_item(play_film, title, {"href": data.get("url")},
                      ku.art(data.get("image", ["Default.png"])[0]), info,
                      False)
    xp.setContent(plugin.handle, "videos")
    xp.setPluginCategory(
        plugin.handle, "{} '{}'".format(ku.get_string(32007),
                                        bfis.query_decode(query)))
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE)
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE)
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_VIDEO_YEAR)
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_DURATION)
    xp.endOfDirectory(plugin.handle)
Example #9
0
def search():
    query = get_arg("q")
    offset = int(get_arg("offset", 0))
    # remove saved search item
    if bool(get_arg("delete", False)):
        bfis.remove(query)
        xbmc.executebuiltin("Container.Refresh()")
        return True

    # View saved search menu
    if bool(get_arg("menu", False)):
        add_menu_item(search, "[{}]".format(ku.get_string(32016)), {"new": True})  # [New Search]
        for item in bfis.retrieve():
            text = item.encode("utf-8")
            add_menu_item(search, text, {"q": text})
        xp.setPluginCategory(plugin.handle, ku.get_string(32007))  # Search
        xp.endOfDirectory(plugin.handle)
        return True

    # look-up
    if bool(get_arg("new", False)):
        query = ku.user_input()
        bfis.append(query)
        if not query:
            return False

    search_url = bfis.get_search_url(query, offset)
    data = bfis.get_json(search_url)
    if data is None:
        return False

    hits = data.get("hits", False)
    if not hits:
        return False

    # Results
    results = hits.get("hits", [])
    paginate(query,
             len(results),
             int(hits.get("total", 0)),
             offset)
    for element in results:
        data = element.get("_source", False)
        if not data:
            continue

        title = data.get("title", "")
        duration = data.get("duration", 0)  # can still be NoneType *
        info = {
            "originaltitle": data.get("original_title", ""),
            "plot": bfis.html_to_text(data.get("standfirst", "")),
            "genre": data.get("genre", ""),
            "cast": data.get("cast", ""),
            "director": data.get("director", ""),
            "year": int(data.get("release_date", 0)),
            "duration": 0 if duration is None else int(duration) * 60,  # *
            "mediatype": "video"
        }
        add_menu_item(
            play_film,
            title,
            {"href": data.get("url")},
            ku.art(data.get("image", ["Default.png"])[0]),
            info,
            False)
    xp.setContent(plugin.handle, "videos")
    xp.setPluginCategory(plugin.handle, "{} '{}'".format(ku.get_string(32007), bfis.query_decode(query)))
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE)
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE)
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_VIDEO_YEAR)
    xp.addSortMethod(plugin.handle, xp.SORT_METHOD_DURATION)
    xp.endOfDirectory(plugin.handle)