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

added support searchparams for recognize, based on shazamio_core #133

Merged
merged 13 commits into from
Feb 4, 2025
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/auto-black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
- name: Install Black
run: pip install black
- name: Run black --check .
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
id: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.10.15
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
Expand All @@ -42,16 +42,16 @@ jobs:
id: setup-ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v1
- name: Install libasound2-dev
run: sudo apt-get install -y libasound2-dev build-essential libudev-dev
run: sudo apt-get install -y libasound2-dev build-essential

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --only=dev --no-interaction --no-root
run: poetry install --with dev --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --only=dev --no-interaction
run: poetry install --with dev --no-interaction
#----------------------------------------------
# run test suite
#----------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions examples/recognize_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

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

logger = logging.getLogger(__name__)
logging.basicConfig(
Expand All @@ -19,15 +19,14 @@ async def main():
attempts=12, max_timeout=204.8, statuses={500, 502, 503, 504, 429}
),
),
segment_duration_seconds=10,
)

# 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/Gloria.ogg")
new_version_path = await shazam.recognize(
"data/Gloria.ogg",
options=SearchParams(segment_duration_seconds=5),
)
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)

Expand Down
802 changes: 394 additions & 408 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "shazamio"
version = "0.7.0"
version = "0.8.0"
description = "Is a asynchronous framework from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp."
authors = ["dotX12"]
license = "MIT License"
Expand All @@ -15,25 +15,25 @@ include = [

[tool.poetry.dependencies]
python = "^3.10"
numpy = "2.1.2"
numpy = "2.2.2"
aiohttp = "^3.8.3"
pydub = "^0.25.1"
dataclass-factory = "2.16"
aiofiles = "23.2.1"
anyio = "4.3.0"
shazamio-core = "^1.0.7"
aiohttp-retry = "^2.8.3"
pydantic = "2.9.2"
[tool.poetry.dev-dependencies]
shazamio-core = "1.1.2"

[tool.poetry.group.dev.dependencies]
black = {version = "^24.2.0", allow-prereleases = true}
pytest = "8.1.2"
pytest-asyncio = "^0.23.6"

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


[tool.pytest.ini_options]
addopts = "-scoped"
asyncio_mode = "auto"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="shazamio",
version="0.7.0",
version="0.8.0",
author="dotX12",
description="Is a FREE asynchronous library from reverse engineered Shazam API written in Python 3.6+ with asyncio and aiohttp. Includes all the methods that Shazam has, including searching for a song by file.",
long_description=long_description,
Expand Down
10 changes: 9 additions & 1 deletion shazamio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
from .converter import GeoService
from .enums import GenreMusic
from .client import HTTPClient
from shazamio_core.shazamio_core import SearchParams

__all__ = ("Serialize", "Shazam", "GeoService", "GenreMusic", "HTTPClient")
__all__ = (
"Serialize",
"Shazam",
"GeoService",
"GenreMusic",
"HTTPClient",
"SearchParams",
)
19 changes: 13 additions & 6 deletions shazamio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from aiohttp_retry import ExponentialRetry
from pydub import AudioSegment
from shazamio_core import Recognizer, Signature
from shazamio_core import Recognizer, Signature, SearchParams

from .client import HTTPClient
from .converter import Converter, GeoService
Expand All @@ -23,18 +23,23 @@


class Shazam(Request):
"""Is asynchronous framework for reverse engineered Shazam API written in Python 3.7 with
asyncio and aiohttp."""
"""
Is asynchronous framework for reverse engineered Shazam API written in Python 3.10+ with
asyncio and aiohttp.
"""

def __init__(
self,
language: str = "en-US",
endpoint_country: str = "GB",
http_client: Optional[HTTPClientInterface] = None,
segment_duration_seconds: int = 10,
):
super().__init__(language=language)

self.core_recognizer = Recognizer()
self.core_recognizer = Recognizer(
segment_duration_seconds=segment_duration_seconds,
)
self.language = language
self.endpoint_country = endpoint_country

Expand Down Expand Up @@ -564,6 +569,7 @@ async def recognize(
self,
data: Union[str, bytes, bytearray],
proxy: Optional[str] = None,
options: Optional[SearchParams] = None,
) -> Dict[str, Any]:
"""
All logic and mathematics are transferred to RUST lang.
Expand All @@ -572,12 +578,13 @@ async def recognize(
database.
:param data: Path to song file or bytes
:param proxy: Proxy server
:param options: Search parameters
:return: Dictionary with information about the found song
"""
if isinstance(data, (str, pathlib.Path)):
signature = await self.core_recognizer.recognize_path(data)
signature = await self.core_recognizer.recognize_path(value=data, options=options)
elif isinstance(data, (bytes, bytearray)):
signature = await self.core_recognizer.recognize_bytes(data)
signature = await self.core_recognizer.recognize_bytes(value=data, options=options)
else:
raise ValueError("Invalid data type")

Expand Down
Loading