Retrieve and apply info from the autotagger for albums matched by query and their items.
(self, lib, query, move, pretend, write)
| 130 | return items |
| 131 | |
| 132 | def albums(self, lib, query, move, pretend, write): |
| 133 | """Retrieve and apply info from the autotagger for albums matched by |
| 134 | query and their items. |
| 135 | """ |
| 136 | # Process matching albums. |
| 137 | for album in lib.albums(query): |
| 138 | # Do we have a valid Beatport album? |
| 139 | items = self.get_album_tracks(album) |
| 140 | if not items: |
| 141 | continue |
| 142 | |
| 143 | # Get the Beatport album information. |
| 144 | albuminfo = self.beatport_plugin.album_for_id(album.mb_albumid) |
| 145 | if not albuminfo: |
| 146 | self._log.info( |
| 147 | "Release ID {0.mb_albumid} not found for album {0}", album |
| 148 | ) |
| 149 | continue |
| 150 | |
| 151 | beatport_trackid_to_trackinfo = { |
| 152 | track.track_id: track for track in albuminfo.tracks |
| 153 | } |
| 154 | library_trackid_to_item = { |
| 155 | int(item.mb_trackid): item for item in items |
| 156 | } |
| 157 | item_info_pairs = [ |
| 158 | (item, beatport_trackid_to_trackinfo[track_id]) |
| 159 | for track_id, item in library_trackid_to_item.items() |
| 160 | ] |
| 161 | |
| 162 | self._log.info("applying changes to {}", album) |
| 163 | with lib.transaction(): |
| 164 | AlbumMatch( |
| 165 | Distance(), albuminfo, dict(item_info_pairs) |
| 166 | ).apply_metadata(from_scratch=False) |
| 167 | changed = False |
| 168 | # Find any changed item to apply Beatport changes to album. |
| 169 | any_changed_item = items[0] |
| 170 | for item in items: |
| 171 | item_changed = ui.show_model_changes(item) |
| 172 | changed |= item_changed |
| 173 | if item_changed: |
| 174 | any_changed_item = item |
| 175 | apply_item_changes(lib, item, move, pretend, write) |
| 176 | |
| 177 | if pretend or not changed: |
| 178 | continue |
| 179 | |
| 180 | # Update album structure to reflect an item in it. |
| 181 | for key in library.Album.item_keys: |
| 182 | album[key] = any_changed_item[key] |
| 183 | album.store() |
| 184 | |
| 185 | # Move album art (and any inconsistent items). |
| 186 | if move and lib.directory in util.ancestry(items[0].path): |
| 187 | self._log.debug("moving album {}", album) |
| 188 | album.move() |
no test coverage detected