From 4866901159d34f39ad7f3f88f8dfab7c5ef45833 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 6 Nov 2022 14:57:45 +0100 Subject: [PATCH] thumbnail view: Search for collection link if requested - uses one found, if only one was found to prevent issues when multiple would be possible --- server/app.py | 6 ++++++ server/templates/macros.htm | 3 +++ 2 files changed, 9 insertions(+) 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) %}