Closed robtekky closed 7 months ago
What do you want to get, what attributes?
artist_id = 1300793014
albums = await shazam.artist_albums(artist_id=artist_id)
serialized = Serialize.artist_albums(data=albums)
for i in serialized.data:
print(f"{i.attributes.artist_name} ->>>>>>>> {i.attributes.name} - {i.attributes.track_count} {i.attributes.release_date}")
BONES ->>>>>>>> FromBeyondTheGrave - 12 2020-11-07
BONES ->>>>>>>> IFeelLikeDirt - 14 2019-11-29
BONES ->>>>>>>> InLovingMemory - 17 2021-06-18
BONES ->>>>>>>> Offline - 16 2020-02-25
BONES ->>>>>>>> TeenWitch - 17 2014-02-25
BONES & Eddy Baker ->>>>>>>> SparrowsCreek - 10 2019-02-11
BONES ->>>>>>>> UnderTheWillowTree - 19 2019-05-03
BONES ->>>>>>>> Unrendered - 18 2017-04-21
Xavier Wulf & BONES ->>>>>>>> Caves - EP - 6 2013-12-14
BONES & Lyson ->>>>>>>> Remains - 13 2020-05-31
i see, albums collab many artists
BONES & Eddy Baker ->>>>>>>> SparrowsCreek - 10 2019-02-11
Xavier Wulf & BONES ->>>>>>>> Caves - EP - 6 2013-12-14
BONES & Lyson ->>>>>>>> Remains - 13 2020-05-31
@dotX12 Thanks for the prompt reply.
What I need is which album/albums are associated to a certain track.
I know the artist_albums
function returns all albums for the given artist, but it does not contain a list of track titles included into each album.
That is what I am looking for:
Thanks.
@dotX12 Thanks for the prompt reply.
What I need is which album/albums are associated to a certain track. I know the
artist_albums
function returns all albums for the given artist, but it does not contain a list of track titles included into each album.That is what I am looking for:
- the list of album(s) for the given artist, and including the given track title.
Thanks.
do u need this?
import asyncio
from shazamio import Shazam, Serialize
async def main():
shazam = Shazam()
albums = await shazam.search_album(album_id=1538894474)
serialized = Serialize.album_info(data=albums)
for i in serialized.data[0].relationships.tracks.data:
msg = f"{i.id} | {i.attributes.album_name} | {i.attributes.artist_name} [{i.attributes.name}]"
print(msg)
loop = asyncio.get_event_loop_policy().get_event_loop()
loop.run_until_complete(main())
1538894476 | FromBeyondTheGrave | BONES [FromBeyondTheGrave]
1538894477 | FromBeyondTheGrave | BONES [Ashes]
1538894478 | FromBeyondTheGrave | BONES [2Stroke]
1538894479 | FromBeyondTheGrave | BONES [Equipped]
1538894480 | FromBeyondTheGrave | BONES [.223]
1538894481 | FromBeyondTheGrave | BONES [WhoGoesThere]
1538894482 | FromBeyondTheGrave | BONES [BarbwireRibCage]
1538894483 | FromBeyondTheGrave | BONES [TombstoneKiller]
1538894484 | FromBeyondTheGrave | BONES [SkeletonRaps]
1538894485 | FromBeyondTheGrave | BONES [RedAlert]
1538894486 | FromBeyondTheGrave | BONES [Cement]
1538894487 | FromBeyondTheGrave | BONES [DarkShadowBlunts]
Ummmm, not exactly. Although maybe it can end up working well ...
In your example, you have the album id already known.
If I want to get that, I think I will need to get all albums associated to the artist id, and for each of those albums, do your stuff ....
Basically, my logic will be something like the following:
Thriller
, from Michael Jackson
. For that, I only have the mp3 file, with no artist, no title and no album added to its metadata.Shazam.recognize
function to get the artist_id, the artist name and the title of the track.Shazam.artist_albums
to get all the albums of the given artist id.Shazam.album_info
to get the tracks inside, until we find a track with title equal to the title obtained on step 2.Hope this makes sense .....
I will give it a try and let you know.
Thanks!
Ummmm, not exacly. Although maybe it can end up working well ...
In your example, you have the album id already known.
If I want to get that, I think I will need to get all albums associated to the artist id, and for each of those albums, do your stuff ....
Basically, my logic will be something like the following:
- Let's assume that I want to know the album name of the track
Thriller
, fromMichael Jackson
. For that, I only have the mp3 file, with no artist, no title and no album added to its metadata.- First, I use the
Shazam.recognize
function to get the artist_id, the artist name and the title of the track.- then, I will use
Shazam.artist_albums
to get all the albums of the given artist id.- and now, I will iterate thru the obtained albums, caling
Shazam.album_info
to get the tracks inside, until we find a track with title equal to the title obtained on step 2.Hope this makes sense .....
I will give it a try and let you know.
Thanks!
The code I provided above has not yet been added. If I understand correctly, you need to find out from the file with the song which album this song is in?
Exactly!
@robtekky two steps.
Do you only need the album title or do you want to somehow work with the tracks within that album? If only the name of the album - as a result there is a lot of different data, for example here.
import asyncio
import logging
from typing import Optional
from aiohttp_retry import ExponentialRetry
from shazamio import Shazam, HTTPClient
logger = logging.getLogger(__name__)
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - [%(filename)s:%(lineno)d - %(funcName)s()] - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
def get_album_name(data: dict[str, any]) -> Optional[str]:
for element in data["sections"]:
if element["type"] == "SONG":
for item in element["metadata"]:
if item["title"] == "Album":
return item["text"]
async def main():
shazam = Shazam(
http_client=HTTPClient(
retry_options=ExponentialRetry(
attempts=12, max_timeout=204.8, statuses={500, 502, 503, 504, 429}
),
),
)
new_version_path = await shazam.recognize("data/Gloria.ogg")
album_name = get_album_name(data=new_version_path["track"])
print(album_name)
loop = asyncio.get_event_loop_policy().get_event_loop()
loop.run_until_complete(main())
But if for some reason this is not enough for you, you can make an additional request on shazam to find out more details about this album. I haven't released search_album to pypi yet, but you can try pulling changes from the dev2.0 (https://github.com/shazamio/ShazamIO/pull/100) branch (again, if you really need it), maybe the function above will suffice.
import asyncio
import logging
from aiohttp_retry import ExponentialRetry
from shazamio import Shazam, Serialize, HTTPClient
logger = logging.getLogger(__name__)
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - [%(filename)s:%(lineno)d - %(funcName)s()] - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
async def main():
shazam = Shazam(
http_client=HTTPClient(
retry_options=ExponentialRetry(
attempts=12, max_timeout=204.8, statuses={500, 502, 503, 504, 429}
),
),
)
new_version_path = await shazam.recognize("data/Gloria.ogg")
album_info = await shazam.search_album(album_id=new_version_path["track"]["albumadamid"])
album_serialized = Serialize.album_info(data=album_info)
# Get album name
print(album_serialized.data[0].attributes.name)
# And get all tracks in album
for i in album_serialized.data[0].relationships.tracks.data:
msg = (
f"{i.id} | {i.attributes.album_name} | {i.attributes.artist_name} [{i.attributes.name}]"
)
print(msg)
loop = asyncio.get_event_loop_policy().get_event_loop()
loop.run_until_complete(main())
You can analyze the response from Shazam recognize (json) yourself and see what data it returns :)
Yeah, thanks, that is what I did .... not sure if I overlooked it somehow though ....
I will give it a try and get back to you.
Thanks.
Unfortunately, using the get_album_name
function you posted, I get None for the album name most of the times.
It seems what we get when recognize
function is called does not normally contain the album name inside.
search_album
is not an option for me, since I do not have the album id to be used as input parameter.
I am afraid I will have to use something like Spotipy
library additionally in order to get the album name for a given song title.
Thanks
Unfortunately, using the
get_album_name
function you posted, I get None for the album name most of the times. It seems what we get whenrecognize
function is called does not normally contain the album name inside.
search_album
is not an option for me, since I do not have the album id to be used as input parameter.I am afraid I will have to use something like
Spotipy
library additionally in order to get the album name for a given song title.Thanks
But the album identifier is in the response when calling the recognize function :/
result_recognize = await shazam.recognize("data/Gloria.ogg")
album_id = result_recognize["track"]["albumadamid"]
album_info = await shazam.search_album(album_id=album_id)
album_serialized = Serialize.album_info(data=album_info)
# Get album name
print(album_serialized.data[0].attributes.name)
ah ok, I will try that and post the results here ....
But the album identifier is in the response when calling the recognize function :/
Not in my case, at least not always.
This is what I get from recognize
for song title: Tarantula, artist: Smashing Pumpkins:
{'matches': [{'id': '216933643', 'offset': 109.620734375, 'timeskew': -0.00013494492, 'frequencyskew': 0.00012087822}], 'location': {'accuracy': 0.01}, 'timestamp': 2323680605, 'timezone': 'Europe/Moscow', 'track': {'layout': '5', 'type': 'MUSIC', 'key': '45053306', 'title': 'Tarantula', 'subtitle': 'The Smashing Pumpkins', 'images': {'background': 'https://is1-ssl.mzstatic.com/image/thumb/AMCArtistImages126/v4/93/48/c5/9348c5e3-6424-7911-c6cc-ea9b31b47664/0153beec-a084-4288-8731-e35a168593e3_ami-identity-8e1c3d516591a3f1ae95545b0ce45c27-2023-10-31T15-40-58.980Z_cropped.png/800x800cc.jpg', 'coverart': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg', 'coverarthq': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg'}, 'share': {'subject': 'Tarantula - The Smashing Pumpkins', 'text': 'Tarantula by The Smashing Pumpkins', 'href': 'https://www.shazam.com/track/45053306/tarantula', 'image': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg', 'twitter': 'I used @Shazam to discover Tarantula by The Smashing Pumpkins.', 'html': 'https://www.shazam.com/snippets/email-share/45053306?lang=en-US&country=GB', 'avatar': 'https://is1-ssl.mzstatic.com/image/thumb/AMCArtistImages126/v4/93/48/c5/9348c5e3-6424-7911-c6cc-ea9b31b47664/0153beec-a084-4288-8731-e35a168593e3_ami-identity-8e1c3d516591a3f1ae95545b0ce45c27-2023-10-31T15-40-58.980Z_cropped.png/800x800cc.jpg', 'snapchat': 'https://www.shazam.com/partner/sc/track/45053306'}, 'hub': {'type': 'APPLEMUSIC', 'image': 'https://images.shazam.com/static/icons/hub/ios/v5/applemusic_{scalefactor}.png', 'options': [{'caption': 'OPEN IN', 'actions': [{'name': 'hub:applemusic:subscribe', 'type': 'applemusicopen', 'uri': 'https://music.apple.com/subscribe?mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=music&itsct=Shazam_ios'}, {'name': 'hub:applemusic:subscribe', 'type': 'uri', 'uri': 'https://music.apple.com/subscribe?mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=music&itsct=Shazam_ios'}], 'beacondata': {'type': 'open', 'providername': 'applemusic'}, 'image': 'https://images.shazam.com/static/icons/hub/ios/v5/overflow-open-option_{scalefactor}.png', 'type': 'open', 'listcaption': 'Open in Apple Music', 'overflowimage': 'https://images.shazam.com/static/icons/hub/ios/v5/applemusic-overflow_{scalefactor}.png', 'colouroverflowimage': False, 'providername': 'applemusic'}], 'providers': [{'caption': 'Open in Spotify', 'images': {'overflow': 'https://images.shazam.com/static/icons/hub/ios/v5/spotify-overflow_{scalefactor}.png', 'default': 'https://images.shazam.com/static/icons/hub/ios/v5/spotify_{scalefactor}.png'}, 'actions': [{'name': 'hub:spotify:searchdeeplink', 'type': 'uri', 'uri': 'spotify:search:Tarantula%20The%20Smashing%20Pumpkins'}], 'type': 'SPOTIFY'}, {'caption': 'Open in Deezer', 'images': {'overflow': 'https://images.shazam.com/static/icons/hub/ios/v5/deezer-overflow_{scalefactor}.png', 'default': 'https://images.shazam.com/static/icons/hub/ios/v5/deezer_{scalefactor}.png'}, 'actions': [{'name': 'hub:deezer:searchdeeplink', 'type': 'uri', 'uri': 'deezer-query://www.deezer.com/play?query=%7Btrack%3A%27Tarantula%27%20artist%3A%27The+Smashing+Pumpkins%27%7D'}], 'type': 'DEEZER'}], 'explicit': False, 'displayname': 'APPLE MUSIC'}, 'sections': [{'type': 'SONG', 'metapages': [{'image': 'https://is1-ssl.mzstatic.com/image/thumb/AMCArtistImages126/v4/93/48/c5/9348c5e3-6424-7911-c6cc-ea9b31b47664/0153beec-a084-4288-8731-e35a168593e3_ami-identity-8e1c3d516591a3f1ae95545b0ce45c27-2023-10-31T15-40-58.980Z_cropped.png/800x800cc.jpg', 'caption': 'The Smashing Pumpkins'}, {'image': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg', 'caption': 'Tarantula'}], 'tabname': 'Song', 'metadata': []}, {'type': 'VIDEO', 'tabname': 'Video', 'youtubeurl': 'https://cdn.shazam.com/video/v3/-/GB/iphone/45053306/youtube/video?q=The+Smashing+Pumpkins+%22Tarantula%22'}, {'type': 'RELATED', 'url': 'https://cdn.shazam.com/shazam/v3/en-US/GB/iphone/-/tracks/track-similarities-id-45053306?startFrom=0&pageSize=20&connected=', 'tabname': 'Related'}], 'url': 'https://www.shazam.com/track/45053306/tarantula', 'artists': [{'id': '42', 'adamid': '1646302'}], 'genres': {'primary': 'Hard Rock'}, 'urlparams': {'{tracktitle}': 'Tarantula', '{trackartist}': 'The+Smashing+Pumpkins'}, 'highlightsurls': {'artisthighlightsurl': 'https://cdn.shazam.com/video/v3/en-US/GB/iphone/1646302/highlights?affiliate=mttnagencyid%3Ds2n%26mttnsiteid%3D125115%26mttn3pid%3DApple-Shazam%26mttnsub1%3DShazam_ios%26mttnsub2%3D5348615A-616D-3235-3830-44754D6D5973%26itscg%3D30201%26app%3Dmusic%26itsct%3DShazam_ios'}, 'relatedtracksurl': 'https://cdn.shazam.com/shazam/v3/en-US/GB/iphone/-/tracks/track-similarities-id-45053306?startFrom=0&pageSize=20&connected='}, 'tagid': 'F45B7EC2-2EE4-49E1-8657-619F4C043D2C'}
There is an artist_id (adamid), but there is no albumadamid.
But the album identifier is in the response when calling the recognize function :/
Not in my case, at least not always.
This is what I get from
recognize
for song title: Tarantula, artist: Smashing Pumpkins:
{'matches': [{'id': '216933643', 'offset': 109.620734375, 'timeskew': -0.00013494492, 'frequencyskew': 0.00012087822}], 'location': {'accuracy': 0.01}, 'timestamp': 2323680605, 'timezone': 'Europe/Moscow', 'track': {'layout': '5', 'type': 'MUSIC', 'key': '45053306', 'title': 'Tarantula', 'subtitle': 'The Smashing Pumpkins', 'images': {'background': 'https://is1-ssl.mzstatic.com/image/thumb/AMCArtistImages126/v4/93/48/c5/9348c5e3-6424-7911-c6cc-ea9b31b47664/0153beec-a084-4288-8731-e35a168593e3_ami-identity-8e1c3d516591a3f1ae95545b0ce45c27-2023-10-31T15-40-58.980Z_cropped.png/800x800cc.jpg', 'coverart': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg', 'coverarthq': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg'}, 'share': {'subject': 'Tarantula - The Smashing Pumpkins', 'text': 'Tarantula by The Smashing Pumpkins', 'href': 'https://www.shazam.com/track/45053306/tarantula', 'image': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg', 'twitter': 'I used @Shazam to discover Tarantula by The Smashing Pumpkins.', 'html': 'https://www.shazam.com/snippets/email-share/45053306?lang=en-US&country=GB', 'avatar': 'https://is1-ssl.mzstatic.com/image/thumb/AMCArtistImages126/v4/93/48/c5/9348c5e3-6424-7911-c6cc-ea9b31b47664/0153beec-a084-4288-8731-e35a168593e3_ami-identity-8e1c3d516591a3f1ae95545b0ce45c27-2023-10-31T15-40-58.980Z_cropped.png/800x800cc.jpg', 'snapchat': 'https://www.shazam.com/partner/sc/track/45053306'}, 'hub': {'type': 'APPLEMUSIC', 'image': 'https://images.shazam.com/static/icons/hub/ios/v5/applemusic_{scalefactor}.png', 'options': [{'caption': 'OPEN IN', 'actions': [{'name': 'hub:applemusic:subscribe', 'type': 'applemusicopen', 'uri': 'https://music.apple.com/subscribe?mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=music&itsct=Shazam_ios'}, {'name': 'hub:applemusic:subscribe', 'type': 'uri', 'uri': 'https://music.apple.com/subscribe?mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=music&itsct=Shazam_ios'}], 'beacondata': {'type': 'open', 'providername': 'applemusic'}, 'image': 'https://images.shazam.com/static/icons/hub/ios/v5/overflow-open-option_{scalefactor}.png', 'type': 'open', 'listcaption': 'Open in Apple Music', 'overflowimage': 'https://images.shazam.com/static/icons/hub/ios/v5/applemusic-overflow_{scalefactor}.png', 'colouroverflowimage': False, 'providername': 'applemusic'}], 'providers': [{'caption': 'Open in Spotify', 'images': {'overflow': 'https://images.shazam.com/static/icons/hub/ios/v5/spotify-overflow_{scalefactor}.png', 'default': 'https://images.shazam.com/static/icons/hub/ios/v5/spotify_{scalefactor}.png'}, 'actions': [{'name': 'hub:spotify:searchdeeplink', 'type': 'uri', 'uri': 'spotify:search:Tarantula%20The%20Smashing%20Pumpkins'}], 'type': 'SPOTIFY'}, {'caption': 'Open in Deezer', 'images': {'overflow': 'https://images.shazam.com/static/icons/hub/ios/v5/deezer-overflow_{scalefactor}.png', 'default': 'https://images.shazam.com/static/icons/hub/ios/v5/deezer_{scalefactor}.png'}, 'actions': [{'name': 'hub:deezer:searchdeeplink', 'type': 'uri', 'uri': 'deezer-query://www.deezer.com/play?query=%7Btrack%3A%27Tarantula%27%20artist%3A%27The+Smashing+Pumpkins%27%7D'}], 'type': 'DEEZER'}], 'explicit': False, 'displayname': 'APPLE MUSIC'}, 'sections': [{'type': 'SONG', 'metapages': [{'image': 'https://is1-ssl.mzstatic.com/image/thumb/AMCArtistImages126/v4/93/48/c5/9348c5e3-6424-7911-c6cc-ea9b31b47664/0153beec-a084-4288-8731-e35a168593e3_ami-identity-8e1c3d516591a3f1ae95545b0ce45c27-2023-10-31T15-40-58.980Z_cropped.png/800x800cc.jpg', 'caption': 'The Smashing Pumpkins'}, {'image': 'https://is1-ssl.mzstatic.com/image/thumb/Music/38/a2/67/mzi.lukgwqjh.jpg/400x400cc.jpg', 'caption': 'Tarantula'}], 'tabname': 'Song', 'metadata': []}, {'type': 'VIDEO', 'tabname': 'Video', 'youtubeurl': 'https://cdn.shazam.com/video/v3/-/GB/iphone/45053306/youtube/video?q=The+Smashing+Pumpkins+%22Tarantula%22'}, {'type': 'RELATED', 'url': 'https://cdn.shazam.com/shazam/v3/en-US/GB/iphone/-/tracks/track-similarities-id-45053306?startFrom=0&pageSize=20&connected=', 'tabname': 'Related'}], 'url': 'https://www.shazam.com/track/45053306/tarantula', 'artists': [{'id': '42', 'adamid': '1646302'}], 'genres': {'primary': 'Hard Rock'}, 'urlparams': {'{tracktitle}': 'Tarantula', '{trackartist}': 'The+Smashing+Pumpkins'}, 'highlightsurls': {'artisthighlightsurl': 'https://cdn.shazam.com/video/v3/en-US/GB/iphone/1646302/highlights?affiliate=mttnagencyid%3Ds2n%26mttnsiteid%3D125115%26mttn3pid%3DApple-Shazam%26mttnsub1%3DShazam_ios%26mttnsub2%3D5348615A-616D-3235-3830-44754D6D5973%26itscg%3D30201%26app%3Dmusic%26itsct%3DShazam_ios'}, 'relatedtracksurl': 'https://cdn.shazam.com/shazam/v3/en-US/GB/iphone/-/tracks/track-similarities-id-45053306?startFrom=0&pageSize=20&connected='}, 'tagid': 'F45B7EC2-2EE4-49E1-8657-619F4C043D2C'}
There is an artist_id (adamid), but there is no albumadamid.
https://www.shazam.com/track/45053306/tarantula Well, yes, this song does not have an album and there is no way to determine it. And in general, for some reason, even the page for this song does not open for me and I cannot find it in the search...
In general, songs can exist even without albums and the Shazam database may not know everything about it, especially since it is an old song.
well, yeah, in this case there is at least one album containing it (Zeitgeist), but it is true that Shazam database seems to be ignorant about it....
Thanks
I was able to use the dev2.0 branch successfully ......
For metadata tags not available thru Shazam, I have used a fallback to Spotipy.
Feel free to close this issue/request.
Thanks a lot for your help.
I was able to use the dev2.0 branch successfully ......
For metadata tags not available thru Shazam, I have used a fallback to Spotipy.
Feel free to close this issue/request.
Thanks a lot for your help.
released in 0.6.0
I was able to use the dev2.0 branch successfully ......
For metadata tags not available thru Shazam, I have used a fallback to Spotipy.
Feel free to close this issue/request.
Thanks a lot for your help. @robtekky Would you please share how you use spotipy when shazamio doesn't work. I'm struggling to find a solution. Thanks in advance.
@asapsmc
It would be something like the following:
spotify = spotipy.Spotify(
client_credentials_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
)
# All unset attributes need the Spotify album object to be obtained
artist_results = spotify.search(q=f"artist:{artist_name}", type="artist")
if artist_results and (artists := artist_results["artists"]["items"]):
artist = artists[0]
genres_spotify = artist.get("genres", [])
if genre_shazam and genres_spotify:
if genre_shazam.lower() in genres_spotify:
if verbose:
print("\nThe genres in Shazam and in Spotify do match")
else:
if verbose:
print(
f"\nThe genre in Shazam is not included in Spotify: {genre_shazam=}, {genres_spotify=}"
)
songs_with_different_genres.append((title, artist_name, genre_shazam, genres_spotify))
artist_id = artist["id"]
album_results = spotify.artist_albums(artist_id=artist_id)
album_found = False
album_dict = {}
while not album_found:
albums = album_results.get("items", [])
for album in albums:
# Ignore albums being compilations
if album["album_type"] == "compilation":
continue
track_results = spotify.album_tracks(album_id=album["id"]) or {}
tracks = track_results.get("items", [])
for _track in tracks:
if _track["name"].lower() == title.lower():
album_found = True
album_dict = album
break
if album_found:
break
if not album_found:
if album_results["next"]:
album_results = spotify.next(album_results)
else:
break
if album_found:
album_name_spotify = album_dict["name"]
if verbose:
print(f"\nAlbum found: {album_name_spotify}\n")
if album_name_shazam:
if album_name_spotify.lower() == album_name_shazam.lower():
if verbose:
print("The album names in Shazam and in Spotify are identical")
else:
print(f"Different album names: {album_name_shazam=}, {album_name_spotify=}")
songs_with_different_album_names.add((album_name_shazam, album_name_spotify))
year_spotify = get_year(album_dict["release_date"])
if year_shazam:
if year_spotify == year_shazam:
if verbose:
print("The years in Shazam and in Spotify are identical")
else:
if verbose:
print(f"Different years: {year_shazam=}, {year_spotify=}")
songs_with_different_years.add((album_name_shazam, album_name_spotify))
@asapsmc
It would be something like the following:
spotify = spotipy.Spotify( client_credentials_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret) ) # All unset attributes need the Spotify album object to be obtained artist_results = spotify.search(q=f"artist:{artist_name}", type="artist") if artist_results and (artists := artist_results["artists"]["items"]): artist = artists[0] genres_spotify = artist.get("genres", []) if genre_shazam and genres_spotify: if genre_shazam.lower() in genres_spotify: if verbose: print("\nThe genres in Shazam and in Spotify do match") else: if verbose: print( f"\nThe genre in Shazam is not included in Spotify: {genre_shazam=}, {genres_spotify=}" ) songs_with_different_genres.append((title, artist_name, genre_shazam, genres_spotify)) artist_id = artist["id"] album_results = spotify.artist_albums(artist_id=artist_id) album_found = False album_dict = {} while not album_found: albums = album_results.get("items", []) for album in albums: # Ignore albums being compilations if album["album_type"] == "compilation": continue track_results = spotify.album_tracks(album_id=album["id"]) or {} tracks = track_results.get("items", []) for _track in tracks: if _track["name"].lower() == title.lower(): album_found = True album_dict = album break if album_found: break if not album_found: if album_results["next"]: album_results = spotify.next(album_results) else: break if album_found: album_name_spotify = album_dict["name"] if verbose: print(f"\nAlbum found: {album_name_spotify}\n") if album_name_shazam: if album_name_spotify.lower() == album_name_shazam.lower(): if verbose: print("The album names in Shazam and in Spotify are identical") else: print(f"Different album names: {album_name_shazam=}, {album_name_spotify=}") songs_with_different_album_names.add((album_name_shazam, album_name_spotify)) year_spotify = get_year(album_dict["release_date"]) if year_shazam: if year_spotify == year_shazam: if verbose: print("The years in Shazam and in Spotify are identical") else: if verbose: print(f"Different years: {year_shazam=}, {year_spotify=}") songs_with_different_years.add((album_name_shazam, album_name_spotify))
Thank you.
Hello. I am using the
recognize
API to successfully identify a number of different attributes from a given song file:Is there a way to get the list of albums that title has been included into for the given _artist/artistid ?
The dict returned by
recognize
does not seem to contain such information. I have also tried withtrack_about
, and artist_albums, to no avail.thanks.