14
14
# GNU General Public License for more details.
15
15
16
16
PLUGIN_NAME = "Abbreviate artist-sort"
17
- PLUGIN_AUTHOR = "Sophist"
17
+ PLUGIN_AUTHOR = "Sophist, Sambhav Dixit "
18
18
PLUGIN_DESCRIPTION = '''Abbreviate Artist-Sort and Album-Artist-Sort Tags.
19
19
e.g. "Vivaldi, Antonio" becomes "Vivaldi, A."
20
20
This is particularly useful for classical albums that can have a long list of artists.
80
80
81
81
82
82
def abbreviate_artistsort (tagger , metadata , track , release ):
83
-
84
83
for sortTag , unsortTag , sortTagNew in _abbreviate_tags :
85
84
if not (sortTag in metadata and unsortTag in metadata ):
86
85
continue
@@ -99,7 +98,6 @@ def abbreviate_artistsort(tagger, metadata, track, release):
99
98
new_unsort = ""
100
99
101
100
while len (sort ) > 0 and len (unsort ) > 0 :
102
-
103
101
if not _split in sort :
104
102
log .debug (" Ending without separator '%s' - moving '%s'." % (_split , sort ))
105
103
new_sort += sort
@@ -119,23 +117,8 @@ def abbreviate_artistsort(tagger, metadata, track, release):
119
117
new_unsort += unsort [0 :len (unsort ) - len (unsort .lstrip ())]
120
118
unsort = unsort .lstrip ()
121
119
122
- # Sorted: Stuff, ...
123
- # Unsorted: Stuff, ...
124
- temp = surname + _split
125
- l = len (temp )
126
- if unsort [:l ] == temp :
127
- log .debug (" No forename - moving '%s'." % (surname ))
128
- new_sort += temp
129
- new_unsort += temp
130
- sort = sort [l :]
131
- unsort = unsort [l :]
132
- continue
133
-
134
- # Sorted: Stuff; Surname, Forename(s)...
135
- # Unsorted: Stuff; Forename(s) Surname...
136
- # Move matching words plus white-space one by one
137
- if unsort .find (' ' + surname ) == - 1 :
138
- while surname .split (None , 1 )[0 ] == unsort .split (None , 1 )[0 ]:
120
+ if len (surname .split ()) > 1 :
121
+ while len (sort ) > 0 and len (unsort ) > 0 :
139
122
x = unsort .split (None , 1 )[0 ]
140
123
log .debug (" Moving matching word '%s'." % (x ))
141
124
new_sort += x
@@ -146,88 +129,51 @@ def abbreviate_artistsort(tagger, metadata, track, release):
146
129
surname = surname .lstrip ()
147
130
new_unsort += unsort [0 :len (unsort ) - len (unsort .lstrip ())]
148
131
unsort = unsort .lstrip ()
149
-
150
- # If we still can't find surname then we are up a creek...
151
- pos = unsort .find (' ' + surname )
152
- if pos == - 1 :
153
- log .debug (
154
- _ ("%s: Track %s: Unable to abbreviate surname '%s' - not matched in unsorted %s: '%s'." ),
155
- PLUGIN_NAME ,
156
- metadata ['tracknumber' ],
157
- surname ,
158
- unsortTag ,
159
- unsort [i ],
160
- )
161
- log .warning (" Could not match surname '%s' in remaining unsorted: %s" % (surname , unsort ))
162
- break
163
-
164
- # Sorted: Surname, Forename(s)...
165
- # Unsorted: Forename(s) Surname...
166
- forename = unsort [:pos ]
167
- if rest [:len (forename )] != forename :
168
- log .debug (
169
- _ ("%s: Track %s: Unable to abbreviate surname (%s) - forename (%s) not matched in unsorted %s: '%s'." ),
170
- PLUGIN_NAME ,
171
- metadata ['tracknumber' ],
172
- surname ,
173
- forename ,
174
- unsortTag ,
175
- unsort [i ],
176
- )
177
- log .warning (" Could not match forename (%s) for surname (%s) in remaining unsorted (%s):" % (forename , surname , unsort ))
178
- break
179
-
180
- inits = ' ' .join ([x [0 ] + '.' for x in forename .split ()])
181
-
182
- # Sorted: Beatles, The...
183
- # Unsorted: The Beatles...
184
- if forename in _prefixes :
185
- inits = forename
186
-
187
- new_sort += surname + _split + inits
188
- sort = rest [len (forename ):]
189
- new_sort += sort [0 :len (sort ) - len (sort [1 :].lstrip ())]
190
- sort = sort [1 :].lstrip ()
191
- new_unsort += forename
192
- unsort = unsort [len (forename ):]
193
- new_unsort += unsort [0 :len (unsort ) - len (unsort .lstrip ())]
194
- unsort = unsort .lstrip ()
195
- new_unsort += surname
196
- unsort = unsort [len (surname ):]
197
- new_unsort += unsort [0 :len (unsort ) - len (unsort [1 :].lstrip ())]
198
- unsort = unsort [1 :].lstrip ()
199
-
200
- if forename != inits :
201
- log .debug (
202
- _ ("%s: Abbreviated surname (%s, %s) to (%s, %s) in '%s'." ),
203
- PLUGIN_NAME ,
204
- surname ,
205
- forename ,
206
- surname ,
207
- inits ,
208
- sortTag ,
209
- )
210
- log .debug ("Abbreviated (%s, %s) to (%s, %s)." % (surname , forename , surname , inits ))
211
- else : # while loop ended without a break i.e. no errors
212
- if unsorts [i ] != new_unsort :
213
- log .error (
214
- _ ("%s: Track %s: Logic error - mangled %s from '%s' to '%s'." ),
215
- PLUGIN_NAME ,
216
- metadata ['tracknumber' ],
217
- unsortTag ,
218
- unsorts [i ],
219
- new_unsort ,
220
- )
221
- log .warning ("Error: Unsorted text for %s has changed from '%s' to '%s'!" % (unsortTag , unsorts [i ], new_unsort ))
222
- _abbreviate_cache [sorts [i ]] = new_sort
223
- log .debug (" Abbreviated and cached (%s) as (%s)." % (sorts [i ], new_sort ))
224
- if sorts [i ] != new_sort :
225
- log .debug (_ ("%s: Abbreviated tag '%s' to '%s'." ),
226
- PLUGIN_NAME ,
227
- sorts [i ],
228
- new_sort ,
229
- )
230
- sorts [i ] = new_sort
132
+ else :
133
+ log .debug (" Only one word found in the sorted name '%s'." % (sort ))
134
+ inits = ' ' .join ([x [0 ] + '.' for x in surname .split ()])
135
+ new_sort += surname + _split + inits
136
+ sort = rest [len (surname ):]
137
+ new_sort += sort [0 :len (sort ) - len (sort [1 :].lstrip ())]
138
+ sort = sort [1 :].lstrip ()
139
+ new_unsort += surname
140
+ unsort = unsort [len (surname ):]
141
+ new_unsort += unsort [0 :len (unsort ) - len (unsort .lstrip ())]
142
+ unsort = unsort .lstrip ()
143
+ new_unsort += surname
144
+ unsort = unsort [len (surname ):]
145
+ new_unsort += unsort [0 :len (unsort ) - len (unsort [1 :].lstrip ())]
146
+ unsort = unsort [1 :].lstrip ()
147
+
148
+ if surname != inits :
149
+ log .debug (
150
+ _ ("%s: Abbreviated surname (%s) to (%s) in '%s'." ),
151
+ PLUGIN_NAME ,
152
+ surname ,
153
+ inits ,
154
+ sortTag ,
155
+ )
156
+ log .debug ("Abbreviated (%s) to (%s)." % (surname , inits ))
157
+
158
+ if unsorts [i ] != new_unsort :
159
+ log .error (
160
+ _ ("%s: Track %s: Logic error - mangled %s from '%s' to '%s'." ),
161
+ PLUGIN_NAME ,
162
+ metadata ['tracknumber' ],
163
+ unsortTag ,
164
+ unsorts [i ],
165
+ new_unsort ,
166
+ )
167
+ log .warning ("Error: Unsorted text for %s has changed from '%s' to '%s'!" % (unsortTag , unsorts [i ], new_unsort ))
168
+ _abbreviate_cache [sorts [i ]] = new_sort
169
+ log .debug (" Abbreviated and cached (%s) as (%s)." % (sorts [i ], new_sort ))
170
+ if sorts [i ] != new_sort :
171
+ log .debug (_ ("%s: Abbreviated tag '%s' to '%s'." ),
172
+ PLUGIN_NAME ,
173
+ sorts [i ],
174
+ new_sort ,
175
+ )
176
+ sorts [i ] = new_sort
231
177
metadata [sortTagNew ] = sorts
232
178
233
179
register_track_metadata_processor (abbreviate_artistsort )
0 commit comments