From 0da48c97367cb527d533a594c609e2909ed88e89 Mon Sep 17 00:00:00 2001
From: thevickypedia
Date: Sun, 28 Jan 2024 10:29:14 -0600
Subject: [PATCH] Avoid letting subtitle files ruining navigation buttons Have
different naming convention for navigation button links and titles
---
pystream/models/squire.py | 14 ++++++--------
pystream/routers/video.py | 11 ++++++++---
pystream/templates/land.html | 4 ++--
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/pystream/models/squire.py b/pystream/models/squire.py
index b817dfb..a36bed5 100644
--- a/pystream/models/squire.py
+++ b/pystream/models/squire.py
@@ -3,7 +3,6 @@
import re
import secrets
from typing import Dict, List, Tuple, Union
-from urllib import parse as urlparse
from fastapi import Request
from fastapi.templating import Jinja2Templates
@@ -98,17 +97,16 @@ 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))
+ 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_ = urlparse.quote(dir_content[idx - 1])
- assert pathlib.PosixPath(previous_).suffix in config.env.file_formats
- except (IndexError, AssertionError):
+ previous_ = dir_content[idx - 1]
+ except IndexError:
previous_ = None
try:
- next_ = urlparse.quote(dir_content[idx + 1])
- assert pathlib.PosixPath(next_).suffix in config.env.file_formats
- except (IndexError, AssertionError):
+ next_ = dir_content[idx + 1]
+ except IndexError:
next_ = None
return previous_, next_
diff --git a/pystream/routers/video.py b/pystream/routers/video.py
index ecbf087..fc1662c 100644
--- a/pystream/routers/video.py
+++ b/pystream/routers/video.py
@@ -94,13 +94,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 %}
-