Skip to content

Commit c1a81f9

Browse files
authored
Merge pull request #133 from shazamio/feat/new_version
added support searchparams for recognize, based on shazamio_core
2 parents 27ed16c + aff19f0 commit c1a81f9

File tree

8 files changed

+435
-435
lines changed

8 files changed

+435
-435
lines changed

.github/workflows/auto-black.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v1
13-
- name: Set up Python 3.7
13+
- name: Set up Python 3.9
1414
uses: actions/setup-python@v1
1515
with:
16-
python-version: 3.8
16+
python-version: 3.9
1717
- name: Install Black
1818
run: pip install black
1919
- name: Run black --check .

.github/workflows/pytest.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
id: setup-python
1616
uses: actions/setup-python@v2
1717
with:
18-
python-version: 3.8
18+
python-version: 3.10.15
1919
#----------------------------------------------
2020
# ----- install & configure poetry -----
2121
#----------------------------------------------
@@ -42,16 +42,16 @@ jobs:
4242
id: setup-ffmpeg
4343
uses: FedericoCarboni/setup-ffmpeg@v1
4444
- name: Install libasound2-dev
45-
run: sudo apt-get install -y libasound2-dev build-essential libudev-dev
45+
run: sudo apt-get install -y libasound2-dev build-essential
4646

4747
- name: Install dependencies
4848
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
49-
run: poetry install --only=dev --no-interaction --no-root
49+
run: poetry install --with dev --no-interaction --no-root
5050
#----------------------------------------------
5151
# install your root project, if required
5252
#----------------------------------------------
5353
- name: Install library
54-
run: poetry install --only=dev --no-interaction
54+
run: poetry install --with dev --no-interaction
5555
#----------------------------------------------
5656
# run test suite
5757
#----------------------------------------------

examples/recognize_song.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33

44
from aiohttp_retry import ExponentialRetry
5-
from shazamio import Shazam, Serialize, HTTPClient
5+
from shazamio import Shazam, Serialize, HTTPClient, SearchParams
66

77
logger = logging.getLogger(__name__)
88
logging.basicConfig(
@@ -19,15 +19,14 @@ async def main():
1919
attempts=12, max_timeout=204.8, statuses={500, 502, 503, 504, 429}
2020
),
2121
),
22+
segment_duration_seconds=10,
2223
)
2324

24-
# pass path (deprecated)
25-
# old_version = await shazam.recognize_song(data="data/dora.ogg") # deprecated
26-
# serialized_old = Serialize.full_track(old_version)
27-
# print(serialized_old)
28-
2925
# pass path
30-
new_version_path = await shazam.recognize("data/Gloria.ogg")
26+
new_version_path = await shazam.recognize(
27+
"data/Gloria.ogg",
28+
options=SearchParams(segment_duration_seconds=5),
29+
)
3130
serialized_new_path = Serialize.full_track(new_version_path)
3231
print(serialized_new_path)
3332

poetry.lock

Lines changed: 394 additions & 408 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "shazamio"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
description = "Is a asynchronous framework from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp."
55
authors = ["dotX12"]
66
license = "MIT License"
@@ -15,25 +15,25 @@ include = [
1515

1616
[tool.poetry.dependencies]
1717
python = "^3.10"
18-
numpy = "2.1.2"
18+
numpy = "2.2.2"
1919
aiohttp = "^3.8.3"
2020
pydub = "^0.25.1"
2121
dataclass-factory = "2.16"
2222
aiofiles = "23.2.1"
2323
anyio = "4.3.0"
24-
shazamio-core = "^1.0.7"
2524
aiohttp-retry = "^2.8.3"
2625
pydantic = "2.9.2"
27-
[tool.poetry.dev-dependencies]
26+
shazamio-core = "1.1.2"
27+
28+
[tool.poetry.group.dev.dependencies]
2829
black = {version = "^24.2.0", allow-prereleases = true}
2930
pytest = "8.1.2"
3031
pytest-asyncio = "^0.23.6"
3132

3233
[build-system]
33-
requires = ["poetry-core>=1.0.0", "wheel>=0.36,<1.0"]
34+
requires = ["poetry-core"]
3435
build-backend = "poetry.core.masonry.api"
3536

36-
3737
[tool.pytest.ini_options]
3838
addopts = "-scoped"
3939
asyncio_mode = "auto"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="shazamio",
8-
version="0.7.0",
8+
version="0.8.0",
99
author="dotX12",
1010
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.",
1111
long_description=long_description,

shazamio/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@
33
from .converter import GeoService
44
from .enums import GenreMusic
55
from .client import HTTPClient
6+
from shazamio_core.shazamio_core import SearchParams
67

7-
__all__ = ("Serialize", "Shazam", "GeoService", "GenreMusic", "HTTPClient")
8+
__all__ = (
9+
"Serialize",
10+
"Shazam",
11+
"GeoService",
12+
"GenreMusic",
13+
"HTTPClient",
14+
"SearchParams",
15+
)

shazamio/api.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from aiohttp_retry import ExponentialRetry
88
from pydub import AudioSegment
9-
from shazamio_core import Recognizer, Signature
9+
from shazamio_core import Recognizer, Signature, SearchParams
1010

1111
from .client import HTTPClient
1212
from .converter import Converter, GeoService
@@ -23,18 +23,23 @@
2323

2424

2525
class Shazam(Request):
26-
"""Is asynchronous framework for reverse engineered Shazam API written in Python 3.7 with
27-
asyncio and aiohttp."""
26+
"""
27+
Is asynchronous framework for reverse engineered Shazam API written in Python 3.10+ with
28+
asyncio and aiohttp.
29+
"""
2830

2931
def __init__(
3032
self,
3133
language: str = "en-US",
3234
endpoint_country: str = "GB",
3335
http_client: Optional[HTTPClientInterface] = None,
36+
segment_duration_seconds: int = 10,
3437
):
3538
super().__init__(language=language)
3639

37-
self.core_recognizer = Recognizer()
40+
self.core_recognizer = Recognizer(
41+
segment_duration_seconds=segment_duration_seconds,
42+
)
3843
self.language = language
3944
self.endpoint_country = endpoint_country
4045

@@ -564,6 +569,7 @@ async def recognize(
564569
self,
565570
data: Union[str, bytes, bytearray],
566571
proxy: Optional[str] = None,
572+
options: Optional[SearchParams] = None,
567573
) -> Dict[str, Any]:
568574
"""
569575
All logic and mathematics are transferred to RUST lang.
@@ -572,12 +578,13 @@ async def recognize(
572578
database.
573579
:param data: Path to song file or bytes
574580
:param proxy: Proxy server
581+
:param options: Search parameters
575582
:return: Dictionary with information about the found song
576583
"""
577584
if isinstance(data, (str, pathlib.Path)):
578-
signature = await self.core_recognizer.recognize_path(data)
585+
signature = await self.core_recognizer.recognize_path(value=data, options=options)
579586
elif isinstance(data, (bytes, bytearray)):
580-
signature = await self.core_recognizer.recognize_bytes(data)
587+
signature = await self.core_recognizer.recognize_bytes(value=data, options=options)
581588
else:
582589
raise ValueError("Invalid data type")
583590

0 commit comments

Comments
 (0)