コード例 #1
0
def root():
    menu_items = []

    for label, query in kinoman_api.list_categories_video_menu():
        menu_items.append({
            "label": label,
            "path": path_for("list_movies", query=query),
            "is_folder": True,
        })

    search_icon = {"art": {"icon": "DefaultAddonsSearch.png"}}

    menu_items.append({
        "label": "Поиск по фильтру",
        "path": path_for("search_filter"),
        "video_data": search_icon,
        "is_folder": True,
    })

    if player.get_setting("search_history_status",
                          "bool") and player.get_setting(
                              "_search_history", "list"):
        search_endpoint = "search_history"
    else:
        search_endpoint = "search"

    menu_items.append({
        "label": "Поиск",
        "path": path_for(search_endpoint),
        "video_data": search_icon,
        "is_folder": True,
    })

    player.print_items(menu_items, cache=False)
コード例 #2
0
def search_filter(query=None, step=0):
    if query is None:
        query = {}

    step_menu_generators = [
        kinoman_api.gen_categories_video,
        kinoman_api.gen_categories_age,
        kinoman_api.gen_categories_genre,
        kinoman_api.gen_categories_year,
    ]

    menu_items = []
    for item_label, item_query in step_menu_generators[step]():
        query.update(item_query)

        if step == len(step_menu_generators) - 1:
            menu_items.append({
                "label": item_label,
                "path": path_for("list_movies", query=query),
                "is_folder": True,
            })
        else:
            menu_items.append({
                "label":
                item_label,
                "path":
                path_for("search_filter",
                         path_vars={"step": step + 1},
                         query=query),
                "is_folder":
                True,
            })

    player.print_items(menu_items)
コード例 #3
0
def search_history():
    if not player.get_setting("search_history_status", "bool"):
        search_clear()

    search_icon = {"art": {"icon": "DefaultAddonsSearch.png"}}
    clear_icon = {"art": {"icon": "DefaultAddonNone.png"}}

    menu_items = [
        {
            "label": "Новый поиск",
            "path": path_for("search"),
            "video_data": search_icon,
            "is_folder": True,
        },
        {
            "label": "Очистить",
            "path": path_for("search_clear"),
            "video_data": clear_icon,
            "is_folder": True,
        },
    ]

    history = player.get_setting("_search_history", "list")

    for search_term in reversed(history):
        menu_items.append({
            "label":
            search_term,
            "path":
            path_for("search", path_vars={"s_query": search_term}),
            "is_folder":
            True,
        })

    player.print_items(menu_items)
コード例 #4
0
def list_movies(query):
    if "q" not in query:
        query["page"] = int(query.get("page", 1))

    items = []

    for title, video_id, video_data in kinoman_api.get_movies(query.copy()):
        if title.startswith("-->"):
            query["page"] += 1
            item_path = path_for("list_movies", query=query)
        else:
            item_path = path_for("open_movie",
                                 path_vars={"video_id": video_id})

        items.append({
            "label": title,
            "path": item_path,
            "video_data": video_data,
            "is_folder": True,
        })

    player.print_items(items, content_type="movies")
コード例 #5
0
def open_movie(video_id, video_dir=None):
    movie_data = kinoman_api.get_movie_data(video_id)

    if movie_data["series_season_n"] is not None and video_dir is not None:
        content_type = "episodes"
    else:
        content_type = "movies"

    items = []
    for (
            video_type,
            file_name,
            title,
            url,
            series,
            file_info,
    ) in kinoman_api.get_movie_files_list(movie_data["file_lists"], video_dir,
                                          movie_data["series_season_n"]):

        if url.startswith("http"):
            url_play = path_for(
                "play",
                path_vars={
                    "video_id": video_id,
                    "video_type": video_type,
                    "video_name": file_name,
                },
            )
            is_playable = True
        else:
            url_play = path_for("open_movie",
                                path_vars={
                                    "video_id": video_id,
                                    "video_dir": url
                                })
            is_playable = False

        # Gather all unique data into update dictionary
        data_update = {}
        if series:
            data_update = series.copy()
        if file_info:
            data_update["plot"] = ("[B]" + file_info + "[/B][CR][CR]" +
                                   movie_data["movie_info"]["info"]["plot"])

        # Check if there is unique data and create deep copy of movie info to update,
        # so that every entry could have unique data
        if data_update:
            movie_data_alt = deepcopy(movie_data["movie_info"])
            movie_data_alt["info"].update(data_update)
        else:
            movie_data_alt = movie_data["movie_info"]

        items.append({
            "label": title,
            "path": url_play,
            "is_playable": is_playable,
            "is_folder": not is_playable,
            "video_data": movie_data_alt,
        })

    return player.print_items(items, content_type=content_type)
コード例 #6
0
def search_clear():
    player.set_setting("_search_history", "")
    player.redirect_in_place(path_for("root"))
コード例 #7
0
 def test_exception_no_functions(self):
     with self.assertRaisesRegexp(
             ValueError, r"^No functions registered for endpoint .*"):
         router.path_for("test_function_nonexistent")
コード例 #8
0
 def test_exception_bad_args_type(self):
     with self.assertRaisesRegexp(
             ValueError,
             r"^Variable .* has wrong variable type for function .*"):
         router.path_for("test_function_args", path_vars={"page": None})
コード例 #9
0
 def test_exception_bad_function_params(self):
     with self.assertRaisesRegexp(
             ValueError, r"^Function .* does not have parameters: .*"):
         router.path_for("test_function_root",
                         path_vars={"non_existing_param": None})
コード例 #10
0
 def test_exception_ambiguous_function_params(self):
     with self.assertRaisesRegexp(
             ValueError,
             r"^Ambiguous paths for .* with this set of variables"):
         router.path_for("test_function_ambiguous")
コード例 #11
0
 def test_exception_bad_query(self):
     with self.assertRaisesRegexp(ValueError,
                                  r"query must be a dictionary"):
         router.path_for("test_function_root", query=[])
コード例 #12
0
 def test_exception_bad_vars(self):
     with self.assertRaisesRegexp(ValueError,
                                  r"path_vars must be a dictionary"):
         router.path_for("test_function_root", path_vars=[])
コード例 #13
0
 def test_good_paths_for_args(self):
     good_path = router.path_for("test_function_args",
                                 path_vars={"page": 10})
     self.assertEqual(good_path, "/movies/page/10")
コード例 #14
0
 def test_good_paths_for_query(self):
     good_path = router.path_for("test_function_root",
                                 query={"test": "test"})
     self.assertEqual(good_path, "/?test=test")
コード例 #15
0
 def test_good_paths_for(self):
     good_path = router.path_for("test_function_root")
     self.assertEqual(good_path, "/")