-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovie_handlers.py
More file actions
146 lines (127 loc) · 5.45 KB
/
movie_handlers.py
File metadata and controls
146 lines (127 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from ui_ux import show_list_and_get_user_choice, print_cancellation_summary, prompt_search_decision, get_title_and_year_input
from ui_ux import display_res, action_menu, process_number_choice
from helper import extract_results, search_api
def handle_movies_with_no_match(movie_no, api_client):
if not movie_no:
print(f"\n[INFO] There are no movies with no match. Continue with the next task.")
return [], [], []
handled, skipped, remaining, choice = show_list_and_get_user_choice(
movie_no,
content="movies",
action="search",
res_quantity="no match"
)
if choice == 2:
return [], [], []
handled_movies = []
skipped_movies = []
remaining_movies = []
for idx, movie in enumerate(movie_no):
choice, handled_movies, skipped_movies, remaining_movies = prompt_search_decision(
movie, idx, handled_movies, skipped_movies, movie_no, content="movies", action="search"
)
if choice == 'c':
return handled_movies, skipped_movies, remaining_movies
if choice == 'n' or choice == 's':
continue
title, year = get_title_and_year_input(mo=True, file=movie)
while True:
result, options = search_api(api_client, 'tmdb', title, year)
if not options:
action_menu(no=True)
sel = input("Choice: ").strip().lower()
if sel == 'r':
title, year = get_title_and_year_input(re=True, mo=True)
continue
elif sel == 's':
skipped_movies.append(movie)
break
elif sel == 'c':
handled_movies, skipped_movies, remaining_movies = print_cancellation_summary(
handled=handled_movies,
skipped=skipped_movies,
source=movie_no,
mode=1,
idx_or_processed=idx,
content="movies",
action="search"
)
return handled_movies, skipped_movies, remaining_movies
else:
print("Invalid input. Please enter r, s, or c.")
display_res(options)
action_menu()
sel = input("Choice: ").strip().lower()
if process_number_choice(sel, options, movie, handled_movies):
break
if sel == 'r':
title, year = get_title_and_year_input(re=True, mo=True)
continue
elif sel == 's':
skipped_movies.append(movie)
break
elif sel == 'c':
handled_movies, skipped_movies, remaining_movies = print_cancellation_summary(
handled=handled_movies,
skipped=skipped_movies,
source=movie_no,
mode=1,
idx_or_processed=idx,
content="movies",
action="search"
)
return handled_movies, skipped_movies, remaining_movies
else:
print(f"Invalid input. Please enter a number between 1-{len(options)} or r, a, s, c.")
return handled_movies, skipped_movies, remaining_movies
# ======================================================================
# ======================================================================
# ======================================================================
def handle_movies_with_multiple_matches(movie_mult, api_client):
if not movie_mult:
print(f"\n[INFO] There are no movies with multiple_matches. Continue with the next task.")
return [], [], []
handled, skipped, remaining, choice = show_list_and_get_user_choice(
movie_mult,
content="movies",
action="selection",
res_quantity="multiple matches"
)
if choice == 2:
return [], [], []
handled_movies = []
skipped_movies = []
remaining_movies = []
for idx, movie in enumerate(movie_mult):
details = movie['details']
options = extract_results(details)
display_res(options, movie, content="movie")
action_menu()
while True:
sel = input("Choice: ").strip().lower()
if process_number_choice(sel, options, movie, handled_movies):
break
elif sel == 'r':
title, year = get_title_and_year_input(mo=True)
result, options = search_api(api_client, 'tmdb', title, year)
if options:
display_res(options)
else:
print("No results.")
elif sel == 's':
skipped_movies.append(movie)
break
elif sel == 'c':
handled_movies, skipped_movies, remaining_movies = print_cancellation_summary(
handled=handled_movies,
skipped=skipped_movies,
source=movie_mult,
mode=1,
idx_or_processed=idx,
content="movies",
action="selection"
)
return handled_movies, skipped_movies, remaining_movies
else:
print(f"Invalid input. Please enter a number between 1-{len(options)} or r, a, s, c.")
return handled_movies, skipped_movies, remaining_movies