Skip to content

Commit

Permalink
added changes to support singers without surname
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhavnoobcoder committed Jan 1, 2024
1 parent d1e6352 commit 9228334
Show file tree
Hide file tree
Showing 4 changed files with 5,270 additions and 102 deletions.
150 changes: 48 additions & 102 deletions plugins/abbreviate_artistsort/abbreviate_artistsort.py
Original file line number Diff line number Diff line change
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
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)
register_track_metadata_processor(abbreviate_artistsort)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'plugins/additional_artists_details/options_additional_artists_details.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_AdditionalArtistsDetailsOptionsPage(object):
def setupUi(self, AdditionalArtistsDetailsOptionsPage):
AdditionalArtistsDetailsOptionsPage.setObjectName("AdditionalArtistsDetailsOptionsPage")
AdditionalArtistsDetailsOptionsPage.resize(561, 802)
AdditionalArtistsDetailsOptionsPage.setMinimumSize(QtCore.QSize(100, 0))
self.verticalLayout = QtWidgets.QVBoxLayout(AdditionalArtistsDetailsOptionsPage)
self.verticalLayout.setObjectName("verticalLayout")
self.scrollArea = QtWidgets.QScrollArea(AdditionalArtistsDetailsOptionsPage)
self.scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 543, 784))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.gb_description = QtWidgets.QGroupBox(self.scrollAreaWidgetContents)
self.gb_description.setObjectName("gb_description")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.gb_description)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.format_description = QtWidgets.QLabel(self.gb_description)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.format_description.sizePolicy().hasHeightForWidth())
self.format_description.setSizePolicy(sizePolicy)
self.format_description.setWordWrap(True)
self.format_description.setObjectName("format_description")
self.verticalLayout_3.addWidget(self.format_description)
self.verticalLayout_2.addWidget(self.gb_description)
self.gb_process_track_artists = QtWidgets.QGroupBox(self.scrollAreaWidgetContents)
self.gb_process_track_artists.setObjectName("gb_process_track_artists")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.gb_process_track_artists)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.label = QtWidgets.QLabel(self.gb_process_track_artists)
self.label.setWordWrap(True)
self.label.setObjectName("label")
self.verticalLayout_4.addWidget(self.label)
self.cb_process_tracks = QtWidgets.QCheckBox(self.gb_process_track_artists)
self.cb_process_tracks.setObjectName("cb_process_tracks")
self.verticalLayout_4.addWidget(self.cb_process_tracks)
self.verticalLayout_2.addWidget(self.gb_process_track_artists)
self.gb_area_details = QtWidgets.QGroupBox(self.scrollAreaWidgetContents)
self.gb_area_details.setObjectName("gb_area_details")
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.gb_area_details)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.label_2 = QtWidgets.QLabel(self.gb_area_details)
self.label_2.setWordWrap(True)
self.label_2.setObjectName("label_2")
self.verticalLayout_5.addWidget(self.label_2)
self.cb_area_details = QtWidgets.QCheckBox(self.gb_area_details)
self.cb_area_details.setObjectName("cb_area_details")
self.verticalLayout_5.addWidget(self.cb_area_details)
self.verticalLayout_2.addWidget(self.gb_area_details)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout.addWidget(self.scrollArea)

self.retranslateUi(AdditionalArtistsDetailsOptionsPage)
QtCore.QMetaObject.connectSlotsByName(AdditionalArtistsDetailsOptionsPage)

def retranslateUi(self, AdditionalArtistsDetailsOptionsPage):
_translate = QtCore.QCoreApplication.translate
AdditionalArtistsDetailsOptionsPage.setWindowTitle(_translate("AdditionalArtistsDetailsOptionsPage", "Form"))
self.gb_description.setTitle(_translate("AdditionalArtistsDetailsOptionsPage", "Additional Artists Details"))
self.format_description.setText(_translate("AdditionalArtistsDetailsOptionsPage", "<html><head/><body><p>These settings will determine how the <span style=\" font-weight:600;\">Additional Artists Details</span> plugin operates.</p><p>Please visit the repository on GitHub for <a href=\"https://github.com/rdswift/picard-plugins/blob/2.0_RDS_Plugins/plugins/additional_artists_details/docs/README.md\"><span style=\" text-decoration: underline; color:#0000ff;\">additional information</span></a>.</p></body></html>"))
self.gb_process_track_artists.setTitle(_translate("AdditionalArtistsDetailsOptionsPage", "Process Track Artists"))
self.label.setText(_translate("AdditionalArtistsDetailsOptionsPage", "<html><head/><body><p>This option determines whether or not details are retrieved for all track artists on the release. If you are only interested in details for the album artists then this should be disabled, thus significantly reducing the number of additional calls made to the MusicBrainz api and reducing the time required to load a release. Album artists are always processed.</p></body></html>"))
self.cb_process_tracks.setText(_translate("AdditionalArtistsDetailsOptionsPage", "Process track artists"))
self.gb_area_details.setTitle(_translate("AdditionalArtistsDetailsOptionsPage", "Include Area Details"))
self.label_2.setText(_translate("AdditionalArtistsDetailsOptionsPage", "<html><head/><body><p>This option determines whether or not County and Municipality information is included in the artist location variables created. Regardless of this setting, this information will be included if a County or Municipality is the area specified for an artist.</p></body></html>"))
self.cb_area_details.setText(_translate("AdditionalArtistsDetailsOptionsPage", "Include area details"))
Loading

0 comments on commit 9228334

Please sign in to comment.