Video watchlist: strip dirty titles when sorting (leading-space fix)

'Holy Marvels with Dennis Quaid' is stored with a leading space in the shows
table, so the watchlist sort key fell to ' holy marvels…' — and a leading space
sorts before 'a', jumping it to the top. .strip() the sort key so dirty titles
sort by their real first letter.
This commit is contained in:
BoulderBadgeDad 2026-06-21 08:52:49 -07:00
parent 49714a59ea
commit 5711963a6f
2 changed files with 10 additions and 6 deletions

View file

@ -2044,8 +2044,10 @@ class VideoDatabase:
if sort == "added": # opt-in: explicit follows (have a date) newest-first
items.sort(key=lambda it: (it.get("date_added") or ""), reverse=True)
else: # "default" / "title": alphabetical by name — a manual follow is no more
# special than an auto-added airing show, so they sort together AZ
items.sort(key=lambda it: (it.get("sort_title") or it.get("title") or "").lower())
# special than an auto-added airing show, so they sort together AZ.
# .strip() guards against dirty titles (e.g. a leading space from the
# scan, which would otherwise sort before 'a').
items.sort(key=lambda it: (it.get("sort_title") or it.get("title") or "").strip().lower())
total = len(items)
total_pages = max(1, (total + limit - 1) // limit)
page = min(page, total_pages)

View file

@ -851,11 +851,13 @@ def test_query_watchlist_default_sort_is_alphabetical(db):
db.add_to_watchlist("show", 1, "Welcome to Widows Bay")
db.add_to_watchlist("show", 2, "From")
db.add_to_watchlist("show", 3, "Andor")
titles = [it["title"] for it in db.query_watchlist("show")["items"]]
assert titles == ["Andor", "From", "Welcome to Widows Bay"]
db.add_to_watchlist("show", 4, " Holy Marvels with Dennis Quaid") # dirty leading space
titles = [it["title"].strip() for it in db.query_watchlist("show")["items"]]
# a leading-space title must NOT jump the queue — sorts under H
assert titles == ["Andor", "From", "Holy Marvels with Dennis Quaid", "Welcome to Widows Bay"]
# 'added' is still available opt-in (newest first)
added = [it["title"] for it in db.query_watchlist("show", sort="added")["items"]]
assert added[0] == "Andor" # most recently added
added = [it["title"].strip() for it in db.query_watchlist("show", sort="added")["items"]]
assert added[0] == "Holy Marvels with Dennis Quaid" # most recently added
# ── wishlist (movies + episodes; show/season are bulk ops over episodes) ──────