Unified selection handler for all debrid providers. files: list of dicts or strings (anything indexable) prompt: custom prompt string Returns: list of 0-based indexes
(files, prompt="Enter selection")
| 250 | return urls |
| 251 | |
| 252 | def select_files_interactive(files, prompt="Enter selection"): |
| 253 | """ |
| 254 | Unified selection handler for all debrid providers. |
| 255 | |
| 256 | files: list of dicts or strings (anything indexable) |
| 257 | prompt: custom prompt string |
| 258 | |
| 259 | Returns: list of 0-based indexes |
| 260 | """ |
| 261 | max_index = len(files) |
| 262 | |
| 263 | print(f"{CYAN}{prompt}:{RESET}") |
| 264 | for idx, f in enumerate(files, 1): |
| 265 | if isinstance(f, dict): |
| 266 | name = f.get("name") or f.get("short_name") or f.get("path") or str(f) |
| 267 | else: |
| 268 | name = str(f) |
| 269 | size = f.get("size") if isinstance(f, dict) else None |
| 270 | if size: |
| 271 | mb = size // (1024 * 1024) |
| 272 | print(f"{YELLOW}{idx}{RESET}: {name} {CYAN}({mb} MB){RESET}") |
| 273 | else: |
| 274 | print(f"{YELLOW}{idx}{RESET}: {name}") |
| 275 | |
| 276 | choice = input( |
| 277 | f"{CYAN}Enter numbers, commas, ranges (e.g. 1,3-5) or 'all' (default all): {RESET}" |
| 278 | ).strip() |
| 279 | |
| 280 | # Default = all |
| 281 | if not choice or choice.lower() == "all": |
| 282 | return list(range(max_index)) |
| 283 | |
| 284 | # Use your existing range parser |
| 285 | raw = parse_selection(choice, max_index) |
| 286 | |
| 287 | selected = [i - 1 for i in raw if 1 <= i <= max_index] |
| 288 | |
| 289 | return selected |
| 290 | |
| 291 | def show_progress_factory(): |
| 292 | start_time = [time.time()] |
no test coverage detected