Skip to content

Commit

Permalink
Avoid letting subtitle files ruining navigation buttons
Browse files Browse the repository at this point in the history
Have different naming convention for navigation button links and titles
  • Loading branch information
dormant-user committed Jan 28, 2024
1 parent 4a887a1 commit 01d6f75
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 7 additions & 5 deletions pystream/models/squire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down
11 changes: 8 additions & 3 deletions pystream/routers/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pystream/templates/land.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ <h1>{{ video_title }}</h1>
</p>
</video>
{% if previous %}
<button class="iter" style="float: left" onclick="window.location='{{ previous }}'" title="{{ previous }}">
<button class="iter" style="float: left" onclick="window.location='{{ previous }}'" title="{{ previous_title }}">
<i class="fa fa-backward"></i> Previous
</button>
{% endif %}
{% if next %}
<button class="iter" style="float: right" onclick="window.location='{{ next }}'" title="{{ next }}">
<button class="iter" style="float: right" onclick="window.location='{{ next }}'" title="{{ next_title }}">
Next <i class="fa fa-forward"></i>
</button>
{% endif %}
Expand Down

0 comments on commit 01d6f75

Please sign in to comment.