(self, source: str, media_type: str, query: str)
| 182 | ) |
| 183 | |
| 184 | async def search_interactive(self, source: str, media_type: str, query: str): |
| 185 | client = await self.get_logged_in_client(source) |
| 186 | |
| 187 | with console.status(f"[bold]Searching {source}", spinner="dots"): |
| 188 | pages = await client.search(media_type, query, limit=100) |
| 189 | if len(pages) == 0: |
| 190 | console.print(f"[red]No search results found for query {query}") |
| 191 | return |
| 192 | search_results = SearchResults.from_pages(source, media_type, pages) |
| 193 | |
| 194 | if platform.system() == "Windows": # simple term menu not supported for windows |
| 195 | from pick import pick |
| 196 | |
| 197 | choices = pick( |
| 198 | search_results.results, |
| 199 | title=( |
| 200 | f"{source.capitalize()} {media_type} search.\n" |
| 201 | "Press SPACE to select, RETURN to download, CTRL-C to exit." |
| 202 | ), |
| 203 | multiselect=True, |
| 204 | min_selection_count=1, |
| 205 | ) |
| 206 | assert isinstance(choices, list) |
| 207 | |
| 208 | await self.add_all_by_id( |
| 209 | [(source, media_type, item.id) for item, _ in choices], |
| 210 | ) |
| 211 | |
| 212 | else: |
| 213 | from simple_term_menu import TerminalMenu |
| 214 | |
| 215 | menu = TerminalMenu( |
| 216 | search_results.summaries(), |
| 217 | preview_command=search_results.preview, |
| 218 | preview_size=0.5, |
| 219 | title=( |
| 220 | f"Results for {media_type} '{query}' from {source.capitalize()}\n" |
| 221 | "SPACE - select, ENTER - download, ESC - exit" |
| 222 | ), |
| 223 | cycle_cursor=True, |
| 224 | clear_screen=True, |
| 225 | multi_select=True, |
| 226 | ) |
| 227 | chosen_ind = menu.show() |
| 228 | if chosen_ind is None: |
| 229 | console.print("[yellow]No items chosen. Exiting.") |
| 230 | else: |
| 231 | choices = search_results.get_choices(chosen_ind) |
| 232 | await self.add_all_by_id( |
| 233 | [(source, item.media_type(), item.id) for item in choices], |
| 234 | ) |
| 235 | |
| 236 | async def search_take_first(self, source: str, media_type: str, query: str): |
| 237 | client = await self.get_logged_in_client(source) |
no test coverage detected