From d432390596e76614ed4f498b61a88a9db3048359 Mon Sep 17 00:00:00 2001 From: thevickypedia Date: Sun, 28 Jan 2024 10:48:27 -0600 Subject: [PATCH] Avoid letting subtitle files ruining navigation buttons Have different naming convention for navigation button links and titles --- pystream/models/squire.py | 12 +++++++----- pystream/routers/video.py | 11 ++++++++--- pystream/templates/land.html | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pystream/models/squire.py b/pystream/models/squire.py index 837e2c7..cd0177c 100644 --- a/pystream/models/squire.py +++ b/pystream/models/squire.py @@ -96,17 +96,19 @@ def get_iter(filename: pathlib.PurePath) -> Union[Tuple[str, str], Tuple[None, N Tuple[str, str]: Tuple of previous file and next file. """ - dir_content = sorted(os.listdir(filename.parent), key=lambda x: natural_sort_key(x)) + # Extract only the file formats that are supported + dir_content = sorted( + (file for file in os.listdir(filename.parent) if pathlib.PosixPath(file).suffix in config.env.file_formats), + key=lambda x: natural_sort_key(x) + ) idx = dir_content.index(filename.name) try: previous_ = dir_content[idx - 1] - assert pathlib.PosixPath(previous_).suffix in config.env.file_formats - except (IndexError, AssertionError): + except IndexError: previous_ = None try: next_ = dir_content[idx + 1] - assert pathlib.PosixPath(next_).suffix in config.env.file_formats - except (IndexError, AssertionError): + except IndexError: next_ = None return previous_, next_ diff --git a/pystream/routers/video.py b/pystream/routers/video.py index b023dab..8c1ef71 100644 --- a/pystream/routers/video.py +++ b/pystream/routers/video.py @@ -92,13 +92,18 @@ async def stream_video(request: Request, } ) if pure_path.exists(): - prev_, next_ = squire.get_iter(pure_path) attrs = { "request": request, "video_title": video_path, "home": config.static.home_endpoint, "logout": config.static.logout_endpoint, - "path": f"{config.static.streaming_endpoint}?{config.static.query_param}={urlparse.quote(str(pure_path))}", - "previous": prev_, "next": next_ + "path": f"{config.static.streaming_endpoint}?{config.static.query_param}={urlparse.quote(str(pure_path))}" } + prev_, next_ = squire.get_iter(pure_path) + if prev_: + attrs["previous"] = urlparse.quote(prev_) + attrs["previous_title"] = prev_ + if next_: + attrs["next"] = urlparse.quote(next_) + attrs["next_title"] = next_ # set default to avoid broken image sign in thumbnail preview_src = os.path.join(pathlib.PurePath(__file__).parent, "blank.jpg") if config.env.auto_thumbnail: diff --git a/pystream/templates/land.html b/pystream/templates/land.html index 9219eb3..16ea9d4 100644 --- a/pystream/templates/land.html +++ b/pystream/templates/land.html @@ -129,12 +129,12 @@

{{ video_title }}

{% if previous %} - {% endif %} {% if next %} - {% endif %}