Skip to content

Commit e2cb0a0

Browse files
Move user selection behind a --interactive flag
1 parent d86993d commit e2cb0a0

1 file changed

Lines changed: 43 additions & 20 deletions

File tree

mediux_posters/__main__.py

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from collections import defaultdict
32
from collections.abc import Generator
43
from enum import Enum
54
from platform import python_version
@@ -86,32 +85,36 @@ class MediuxSet(Protocol):
8685

8786

8887
def filter_sets(
89-
set_list: list[T], priority_usernames: list[str], only_priority_usernames: bool
88+
set_list: list[T],
89+
priority_usernames: list[str],
90+
only_priority_usernames: bool,
91+
interactive: bool = False,
9092
) -> Generator[T]:
9193
if not set_list:
9294
return
9395

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-
9896
# Priority usernames first
9997
for username in priority_usernames:
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]
98+
if interactive:
99+
user_sets = [x for x in set_list if x.username == username]
100+
if not user_sets:
101+
continue
102+
103+
while user_sets:
104+
if len(user_sets) == 1:
105+
yield user_sets.pop(0)
113106
else:
114-
raise Abort
107+
choices = [Choice(title=x.set_title, value=x) for x in user_sets]
108+
selected = select(
109+
f"Multiple sets found from '{username}'", choices=choices
110+
).ask()
111+
if selected:
112+
yield selected
113+
user_sets = [x for x in user_sets if x != selected]
114+
else:
115+
raise Abort
116+
else:
117+
yield from [x for x in set_list if x.username == username]
115118

116119
if not only_priority_usernames:
117120
# Remaining sets
@@ -353,6 +356,15 @@ def sync_posters(
353356
"Specify this option multiple times for skipping multiple libraries. ",
354357
),
355358
],
359+
interactive: Annotated[
360+
bool,
361+
Option(
362+
"--interactive",
363+
"-i",
364+
show_default=False,
365+
help="Pause script to allow user selection of set.",
366+
),
367+
] = False,
356368
start: Annotated[
357369
int, Option("--start", "-s", help="The starting index for processing media.")
358370
] = 0,
@@ -410,6 +422,7 @@ def sync_posters(
410422
set_list=set_list,
411423
priority_usernames=settings.priority_usernames,
412424
only_priority_usernames=settings.only_priority_usernames,
425+
interactive=interactive,
413426
)
414427
for set_data in filtered_sets:
415428
if not process_set_data(
@@ -440,6 +453,15 @@ def media_posters(
440453
"Specify this option multiple times for skipping multiple services.",
441454
),
442455
],
456+
interactive: Annotated[
457+
bool,
458+
Option(
459+
"--interactive",
460+
"-i",
461+
show_default=False,
462+
help="Pause script to allow user selection of set.",
463+
),
464+
] = False,
443465
clean: Annotated[
444466
bool,
445467
Option("--clean", "-c", show_default=False, help="Delete the whole cache before starting."),
@@ -504,6 +526,7 @@ def media_posters(
504526
set_list=set_list,
505527
priority_usernames=settings.priority_usernames,
506528
only_priority_usernames=settings.only_priority_usernames,
529+
interactive=interactive,
507530
)
508531
for set_data in filtered_sets:
509532
if not process_set_data(

0 commit comments

Comments
 (0)