Skip to content
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

Fix top tracks, small refactoring. #105

Merged
merged 5 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install --only=dev --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
run: poetry install --only=dev --no-interaction
#----------------------------------------------
# run test suite
#----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/about_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

async def main():
shazam = Shazam()
track_id = 552406075
track_id = 53982678
about_track = await shazam.track_about(track_id=track_id)
serialized = Serialize.track(data=about_track)

Expand Down
41 changes: 41 additions & 0 deletions examples/recognize_and_get_album.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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())
28 changes: 14 additions & 14 deletions examples/recognize_song.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import logging

from shazamio import Shazam, Serialize
from aiohttp_retry import ExponentialRetry
from shazamio import Shazam, Serialize, HTTPClient

logger = logging.getLogger(__name__)
logging.basicConfig(
Expand All @@ -12,27 +13,26 @@


async def main():
# shazam = Shazam(
# http_client=HTTPClient(
# retry_options=ExponentialRetry(attempts=12, max_timeout=204.8, statuses={500, 502, 503, 504, 429}),
# ),
# )
# if u need override retry option...

shazam = Shazam()
shazam = Shazam(
http_client=HTTPClient(
retry_options=ExponentialRetry(
attempts=12, max_timeout=204.8, statuses={500, 502, 503, 504, 429}
),
),
)

# pass path (deprecated)
old_version = await shazam.recognize_song(data="data/dora.ogg") # deprecated
serialized_old = Serialize.full_track(old_version)
print(serialized_old)
# old_version = await shazam.recognize_song(data="data/dora.ogg") # deprecated
# serialized_old = Serialize.full_track(old_version)
# print(serialized_old)

# pass path
new_version_path = await shazam.recognize("data/dora.ogg")
new_version_path = await shazam.recognize("data/Gloria.ogg")
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)

# pass bytes
with open("data/dora.ogg", "rb") as file:
with open("data/Gloria.ogg", "rb") as file:
new_version_path = await shazam.recognize(file.read())
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)
Expand Down
14 changes: 7 additions & 7 deletions examples/top_tracks_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@


async def main():
shazam = Shazam(language="GB")
shazam = Shazam(language="EN")
top_ten_moscow_tracks = await shazam.top_city_tracks(
country_code="RU",
city_name="Moscow",
limit=10,
)
print(top_ten_moscow_tracks)
# ALL TRACKS DICT
for track in top_ten_moscow_tracks["tracks"]:
serialized = Serialize.track(data=track)
# SERIALIZE FROM DATACLASS FACTORY
print(serialized)
serialized = Serialize.playlists(top_ten_moscow_tracks)
print(serialized)

# for element in top_ten_moscow_tracks["data"]:
# serialized = Serialize.playlist(data=element)
# print(serialized)


loop = asyncio.get_event_loop_policy().get_event_loop()
Expand Down
9 changes: 6 additions & 3 deletions examples/top_tracks_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

async def main():
shazam = Shazam()
top_five_track_from_amsterdam = await shazam.top_country_tracks("NL", 5)
for track in top_five_track_from_amsterdam["tracks"]:
serialized = Serialize.track(data=track)
top_five_track_from_amsterdam = await shazam.top_country_tracks("NL", 100)
tracks = Serialize.playlists(top_five_track_from_amsterdam)
print(tracks)

for track in top_five_track_from_amsterdam["data"]:
serialized = Serialize.playlist(data=track)
print(serialized)


Expand Down
13 changes: 10 additions & 3 deletions examples/top_tracks_genre_country.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import asyncio
from shazamio import Shazam, GenreMusic
from shazamio import Shazam, GenreMusic, Serialize


async def main():
shazam = Shazam()
top_spain_rap = await shazam.top_country_genre_tracks(
country_code="ES", genre=GenreMusic.HIP_HOP_RAP, limit=4
country_code="ES",
genre=GenreMusic.HIP_HOP_RAP,
limit=4,
)
print(top_spain_rap)
serialized = Serialize.playlists(top_spain_rap)
print(serialized)

for playlist in top_spain_rap["data"]:
serialized = Serialize.playlist(data=playlist)
print(serialized)


loop = asyncio.get_event_loop_policy().get_event_loop()
Expand Down
9 changes: 6 additions & 3 deletions examples/top_tracks_genre_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ async def main():
shazam = Shazam()
top_rock_in_the_world = await shazam.top_world_genre_tracks(genre=GenreMusic.ROCK, limit=10)

for track in top_rock_in_the_world["tracks"]:
serialized_track = Serialize.track(data=track)
print(serialized_track)
serialized = Serialize.playlists(top_rock_in_the_world)
print(serialized)

for playlist in top_rock_in_the_world["data"]:
serialized = Serialize.playlist(data=playlist)
print(serialized)


loop = asyncio.get_event_loop_policy().get_event_loop()
Expand Down
8 changes: 5 additions & 3 deletions examples/top_world_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
async def main():
shazam = Shazam()
top_world_tracks = await shazam.top_world_tracks(limit=10)
print(top_world_tracks)
for track in top_world_tracks["tracks"]:
serialized = Serialize.track(track)
serialized = Serialize.playlists(top_world_tracks)
print(serialized)

for playlist in top_world_tracks["data"]:
serialized = Serialize.playlist(data=playlist)
print(serialized)


Expand Down
Loading
Loading