-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting album from song/artist #99
Comments
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}")
i see, albums collab many artists
|
@dotX12 What I need is which album/albums are associated to a certain track. That is what I am looking for:
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())
|
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:
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. |
Exactly! |
@robtekky two steps. Do you only need the album title or do you want to somehow work with the tracks within that album? 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 (#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
I am afraid I will have to use something like 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 .... |
Not in my case, at least not always. This is what I get from
There is an artist_id (adamid), but there is no albumadamid. |
https://www.shazam.com/track/45053306/tarantula |
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. |
released in 0.6.0 |
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/artist_id ?
The dict returned by
recognize
does not seem to contain such information.I have also tried with
track_about
, and artist_albums, to no avail.thanks.
The text was updated successfully, but these errors were encountered: