Skip to content

Commit

Permalink
Remove the second artist after feat., ft. or vs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jun 17, 2022
1 parent c3f4e37 commit 945bb3c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 24 deletions.
24 changes: 16 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,22 @@ Usage
$ar_combined_album: “album” without ” (Disc X)”.
Examples: ['Headlines and Deadlines: The Hits of a-ha', 'Die Meistersinger von Nürnberg']
$ar_combined_artist: The first available value of this metatag
order: “albumartist” -> “artist” ->
“albumartist_credit” -> “artist_credit”
$ar_combined_artist: The first non-empty value of the following
list of fields: “albumartist” -> “artist” ->
“albumartist_credit” -> “artist_credit” ->
“albumartist_sort” -> “artist_sort”. If no
value could be determined, then “Unknown” is
assigned. The second artist after “feat.”,
“ft.” or “vs.” is removed.
Examples: ['a-ha', 'Richard Wagner; René Kollo, Helen Donath, ...']
$ar_combined_artist_sort: The first available value of this metatag
order: “albumartist_sort” -> “artist_sort” ->
“ar_combined_artist”
$ar_combined_artist_sort: The first non-empty value of the following
list of fields: “albumartist_sort” ->
“artist_sort” -> “albumartist” -> “artist” ->
“albumartist_credit” -> “artist_credit”. If
no value could be determined, then “Unknown”
is assigned. The second artist after “feat.”,
“ft.” or “vs.” is removed.
Examples: ['a-ha', 'Wagner, Richard; Kollo, René, Donath, Helen...']
$ar_combined_composer: The first not empty field of this field list:
Expand Down Expand Up @@ -948,11 +956,11 @@ Metadata fields
- ``Headlines and Deadlines: The Hits of a-ha``, ``Die Meistersinger von Nürnberg``
* - ar_combined_artist
- common
- The first available value of this metatag order: “albumartist” -> “artist” -> “albumartist_credit” -> “artist_credit”
- The first non-empty value of the following list of fields: “albumartist” -> “artist” -> “albumartist_credit” -> “artist_credit” -> “albumartist_sort” -> “artist_sort”. If no value could be determined, then “Unknown” is assigned. The second artist after “feat.”, “ft.” or “vs.” is removed.
- ``a-ha``, ``Richard Wagner; René Kollo, Helen Donath, ...``
* - ar_combined_artist_sort
- common
- The first available value of this metatag order: “albumartist_sort” -> “artist_sort” -> “ar_combined_artist”
- The first non-empty value of the following list of fields: “albumartist_sort” -> “artist_sort” -> “albumartist” -> “artist” -> “albumartist_credit” -> “artist_credit”. If no value could be determined, then “Unknown” is assigned. The second artist after “feat.”, “ft.” or “vs.” is removed.
- ``a-ha``, ``Wagner, Richard; Kollo, René, Donath, Helen...``
* - ar_combined_composer
- common
Expand Down
20 changes: 16 additions & 4 deletions audiorename/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,30 @@
'Die Meistersinger von Nürnberg'],
},
'ar_combined_artist': {
'description': 'The first available value of this metatag order: '
'description': 'The first non-empty value of the following list of '
'fields: '
'“albumartist” -> “artist” -> “albumartist_credit” '
'-> “artist_credit”',
'-> “artist_credit” -> “albumartist_sort” -> '
'“artist_sort”. '
'If no value could be determined, then “Unknown” is '
'assigned. '
'The second artist after “feat.”, “ft.” or “vs.” '
'is removed.',
'category': 'common',
'examples': ['a-ha',
'Richard Wagner; René Kollo, Helen Donath, ...'],
'data_type': 'str',
},
'ar_combined_artist_sort': {
'description': 'The first available value of this metatag order: '
'description': 'The first non-empty value of the following list of '
'fields: '
'“albumartist_sort” -> “artist_sort” -> '
'“ar_combined_artist”',
'“albumartist” -> “artist” -> “albumartist_credit” -> '
'“artist_credit”. '
'If no value could be determined, then “Unknown” is '
'assigned. '
'The second artist after “feat.”, “ft.” or “vs.” '
'is removed.',
'category': 'common',
'examples': ['a-ha', 'Wagner, Richard; Kollo, René, Donath, Helen...'],
'data_type': 'str',
Expand Down
19 changes: 16 additions & 3 deletions audiorename/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ def ar_initial_artist(self) -> str:
"""
return self._find_initials(self.ar_combined_artist_sort)

@staticmethod
def __remove_feat_vs_second_artist(artist: str) -> str:
"""Give only the first artist, remove the second after ``feat.``,
``ft.`` or ``vs.``"""
return re.sub(r'\s+(feat|ft|vs)\.?\s.*', '', artist,
flags=re.IGNORECASE)

@property
def ar_combined_artist(self) -> str:
"""Uses:
Expand All @@ -371,8 +378,10 @@ def ar_combined_artist(self) -> str:
* ``phrydy.mediafile.MediaFile.artist_credit``
* ``phrydy.mediafile.MediaFile.albumartist_sort``
* ``phrydy.mediafile.MediaFile.artist_sort``
Removes the second artist after ``feat.``, ``ft.`` or ``vs.``.
"""
out: str = ''
out: str
if self.albumartist:
out = self.albumartist
elif self.artist:
Expand All @@ -389,7 +398,7 @@ def ar_combined_artist(self) -> str:
else:
out = 'Unknown'

return out
return Meta.__remove_feat_vs_second_artist(out)

@property
def ar_combined_artist_sort(self) -> str:
Expand All @@ -401,8 +410,10 @@ def ar_combined_artist_sort(self) -> str:
* ``phrydy.mediafile.MediaFile.artist``
* ``phrydy.mediafile.MediaFile.albumartist_credit``
* ``phrydy.mediafile.MediaFile.artist_credit``
Removes the second artist after ``feat.``, ``ft.`` or ``vs.``.
"""
out: str = ''
out: str
if self.albumartist_sort:
out = self.albumartist_sort
elif self.artist_sort:
Expand All @@ -419,6 +430,8 @@ def ar_combined_artist_sort(self) -> str:
else:
out = 'Unknown'

out = Meta.__remove_feat_vs_second_artist(out)

if self.shell_friendly:
out = out.replace(', ', '_')

Expand Down
20 changes: 14 additions & 6 deletions doc/source/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ Comande line interface
$ar_combined_album: “album” without ” (Disc X)”.
Examples: ['Headlines and Deadlines: The Hits of a-ha', 'Die Meistersinger von Nürnberg']
$ar_combined_artist: The first available value of this metatag
order: “albumartist” -> “artist” ->
“albumartist_credit” -> “artist_credit”
$ar_combined_artist: The first non-empty value of the following
list of fields: “albumartist” -> “artist” ->
“albumartist_credit” -> “artist_credit” ->
“albumartist_sort” -> “artist_sort”. If no
value could be determined, then “Unknown” is
assigned. The second artist after “feat.”,
“ft.” or “vs.” is removed.
Examples: ['a-ha', 'Richard Wagner; René Kollo, Helen Donath, ...']
$ar_combined_artist_sort: The first available value of this metatag
order: “albumartist_sort” -> “artist_sort” ->
“ar_combined_artist”
$ar_combined_artist_sort: The first non-empty value of the following
list of fields: “albumartist_sort” ->
“artist_sort” -> “albumartist” -> “artist” ->
“albumartist_credit” -> “artist_credit”. If
no value could be determined, then “Unknown”
is assigned. The second artist after “feat.”,
“ft.” or “vs.” is removed.
Examples: ['a-ha', 'Wagner, Richard; Kollo, René, Donath, Helen...']
$ar_combined_composer: The first not empty field of this field list:
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions test/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def test_field_ar_initial_artist(self):

def test_field_ar_combined_artist(self):
self.assertTrue('ar_combined_artist' in self.output)
self.assertTrue('The first available' in self.output)
self.assertTrue('The first non-empty value' in self.output)

def test_field_ar_combined_artist_sort(self):
self.assertTrue('ar_combined_artist_sort' in self.output)
self.assertTrue('The first available' in self.output)
self.assertTrue('The first non-empty value' in self.output)

# composer
def test_field_ar_initial_composer(self):
Expand Down
10 changes: 9 additions & 1 deletion test/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_real_world(self):


# ar_combined_artist (integration)
class TestPropertyArtistSafe(unittest.TestCase):
class TestPropertyArCombinedArtist(unittest.TestCase):

def test_artist(self):
meta = get_meta('meta', 'artist.mp3')
Expand All @@ -237,6 +237,14 @@ def test_albumartist(self):
meta = get_meta('meta', 'albumartist.mp3')
self.assertEqual(meta.ar_combined_artist, 'albumartist')

def test_removal_feat_vs(self):
meta = get_meta(
'real-world', 'f', 'Fatboy-Slim',
'Song-For-Shelter-Pete-Heller_2001',
'01_Song-for-Shelter-Pete-Hellers.mp3')
self.assertEqual(meta.ar_combined_artist, 'Fatboy Slim')
self.assertEqual(meta.ar_combined_artist_sort, 'Fatboy Slim')


# ar_combined_artist (unit)
class TestPropertyArtistSafeUnit(unittest.TestCase):
Expand Down

0 comments on commit 945bb3c

Please sign in to comment.