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 55dbf25 commit 0da48c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
14 changes: 6 additions & 8 deletions pystream/models/squire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_

Expand Down
11 changes: 8 additions & 3 deletions pystream/routers/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 0da48c9

Please sign in to comment.