MCPcopy
hub / github.com/beetbox/beets / albums

Method albums

beetsplug/bpsync.py:132–188  ·  view source on GitHub ↗

Retrieve and apply info from the autotagger for albums matched by query and their items.

(self, lib, query, move, pretend, write)

Source from the content-addressed store, hash-verified

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()

Callers 15

funcMethod · 0.95
_play_commandMethod · 0.45
library_dataFunction · 0.45
_dupMethod · 0.45
lslimitFunction · 0.45
update_collectionMethod · 0.45
update_album_listMethod · 0.45
process_queryMethod · 0.45
command_funcMethod · 0.45
random_funcFunction · 0.45
_missing_tracksMethod · 0.45
_missing_albumsMethod · 0.45

Calls 12

get_album_tracksMethod · 0.95
AlbumMatchClass · 0.90
DistanceClass · 0.90
apply_item_changesFunction · 0.90
transactionMethod · 0.80
album_for_idMethod · 0.45
infoMethod · 0.45
itemsMethod · 0.45
apply_metadataMethod · 0.45
storeMethod · 0.45
debugMethod · 0.45
moveMethod · 0.45

Tested by

no test coverage detected