removed named exception in favor of ValueError when non-music YouTube channel id given to get_artist. Minor changes to structure of related artists property in get_artist, added thumbnails.
This commit is contained in:
parent
3272e1f523
commit
b1ecae3d9f
5 changed files with 10 additions and 24 deletions
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
import configparser
|
import configparser
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, '..')
|
sys.path.insert(0, '..')
|
||||||
from ytmusicapi.ytmusic import YTMusic, YouTubeChannelIDIsNotArtistException # noqa: E402
|
from ytmusicapi.ytmusic import YTMusic # noqa: E402
|
||||||
|
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.read('./test.cfg', 'utf-8')
|
config.read('./test.cfg', 'utf-8')
|
||||||
|
|
@ -55,16 +55,11 @@ class TestYTMusic(unittest.TestCase):
|
||||||
# test correctness of related artists
|
# test correctness of related artists
|
||||||
related = results['related']['results']
|
related = results['related']['results']
|
||||||
|
|
||||||
# all should have 3 keys per item
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len([x for x in related if set(x.keys()) == {"browseId", "subscribers", "title"}]),
|
len([
|
||||||
len(related))
|
x for x in related
|
||||||
|
if set(x.keys()) == {"browseId", "subscribers", "title", "thumbnails"}
|
||||||
# test names of some related artists
|
]), len(related))
|
||||||
related_artist_names = {x['title'] for x in related}
|
|
||||||
self.assertTrue(
|
|
||||||
{"The Verve", "Liam Gallagher", "Noel Gallagher", "Beady Eye",
|
|
||||||
"The Stone Roses"}.issubset(related_artist_names))
|
|
||||||
|
|
||||||
results = youtube.get_artist("UCLZ7tlKC06ResyDmEStSrOw") # no album year
|
results = youtube.get_artist("UCLZ7tlKC06ResyDmEStSrOw") # no album year
|
||||||
self.assertGreaterEqual(len(results), 11)
|
self.assertGreaterEqual(len(results), 11)
|
||||||
|
|
@ -75,8 +70,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
def test_get_artist_for_non_youtube_music_channel(self):
|
def test_get_artist_for_non_youtube_music_channel(self):
|
||||||
# all YouTube channel IDs can be looked up in YouTube Music, but the page they return will not necessarily return any music content
|
# all YouTube channel IDs can be looked up in YouTube Music, but the page they return will not necessarily return any music content
|
||||||
non_music_channel_id = "UCUcpVoi5KkJmnE3bvEhHR0Q" # e.g. https://music.youtube.com/channel/UCUcpVoi5KkJmnE3bvEhHR0Q
|
non_music_channel_id = "UCUcpVoi5KkJmnE3bvEhHR0Q" # e.g. https://music.youtube.com/channel/UCUcpVoi5KkJmnE3bvEhHR0Q
|
||||||
self.assertRaises(YouTubeChannelIDIsNotArtistException, youtube.get_artist,
|
self.assertRaises(ValueError, youtube.get_artist, non_music_channel_id)
|
||||||
non_music_channel_id)
|
|
||||||
|
|
||||||
def test_get_artist_albums(self):
|
def test_get_artist_albums(self):
|
||||||
artist = youtube.get_artist("UCAeLFBCQS7FvI8PvBrWvSBg")
|
artist = youtube.get_artist("UCAeLFBCQS7FvI8PvBrWvSBg")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from ytmusicapi._version import __version__
|
from ytmusicapi._version import __version__
|
||||||
from ytmusicapi.ytmusic import YTMusic, YouTubeChannelIDIsNotArtistException
|
from ytmusicapi.ytmusic import YTMusic
|
||||||
|
|
||||||
__copyright__ = 'Copyright 2020 sigma67'
|
__copyright__ = 'Copyright 2020 sigma67'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,3 @@ def i18n(method):
|
||||||
return method(self, *method_args, **method_kwargs)
|
return method(self, *method_args, **method_kwargs)
|
||||||
|
|
||||||
return _impl
|
return _impl
|
||||||
|
|
||||||
|
|
||||||
class YouTubeChannelIDIsNotArtistException(Exception):
|
|
||||||
"""
|
|
||||||
Not all YouTube channel IDs have YouTube Music Content, this exception thrown when typical YT Channel ID given
|
|
||||||
to Browser Mixin get_artist method
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
|
|
@ -283,8 +283,7 @@ class BrowsingMixin:
|
||||||
|
|
||||||
if len(results) == 1:
|
if len(results) == 1:
|
||||||
# not a YouTube Music Channel, a standard YouTube Channel ID with no music content was given
|
# not a YouTube Music Channel, a standard YouTube Channel ID with no music content was given
|
||||||
raise YouTubeChannelIDIsNotArtistException(
|
raise ValueError(f"The YouTube Channel ID: {channelId} has no music content.")
|
||||||
f"The YouTube Channel ID: {channelId} has no music content.")
|
|
||||||
|
|
||||||
artist = {'description': None, 'views': None}
|
artist = {'description': None, 'views': None}
|
||||||
header = response['header']['musicImmersiveHeaderRenderer']
|
header = response['header']['musicImmersiveHeaderRenderer']
|
||||||
|
|
|
||||||
|
|
@ -205,5 +205,6 @@ def parse_related_artist(data):
|
||||||
return {
|
return {
|
||||||
'title': nav(item, TITLE_TEXT),
|
'title': nav(item, TITLE_TEXT),
|
||||||
'browseId': nav(item, TITLE + NAVIGATION_BROWSE_ID),
|
'browseId': nav(item, TITLE + NAVIGATION_BROWSE_ID),
|
||||||
'subscribers': nav(item, SUBTITLE)
|
'subscribers': nav(item, SUBTITLE).split(' ')[0],
|
||||||
|
'thumbnails': nav(item, THUMBNAIL_RENDERER),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue