For commands that operate on matched items, performs a query and returns a list of matching items and a list of matching albums. (The latter is only nonempty when album is True.) Raises a UserError if no items match. also_items controls whether, when fetching albums, the associated i
(lib, query, album, also_items=True)
| 4 | |
| 5 | |
| 6 | def do_query(lib, query, album, also_items=True): |
| 7 | """For commands that operate on matched items, performs a query |
| 8 | and returns a list of matching items and a list of matching |
| 9 | albums. (The latter is only nonempty when album is True.) Raises |
| 10 | a UserError if no items match. also_items controls whether, when |
| 11 | fetching albums, the associated items should be fetched also. |
| 12 | """ |
| 13 | if album: |
| 14 | albums = list(lib.albums(query)) |
| 15 | items = [] |
| 16 | if also_items: |
| 17 | for al in albums: |
| 18 | items += al.items() |
| 19 | |
| 20 | else: |
| 21 | albums = [] |
| 22 | items = list(lib.items(query)) |
| 23 | |
| 24 | if album and not albums: |
| 25 | raise UserError("No matching albums found.") |
| 26 | if not album and not items: |
| 27 | raise UserError("No matching items found.") |
| 28 | |
| 29 | return items, albums |