diff --git a/server/app.py b/server/app.py index d3923c2..92ff473 100644 --- a/server/app.py +++ b/server/app.py @@ -21,6 +21,7 @@ from typing import ( List, Mapping, Optional, + Sequence, Set, Type, TypeVar, @@ -246,6 +247,11 @@ def encode_options(opts: Mapping[str, Any]) -> str: return urlencode({k: str(v) for k, v in opts.items()}, quote_via=quote_plus) +@flask_app.template_filter() +def first_and_only(list: Sequence[T]) -> Optional[T]: + return list[0] if len(list) == 1 else None + + @flask_app.template_global() def this_url(changed_args: Mapping[str, str] = {}) -> str: if request.endpoint is None: diff --git a/server/templates/macros.htm b/server/templates/macros.htm index 3436d2c..160fecc 100644 --- a/server/templates/macros.htm +++ b/server/templates/macros.htm @@ -388,6 +388,9 @@ alt="Thumbnail for {{ element.title }}" loading="lazy" /> + {% if link == None %} + {% set link = element.detected_playlists | list | first_and_only %} + {% endif %} {% if link and (link.season or link.episode) %}