Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pr fixing issue exception when artist sorted name has no last name pa… #367

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 48 additions & 102 deletions plugins/abbreviate_artistsort/abbreviate_artistsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# GNU General Public License for more details.

PLUGIN_NAME = "Abbreviate artist-sort"
PLUGIN_AUTHOR = "Sophist"
PLUGIN_AUTHOR = "Sophist, Sambhav Dixit"
PLUGIN_DESCRIPTION = '''Abbreviate Artist-Sort and Album-Artist-Sort Tags.
e.g. "Vivaldi, Antonio" becomes "Vivaldi, A."
This is particularly useful for classical albums that can have a long list of artists.
Expand Down Expand Up @@ -80,7 +80,6 @@


def abbreviate_artistsort(tagger, metadata, track, release):

for sortTag, unsortTag, sortTagNew in _abbreviate_tags:
if not (sortTag in metadata and unsortTag in metadata):
continue
Expand All @@ -99,7 +98,6 @@ def abbreviate_artistsort(tagger, metadata, track, release):
new_unsort = ""

while len(sort) > 0 and len(unsort) > 0:

if not _split in sort:
log.debug(" Ending without separator '%s' - moving '%s'." % (_split, sort))
new_sort += sort
Expand All @@ -119,23 +117,8 @@ def abbreviate_artistsort(tagger, metadata, track, release):
new_unsort += unsort[0:len(unsort) - len(unsort.lstrip())]
unsort = unsort.lstrip()

# Sorted: Stuff, ...
# Unsorted: Stuff, ...
temp = surname + _split
l = len(temp)
if unsort[:l] == temp:
log.debug(" No forename - moving '%s'." % (surname))
new_sort += temp
new_unsort += temp
sort = sort[l:]
unsort = unsort[l:]
continue

# Sorted: Stuff; Surname, Forename(s)...
# Unsorted: Stuff; Forename(s) Surname...
# Move matching words plus white-space one by one
if unsort.find(' ' + surname) == -1:
while surname.split(None, 1)[0] == unsort.split(None, 1)[0]:
if len(surname.split()) > 1:
while len(sort) > 0 and len(unsort) > 0:
x = unsort.split(None, 1)[0]
log.debug(" Moving matching word '%s'." % (x))
new_sort += x
Expand All @@ -146,88 +129,51 @@ def abbreviate_artistsort(tagger, metadata, track, release):
surname = surname.lstrip()
new_unsort += unsort[0:len(unsort) - len(unsort.lstrip())]
unsort = unsort.lstrip()

# If we still can't find surname then we are up a creek...
pos = unsort.find(' ' + surname)
if pos == -1:
log.debug(
_("%s: Track %s: Unable to abbreviate surname '%s' - not matched in unsorted %s: '%s'."),
PLUGIN_NAME,
metadata['tracknumber'],
surname,
unsortTag,
unsort[i],
)
log.warning(" Could not match surname '%s' in remaining unsorted: %s" % (surname, unsort))
break

# Sorted: Surname, Forename(s)...
# Unsorted: Forename(s) Surname...
forename = unsort[:pos]
if rest[:len(forename)] != forename:
log.debug(
_("%s: Track %s: Unable to abbreviate surname (%s) - forename (%s) not matched in unsorted %s: '%s'."),
PLUGIN_NAME,
metadata['tracknumber'],
surname,
forename,
unsortTag,
unsort[i],
)
log.warning(" Could not match forename (%s) for surname (%s) in remaining unsorted (%s):" % (forename, surname, unsort))
break

inits = ' '.join([x[0] + '.' for x in forename.split()])

# Sorted: Beatles, The...
# Unsorted: The Beatles...
if forename in _prefixes:
inits = forename

new_sort += surname + _split + inits
sort = rest[len(forename):]
new_sort += sort[0:len(sort) - len(sort[1:].lstrip())]
sort = sort[1:].lstrip()
new_unsort += forename
unsort = unsort[len(forename):]
new_unsort += unsort[0:len(unsort) - len(unsort.lstrip())]
unsort = unsort.lstrip()
new_unsort += surname
unsort = unsort[len(surname):]
new_unsort += unsort[0:len(unsort) - len(unsort[1:].lstrip())]
unsort = unsort[1:].lstrip()

if forename != inits:
log.debug(
_("%s: Abbreviated surname (%s, %s) to (%s, %s) in '%s'."),
PLUGIN_NAME,
surname,
forename,
surname,
inits,
sortTag,
)
log.debug("Abbreviated (%s, %s) to (%s, %s)." % (surname, forename, surname, inits))
else: # while loop ended without a break i.e. no errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this else statement? Removing this else statement changes the whole meaning of the statements that follow it.

if unsorts[i] != new_unsort:
log.error(
_("%s: Track %s: Logic error - mangled %s from '%s' to '%s'."),
PLUGIN_NAME,
metadata['tracknumber'],
unsortTag,
unsorts[i],
new_unsort,
)
log.warning("Error: Unsorted text for %s has changed from '%s' to '%s'!" % (unsortTag, unsorts[i], new_unsort))
_abbreviate_cache[sorts[i]] = new_sort
log.debug(" Abbreviated and cached (%s) as (%s)." % (sorts[i], new_sort))
if sorts[i] != new_sort:
log.debug(_("%s: Abbreviated tag '%s' to '%s'."),
PLUGIN_NAME,
sorts[i],
new_sort,
)
sorts[i] = new_sort
else:
log.debug(" Only one word found in the sorted name '%s'." % (sort))
inits = ' '.join([x[0] + '.' for x in surname.split()])
new_sort += surname + _split + inits
sort = rest[len(surname):]
new_sort += sort[0:len(sort) - len(sort[1:].lstrip())]
sort = sort[1:].lstrip()
new_unsort += surname
unsort = unsort[len(surname):]
new_unsort += unsort[0:len(unsort) - len(unsort.lstrip())]
unsort = unsort.lstrip()
new_unsort += surname
unsort = unsort[len(surname):]
new_unsort += unsort[0:len(unsort) - len(unsort[1:].lstrip())]
unsort = unsort[1:].lstrip()

if surname != inits:
log.debug(
_("%s: Abbreviated surname (%s) to (%s) in '%s'."),
PLUGIN_NAME,
surname,
inits,
sortTag,
)
log.debug("Abbreviated (%s) to (%s)." % (surname, inits))

if unsorts[i] != new_unsort:
log.error(
_("%s: Track %s: Logic error - mangled %s from '%s' to '%s'."),
PLUGIN_NAME,
metadata['tracknumber'],
unsortTag,
unsorts[i],
new_unsort,
)
log.warning("Error: Unsorted text for %s has changed from '%s' to '%s'!" % (unsortTag, unsorts[i], new_unsort))
_abbreviate_cache[sorts[i]] = new_sort
log.debug(" Abbreviated and cached (%s) as (%s)." % (sorts[i], new_sort))
if sorts[i] != new_sort:
log.debug(_("%s: Abbreviated tag '%s' to '%s'."),
PLUGIN_NAME,
sorts[i],
new_sort,
)
sorts[i] = new_sort
metadata[sortTagNew] = sorts

register_track_metadata_processor(abbreviate_artistsort)
Loading