thumbnail view: Hide common trails on media titles in collections

master
Felix Stupp 2 years ago
parent 73343f0f82
commit 9fd314115a
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -66,6 +66,7 @@ from entertainment_decider.extractors.media import (
media_extract_uri,
media_update,
)
from entertainment_decider.extras import remove_common_trails
T = TypeVar("T")
@ -489,10 +490,16 @@ def show_collection(collection_id: int) -> ResponseReturnValue:
if orm.count(collection.media_links) <= SMALL_COLLECTION_MAX_COUNT
else None
)
media_titles = (
remove_common_trails([link.element.title for link in media_links])
if media_links is not None
else None
)
return render_template(
"collection_element.htm",
collection=collection,
media_links=media_links,
media_titles=media_titles,
)
@ -504,10 +511,12 @@ def show_collection_episodes(collection_id: int) -> ResponseReturnValue:
media_links = MediaCollectionLink.sorted(
MediaCollectionLink.select(lambda l: l.collection == collection)
)
media_titles = remove_common_trails([link.element.title for link in media_links])
return render_template(
"collection_episodes.htm",
collection=collection,
media_links=media_links,
media_titles=media_titles,
)

@ -1 +1,2 @@
from .chain import Chain
from .strings import remove_common_trails

@ -0,0 +1,40 @@
import re
from typing import Sequence
def common_prefix(elements: Sequence[str]) -> str:
if len(elements) <= 1:
return ""
test = re.compile(r"^[^\w]$")
s1 = min(elements)
s2 = max(elements)
i = 0
min_l = min(len(s1), len(s2))
if min_l <= 0:
return ""
for i in range(min_l):
if s1[i] != s2[i]:
break
else:
i += 1
while i > 0 and not test.match(s1[i - 1]):
i -= 1
return s1[:i]
def common_suffix(elements: Sequence[str]) -> str:
return common_prefix([s[::-1] for s in elements])[::-1]
def remove_prefix(elements: Sequence[str]) -> Sequence[str]:
pre = len(common_prefix(elements))
return [s[pre:] for s in elements]
def remove_suffix(elements: Sequence[str]) -> Sequence[str]:
suf = len(common_suffix(elements))
return [s[::-1][suf:][::-1] for s in elements]
def remove_common_trails(elements: Sequence[str]) -> Sequence[str]:
return remove_prefix(remove_suffix(elements))

@ -114,6 +114,7 @@
links=media_links,
check_considered=True,
link_collection=False,
titles=media_titles,
) }}
{% endif %}
</body>

@ -16,6 +16,7 @@
links=media_links,
check_considered=True,
link_collection=False,
titles=media_titles,
) }}
</body>
</html>

@ -384,6 +384,7 @@
check_considered=True,
is_considered=True,
link_collection=True,
title=None,
) %}
{% set element = link.element if link else element %}
<div class="thumbnail_entry" id="media_element_{{ element.id }}" title="{{ element.title }}">
@ -445,7 +446,7 @@
</span>
</div>
<a class="thumbnail_title" href="{{ element.info_link }}">
{{ element.title }}
{{ title or element.title }}
</a>
</div>
{%- endmacro %}
@ -455,6 +456,7 @@
links=None,
check_considered=True,
link_collection=True,
titles=None,
) %}
{%- set l = elements or links -%}
{%- set considered = (links|map(attribute="element") if links else elements)|map(attribute="id")|are_considered -%}
@ -467,6 +469,7 @@
check_considered=False,
is_considered=considered[elem.id] if check_considered else True,
link_collection=link_collection,
title=titles[loop.index0] if titles else None,
) }}
{% endfor %}
</div>

Loading…
Cancel
Save