|
1 | 1 | import logging |
2 | | -from collections import defaultdict |
3 | 2 | from collections.abc import Generator |
4 | 3 | from enum import Enum |
5 | 4 | from platform import python_version |
@@ -86,32 +85,36 @@ class MediuxSet(Protocol): |
86 | 85 |
|
87 | 86 |
|
88 | 87 | 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, |
90 | 92 | ) -> Generator[T]: |
91 | 93 | if not set_list: |
92 | 94 | return |
93 | 95 |
|
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 | | - |
98 | 96 | # Priority usernames first |
99 | 97 | 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) |
113 | 106 | 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] |
115 | 118 |
|
116 | 119 | if not only_priority_usernames: |
117 | 120 | # Remaining sets |
@@ -353,6 +356,15 @@ def sync_posters( |
353 | 356 | "Specify this option multiple times for skipping multiple libraries. ", |
354 | 357 | ), |
355 | 358 | ], |
| 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, |
356 | 368 | start: Annotated[ |
357 | 369 | int, Option("--start", "-s", help="The starting index for processing media.") |
358 | 370 | ] = 0, |
@@ -410,6 +422,7 @@ def sync_posters( |
410 | 422 | set_list=set_list, |
411 | 423 | priority_usernames=settings.priority_usernames, |
412 | 424 | only_priority_usernames=settings.only_priority_usernames, |
| 425 | + interactive=interactive, |
413 | 426 | ) |
414 | 427 | for set_data in filtered_sets: |
415 | 428 | if not process_set_data( |
@@ -440,6 +453,15 @@ def media_posters( |
440 | 453 | "Specify this option multiple times for skipping multiple services.", |
441 | 454 | ), |
442 | 455 | ], |
| 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, |
443 | 465 | clean: Annotated[ |
444 | 466 | bool, |
445 | 467 | Option("--clean", "-c", show_default=False, help="Delete the whole cache before starting."), |
@@ -504,6 +526,7 @@ def media_posters( |
504 | 526 | set_list=set_list, |
505 | 527 | priority_usernames=settings.priority_usernames, |
506 | 528 | only_priority_usernames=settings.only_priority_usernames, |
| 529 | + interactive=interactive, |
507 | 530 | ) |
508 | 531 | for set_data in filtered_sets: |
509 | 532 | if not process_set_data( |
|
0 commit comments