29
29
from beets .plugins import find_plugins
30
30
from beetsplug ._typing import JSONDict
31
31
32
+ _STATUS_PSEUDO = "Pseudo-Release"
32
33
34
+
35
+ # TODO listen for import start and warn if MB plugin found but not before us
33
36
class MusicBrainzPseudoReleasePlugin (MetadataSourcePlugin ):
34
37
def __init__ (self , * args , ** kwargs ) -> None :
35
38
super ().__init__ (* args , ** kwargs )
@@ -47,9 +50,10 @@ def __init__(self, *args, **kwargs) -> None:
47
50
self ._log .debug ("Desired scripts: {0}" , self ._scripts )
48
51
49
52
def _intercept_mb_releases (self , data : JSONDict ):
50
- album_id = data ["id" ] if ( "id" in data ) else None
53
+ album_id = data ["id" ] if "id" in data else None
51
54
if (
52
- not isinstance (album_id , str )
55
+ self ._has_desired_script (data )
56
+ or not isinstance (album_id , str )
53
57
or album_id in self ._pseudo_release_ids
54
58
):
55
59
return None
@@ -68,6 +72,14 @@ def _intercept_mb_releases(self, data: JSONDict):
68
72
69
73
return None
70
74
75
+ def _has_desired_script (self , release : JSONDict ) -> bool :
76
+ if len (self ._scripts ) == 0 :
77
+ return False
78
+ elif script := release .get ("text-representation" , {}).get ("script" ):
79
+ return script in self ._scripts
80
+ else :
81
+ return False
82
+
71
83
def _wanted_pseudo_release_id (
72
84
self ,
73
85
relation : JSONDict ,
@@ -81,11 +93,7 @@ def _wanted_pseudo_release_id(
81
93
return None
82
94
83
95
release = relation ["release" ]
84
- script = release .get ("text-representation" , {}).get (
85
- "script" , self ._scripts [0 ]
86
- )
87
-
88
- if "id" in release and script in self ._scripts :
96
+ if "id" in release and self ._has_desired_script (release ):
89
97
return release ["id" ]
90
98
else :
91
99
return None
@@ -101,7 +109,7 @@ def _intercept_mb_candidates(self, info: AlbumInfo):
101
109
)
102
110
self ._intercepted_candidates [info .album_id ] = info .copy ()
103
111
104
- elif info .get ("albumstatus" , "" ) == "Pseudo-Release" :
112
+ elif info .get ("albumstatus" , "" ) == _STATUS_PSEUDO :
105
113
self ._purge_intercepted_pseudo_releases (info )
106
114
107
115
def candidates (
@@ -175,7 +183,7 @@ def candidates(
175
183
items , official_candidates
176
184
)
177
185
178
- if not self .config .get ().get ("include_official_releases" ):
186
+ if recursion and not self .config .get ().get ("include_official_releases" ):
179
187
official_candidates = []
180
188
181
189
self ._log .debug (
@@ -233,7 +241,7 @@ def _mb_plugin_simulation_matched(
233
241
)
234
242
matched = True
235
243
236
- if official_candidate .get ("albumstatus" , "" ) == "Pseudo-Release" :
244
+ if official_candidate .get ("albumstatus" , "" ) == _STATUS_PSEUDO :
237
245
self ._purge_intercepted_pseudo_releases (official_candidate )
238
246
239
247
return matched
0 commit comments