mirror of
https://github.com/alexta69/metube.git
synced 2026-07-23 13:22:48 +00:00
fix: prefer topic channel for album artist
This commit is contained in:
@@ -87,6 +87,40 @@ class AlbumArtistPostProcessorTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(result['album_artist'], 'ScHoolboy Q')
|
self.assertEqual(result['album_artist'], 'ScHoolboy Q')
|
||||||
|
|
||||||
|
def test_uses_topic_channel_artist_for_joint_album(self):
|
||||||
|
info = {
|
||||||
|
'album': 'Watch the Throne',
|
||||||
|
'artists': ['JAY-Z', 'Kanye West'],
|
||||||
|
'channel': 'JAY-Z & Kanye West - Topic',
|
||||||
|
}
|
||||||
|
|
||||||
|
_, result = self.postprocessor.run(info)
|
||||||
|
|
||||||
|
self.assertEqual(result['album_artist'], 'JAY-Z & Kanye West')
|
||||||
|
|
||||||
|
def test_uses_topic_uploader_and_strips_suffix_for_compilation(self):
|
||||||
|
info = {
|
||||||
|
'album': 'Compilation',
|
||||||
|
'artist': 'Track Artist',
|
||||||
|
'channel': 'Regular Channel',
|
||||||
|
'uploader': 'Various Artists - Topic',
|
||||||
|
}
|
||||||
|
|
||||||
|
_, result = self.postprocessor.run(info)
|
||||||
|
|
||||||
|
self.assertEqual(result['album_artist'], 'Various Artists')
|
||||||
|
|
||||||
|
def test_regular_channel_falls_back_to_main_artist(self):
|
||||||
|
info = {
|
||||||
|
'album': 'Album',
|
||||||
|
'artist': 'Track Artist',
|
||||||
|
'channel': 'Label Channel',
|
||||||
|
}
|
||||||
|
|
||||||
|
_, result = self.postprocessor.run(info)
|
||||||
|
|
||||||
|
self.assertEqual(result['album_artist'], 'Track Artist')
|
||||||
|
|
||||||
def test_preserves_explicit_various_artists(self):
|
def test_preserves_explicit_various_artists(self):
|
||||||
info = {
|
info = {
|
||||||
'album': 'Revenge of the Dreamers III',
|
'album': 'Revenge of the Dreamers III',
|
||||||
|
|||||||
+14
-2
@@ -54,7 +54,9 @@ _LIVE_PROBE_MAX_FAILURES = 5
|
|||||||
|
|
||||||
|
|
||||||
class _AlbumArtistPostProcessor(PostProcessor):
|
class _AlbumArtistPostProcessor(PostProcessor):
|
||||||
"""Fill missing album-artist metadata from yt-dlp's main track artist."""
|
"""Fill missing album-artist metadata from yt-dlp's album-level signals."""
|
||||||
|
|
||||||
|
_TOPIC_SUFFIX = ' - Topic'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _has_value(value: Any) -> bool:
|
def _has_value(value: Any) -> bool:
|
||||||
@@ -76,13 +78,23 @@ class _AlbumArtistPostProcessor(PostProcessor):
|
|||||||
return candidate.split(' · ', 1)[0].strip()
|
return candidate.split(' · ', 1)[0].strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _topic_artist(cls, info) -> Optional[str]:
|
||||||
|
for field in ('channel', 'uploader'):
|
||||||
|
value = info.get(field)
|
||||||
|
if not isinstance(value, str) or not value.endswith(cls._TOPIC_SUFFIX):
|
||||||
|
continue
|
||||||
|
if artist := value[:-len(cls._TOPIC_SUFFIX)].strip():
|
||||||
|
return artist
|
||||||
|
return None
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
if not self._has_value(info.get('album')):
|
if not self._has_value(info.get('album')):
|
||||||
return [], info
|
return [], info
|
||||||
if self._has_value(info.get('album_artist')) or self._has_value(info.get('album_artists')):
|
if self._has_value(info.get('album_artist')) or self._has_value(info.get('album_artists')):
|
||||||
return [], info
|
return [], info
|
||||||
|
|
||||||
if artist := self._main_artist(info):
|
if artist := self._topic_artist(info) or self._main_artist(info):
|
||||||
info['album_artist'] = artist
|
info['album_artist'] = artist
|
||||||
return [], info
|
return [], info
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user