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

Dev to master #89

Closed
wants to merge 12 commits into from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ loop.run_until_complete(main())

<details>
<summary>
<i>🔝🎶🌏🎸 Top tracks in word by genre</i>
<i>🔝🎶🌏🎸 Top tracks in world by genre</i>
</summary>

Get world tracks by certain genre<br>
Expand All @@ -347,7 +347,7 @@ loop.run_until_complete(main())

<details>
<summary>
<i>🔝🎶🌏Top tracks in word</i>
<i>🔝🎶🌏Top tracks in world</i>
</summary>

Get the best tracks from all over the world<br>
Expand Down
16 changes: 16 additions & 0 deletions examples/artist_albums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import asyncio
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
artist_id = 1202214602
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}")


loop = asyncio.get_event_loop_policy().get_event_loop()
loop.run_until_complete(main())
28 changes: 24 additions & 4 deletions examples/recognize_song.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import asyncio
import logging

from shazamio import Shazam, Serialize

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()
out = await shazam.recognize_song("data/dora.ogg")
print(out)

serialized = Serialize.full_track(out)
print(serialized)
# pass path (deprecated)
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")
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)

# pass bytes
with open("data/dora.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)


loop = asyncio.get_event_loop_policy().get_event_loop()
Expand Down
2 changes: 2 additions & 0 deletions examples/song_listening_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ async def main():
track_id = 559284007
count = await shazam.listening_counter(track_id=track_id)
print(count)
count_many = await shazam.listening_counter_many(track_ids=[559284007, 684678069])
print(count_many)


loop = asyncio.get_event_loop_policy().get_event_loop()
Expand Down
676 changes: 566 additions & 110 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ pytest = "^7.2.0"
pytest-asyncio = "^0.20.3"
anyio = "^3.6.2"
pydantic = "^1.10.2"
shazamio-core = "^1.0.1"
aiohttp-retry = "^2.8.3"

[build-system]
requires = ["poetry-core>=1.0.0", "wheel>=0.36,<1.0", "poetry>=1.1,<2", "virtualenv==20.0.33"]
requires = ["poetry-core>=1.0.0", "wheel>=0.36,<1.0"]
build-backend = "poetry.core.masonry.api"


Expand All @@ -37,4 +39,4 @@ filterwarnings = ["ignore::DeprecationWarning"]


[tool.black]
line-length = 100
line-length = 100
4 changes: 2 additions & 2 deletions shazamio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .serializers import Serialize
from .api import Shazam
from .converter import Geo
from .converter import GeoService
from .enums import GenreMusic

__all__ = ("Serialize", "Shazam", "Geo", "GenreMusic")
__all__ = ("Serialize", "Shazam", "GeoService", "GenreMusic")
9 changes: 1 addition & 8 deletions shazamio/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ def get_next_signature(self) -> Optional[DecodedMessage]:
)
self.samples_processed += 128

returned_signature = self.next_signature

self.next_signature = DecodedMessage()
self.next_signature.sample_rate_hz = 16000
self.next_signature.number_samples = 0
self.next_signature.frequency_band_to_sound_peaks = {}

self.ring_buffer_of_samples: RingBuffer[int] = RingBuffer(buffer_size=2048, default_value=0)
self.fft_outputs: RingBuffer[List[float]] = RingBuffer(
buffer_size=256, default_value=[0.0 * 1025]
Expand All @@ -115,7 +108,7 @@ def get_next_signature(self) -> Optional[DecodedMessage]:
buffer_size=256, default_value=[0] * 1025
)

return returned_signature
return self.next_signature

def process_input(self, s16le_mono_samples: List[int]):
self.next_signature.number_samples += len(s16le_mono_samples)
Expand Down
Loading
Loading