@@ -101,6 +101,9 @@ def _intercept_mb_candidates(self, info: AlbumInfo):
101
101
)
102
102
self ._intercepted_candidates [info .album_id ] = info .copy ()
103
103
104
+ elif info .get ("albumstatus" , "" ) == "Pseudo-Release" :
105
+ self ._purge_intercepted_pseudo_releases (info )
106
+
104
107
def candidates (
105
108
self ,
106
109
items : Sequence [Item ],
@@ -144,14 +147,29 @@ def candidates(
144
147
isinstance (plugin , mbplugin .MusicBrainzPlugin )
145
148
for plugin in find_plugins ()
146
149
):
147
- self ._log .debug ("No releases found by main MusicBrainz plugin" )
150
+ self ._log .debug (
151
+ "No releases found after main MusicBrainz plugin executed"
152
+ )
148
153
return []
149
154
150
155
# musicbrainz plugin isn't enabled
151
156
self ._log .debug ("Searching for official releases" )
152
- official_candidates = list (
153
- self ._mb .candidates (items , artist , album , va_likely )
154
- )
157
+
158
+ try :
159
+ existing_album_id = next (
160
+ item .mb_albumid for item in items if item .mb_albumid
161
+ )
162
+ existing_album_info = self ._mb .album_for_id (existing_album_id )
163
+ if not isinstance (existing_album_info , AlbumInfo ):
164
+ official_candidates = list (
165
+ self ._mb .candidates (items , artist , album , va_likely )
166
+ )
167
+ else :
168
+ official_candidates = [existing_album_info ]
169
+ except StopIteration :
170
+ official_candidates = list (
171
+ self ._mb .candidates (items , artist , album , va_likely )
172
+ )
155
173
156
174
recursion = self ._mb_plugin_simulation_matched (
157
175
items , official_candidates
@@ -160,7 +178,11 @@ def candidates(
160
178
if not self .config .get ().get ("include_official_releases" ):
161
179
official_candidates = []
162
180
181
+ self ._log .debug (
182
+ "Emitting {0} official match(es)" , len (official_candidates )
183
+ )
163
184
if recursion :
185
+ self ._log .debug ("Matches found after search" )
164
186
return itertools .chain (
165
187
self .candidates (items , artist , album , va_likely ),
166
188
iter (official_candidates ),
@@ -197,19 +219,38 @@ def _mb_plugin_simulation_matched(
197
219
items : Sequence [Item ],
198
220
official_candidates : list [AlbumInfo ],
199
221
) -> bool :
200
- recursion = False
222
+ matched = False
201
223
for official_candidate in official_candidates :
202
224
if official_candidate .album_id in self ._pseudo_release_ids :
203
225
self ._intercept_mb_candidates (official_candidate )
226
+
204
227
if official_candidate .album_id in self ._intercepted_candidates :
205
228
intercepted = self ._intercepted_candidates [
206
229
official_candidate .album_id
207
230
]
208
231
intercepted .mapping , _ , _ = assign_items (
209
232
items , intercepted .tracks
210
233
)
211
- recursion = True
212
- return recursion
234
+ matched = True
235
+
236
+ if official_candidate .get ("albumstatus" , "" ) == "Pseudo-Release" :
237
+ self ._purge_intercepted_pseudo_releases (official_candidate )
238
+
239
+ return matched
240
+
241
+ def _purge_intercepted_pseudo_releases (self , official_candidate : AlbumInfo ):
242
+ rm_keys = [
243
+ album_id
244
+ for album_id , pseudo_album_ids in self ._pseudo_release_ids .items ()
245
+ if official_candidate .album_id in pseudo_album_ids
246
+ ]
247
+ if rm_keys :
248
+ self ._log .debug (
249
+ "No need to resolve {0}, removing" ,
250
+ rm_keys ,
251
+ )
252
+ for k in rm_keys :
253
+ del self ._pseudo_release_ids [k ]
213
254
214
255
@override
215
256
def album_distance (
0 commit comments