Get simplified track object dicts for library tracks. Matches tracks based on the specified ``keywords``. :param library: beets library object to query. :param keywords: Query to match library items against. :returns: List of simplified track object dicts for libra
(self, library: Library, keywords: str)
| 604 | return True |
| 605 | |
| 606 | def _match_library_tracks(self, library: Library, keywords: str): |
| 607 | """Get simplified track object dicts for library tracks. |
| 608 | |
| 609 | Matches tracks based on the specified ``keywords``. |
| 610 | |
| 611 | :param library: beets library object to query. |
| 612 | :param keywords: Query to match library items against. |
| 613 | |
| 614 | :returns: List of simplified track object dicts for library |
| 615 | items matching the specified query. |
| 616 | |
| 617 | """ |
| 618 | results = [] |
| 619 | failures = [] |
| 620 | |
| 621 | items = library.items(keywords) |
| 622 | |
| 623 | if not items: |
| 624 | self._log.debug( |
| 625 | "Your beets query returned no items, skipping {.data_source}.", |
| 626 | self, |
| 627 | ) |
| 628 | return None |
| 629 | |
| 630 | self._log.info("Processing {} tracks...", len(items)) |
| 631 | |
| 632 | for item in items: |
| 633 | # Apply regex transformations if provided |
| 634 | for regex in self.config["regex"].get(): |
| 635 | if ( |
| 636 | not regex["field"] |
| 637 | or not regex["search"] |
| 638 | or not regex["replace"] |
| 639 | ): |
| 640 | continue |
| 641 | |
| 642 | value = item[regex["field"]] |
| 643 | item[regex["field"]] = re.sub( |
| 644 | regex["search"], regex["replace"], value |
| 645 | ) |
| 646 | |
| 647 | artist = item["artist"] or item["albumartist"] |
| 648 | album = item["album"] |
| 649 | query_string = item["title"] |
| 650 | |
| 651 | # Query the Web API for each track, look for the items' JSON data |
| 652 | query = query_string |
| 653 | if artist: |
| 654 | query += f" artist:'{artist}'" |
| 655 | if album: |
| 656 | query += f" album:'{album}'" |
| 657 | |
| 658 | response_data_tracks = self._search_api("track", query, {}) |
| 659 | if not response_data_tracks: |
| 660 | failures.append(query) |
| 661 | continue |
| 662 | |
| 663 | # Apply market filter if requested |