Skip to content

Commit

Permalink
Merge pull request #100 from shazamio/dev2.0
Browse files Browse the repository at this point in the history
Dev2.0
  • Loading branch information
dotX12 committed Apr 27, 2024
2 parents f088e77 + 0d5eb63 commit 11df2e4
Show file tree
Hide file tree
Showing 36 changed files with 668 additions and 369 deletions.
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:3.8",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": "ffmpeg"
}
}
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
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
18 changes: 18 additions & 0 deletions examples/album_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import asyncio
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
albums = await shazam.search_album(album_id=1544741796)
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())
7 changes: 4 additions & 3 deletions examples/artist_albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

async def main():
shazam = Shazam()
artist_id = 1202214602
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.name} - {i.attributes.track_count} {i.attributes.release_date}")
print(
f"{i.id} | {i.attributes.artist_name} ->>>>>>>> {i.attributes.name} - {i.attributes.track_count} {i.attributes.release_date}"
)


loop = asyncio.get_event_loop_policy().get_event_loop()
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
12 changes: 6 additions & 6 deletions examples/top_tracks_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@


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
serialized = Serialize.playlists(top_ten_moscow_tracks)
print(serialized)

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


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

0 comments on commit 11df2e4

Please sign in to comment.