Skip to content

Commit 461fe5d

Browse files
Add user selection for multiple sets from priority user
Fixes #40
1 parent 8c0df6c commit 461fe5d

4 files changed

Lines changed: 234 additions & 152 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.12.3
3+
rev: v0.13.0
44
hooks:
55
- id: ruff-format
66
- id: ruff-check
@@ -16,7 +16,7 @@ repos:
1616
- --wrap=keep
1717
exclude: ".github\/ISSUE_TEMPLATE\/.*.md"
1818
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v5.0.0
19+
rev: v6.0.0
2020
hooks:
2121
- id: check-ast
2222
- id: check-builtin-literals
@@ -49,7 +49,7 @@ repos:
4949
exclude_types:
5050
- svg
5151
- repo: https://github.com/pappasam/toml-sort
52-
rev: v0.24.2
52+
rev: v0.24.3
5353
hooks:
5454
- id: toml-sort
5555
args:

mediux_posters/__main__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
2+
from collections import defaultdict
23
from collections.abc import Generator
34
from enum import Enum
45
from platform import python_version
56
from typing import Annotated, Final, Protocol, TypeVar
67

8+
from questionary import Choice, select
79
from typer import Abort, Argument, Context, Exit, Option, Typer
810

911
from mediux_posters import __project__, __version__, get_cache_root, setup_logging
@@ -79,6 +81,7 @@ def setup(
7981

8082

8183
class MediuxSet(Protocol):
84+
set_title: str
8285
username: str
8386

8487

@@ -87,9 +90,29 @@ def filter_sets(
8790
) -> Generator[T]:
8891
if not set_list:
8992
return
93+
94+
sets_by_user: dict[str, list[T]] = defaultdict(list)
95+
for x in set_list:
96+
sets_by_user[x.username].append(x)
97+
9098
# Priority usernames first
9199
for username in priority_usernames:
92-
yield from [x for x in set_list if x.username == username]
100+
user_sets = sets_by_user.get(username, [])
101+
if not user_sets:
102+
continue
103+
104+
while user_sets:
105+
if len(user_sets) == 1:
106+
yield user_sets.pop(0)
107+
else:
108+
choices = [Choice(title=x.set_title, value=x) for x in user_sets]
109+
selected = select(f"Multiple sets found from '{username}'", choices=choices).ask()
110+
if selected:
111+
yield selected
112+
user_sets = [x for x in user_sets if x != selected]
113+
else:
114+
raise Abort
115+
93116
if not only_priority_usernames:
94117
# Remaining sets
95118
yield from [x for x in set_list if x.username not in priority_usernames]

pyproject.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ requires = ["hatchling"]
44

55
[dependency-groups]
66
dev = [
7-
"pre-commit >= 4.2.0"
7+
"pre-commit >= 4.3.0"
88
]
99
tests = [
10-
"pytest >= 8.4.1",
11-
"pytest-cov >= 6.2.1",
10+
"pytest >= 8.4.2",
11+
"pytest-cov >= 7.0.0",
1212
"pytest-httpx >= 0.35.0",
13-
"tox >= 4.28.0",
14-
"tox-uv >= 1.26.1"
13+
"tox >= 4.30.2",
14+
"tox-uv >= 1.28.0"
1515
]
1616

1717
[project]
@@ -33,11 +33,12 @@ dependencies = [
3333
"graphql-query >= 1.4.0",
3434
"httpx[http2] >= 0.28.1",
3535
"pydantic >= 2.11.7",
36+
"questionary >= 2.1.1",
3637
"ratelimit >= 2.2.1",
37-
"rich >= 14.0.0",
38+
"rich >= 14.1.0",
3839
"tomli >= 2.2.1 ; python_version < '3.11'",
3940
"tomli-w >= 1.2.0",
40-
"typer >= 0.16.0"
41+
"typer >= 0.17.4",
4142
]
4243
description = "Fetches Show, Movie, and Collection cover art from Mediux and updates Plex/Jellyfin using TMDB IDs."
4344
dynamic = ["version"]

0 commit comments

Comments
 (0)