Skip to content

Commit

Permalink
Merge pull request #26 from dotX12/dev
Browse files Browse the repository at this point in the history
Big Update...

Fix SEARCH_ARTIST (New API Method)
Added black.
Micro fixes.
Added tests.
Change min python 3.6 to 3.8+
  • Loading branch information
dotX12 authored Jun 23, 2022
2 parents 630ecd2 + e2618c1 commit 7ec7a3d
Show file tree
Hide file tree
Showing 37 changed files with 622 additions and 527 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: test

on: pull_request

jobs:
test:
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v2
- name: Set up python
id: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.8
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install ffmpeg
id: setup-ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v1

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Check black
run: |
poetry add --dev black --allow-prereleases
poetry run black . --check
- name: Run tests
run: |
source .venv/bin/activate
pytest tests/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<br><br>

<img width="1000" src="https://user-images.githubusercontent.com/64792903/109359596-ca561a00-7896-11eb-9c93-9cf1f283b1a5.png">
🎵 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.
🎵 Is a FREE asynchronous library from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp. Includes all the methods that Shazam has, including searching for a song by file.

-----
</p>
Expand Down
5 changes: 3 additions & 2 deletions examples/about_artist.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import asyncio
from shazamio import Shazam, serialize_artist
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
artist_id = 43328183
about_artist = await shazam.artist_about(artist_id)
serialized = serialize_artist(about_artist)
serialized = Serialize.artist(about_artist)

print(about_artist) # dict
print(serialized) # serialized from dataclass factory


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
5 changes: 3 additions & 2 deletions examples/about_track.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import asyncio
from shazamio import Shazam, serialize_track
from shazamio import Shazam, Serialize


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

print(about_track) # dict
print(serialized) # serialized from dataclass factory


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
8 changes: 6 additions & 2 deletions examples/recognize_song.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import asyncio
from shazamio import Shazam
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
out = await shazam.recognize_song('data/dora.ogg')
out = await shazam.recognize_song("data/dora.ogg")
print(out)

serialized = Serialize.full_track(out)
print(serialized)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
4 changes: 2 additions & 2 deletions examples/recognize_track_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

async def main():
shazam = Shazam()
out = await shazam.recognize_song('data/dora.ogg')
out = await shazam.recognize_song("data/dora.ogg")
result = Serialize.full_track(data=out)
youtube_data = await shazam.get_youtube_data(link=result.track.youtube_link)
serialized_youtube = Serialize.youtube(data=youtube_data)
print(serialized_youtube.uri)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

1 change: 1 addition & 0 deletions examples/related_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ async def main():
# ONLY №3, №4 SONG
print(related)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
9 changes: 5 additions & 4 deletions examples/search_artists.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import asyncio
from shazamio import Shazam, serialize_artist
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
artists = await shazam.search_artist(query='Lil', limit=5)
for artist in artists['artists']['hits']:
serialized = serialize_artist(data=artist)
artists = await shazam.search_artist(query="LIL", limit=5)
for artist in artists["artists"]["hits"]:
serialized = Serialize.artist(data=artist)
print(serialized)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
3 changes: 2 additions & 1 deletion examples/search_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

async def main():
shazam = Shazam()
tracks = await shazam.search_track(query='Lil', limit=5)
tracks = await shazam.search_track(query="Lil", limit=5)
print(tracks)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
1 change: 1 addition & 0 deletions examples/song_listening_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ async def main():
count = await shazam.listening_counter(track_id=track_id)
print(count)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
11 changes: 7 additions & 4 deletions examples/top_artist_tracks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import asyncio
from shazamio import Shazam, serialize_track
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
artist_id = 201896832
top_three_artist_tracks = await shazam.artist_top_tracks(artist_id=artist_id, limit=3)
for track in top_three_artist_tracks['tracks']:
serialized_track = serialize_track(data=track)
top_three_artist_tracks = await shazam.artist_top_tracks(
artist_id=artist_id, limit=3
)
for track in top_three_artist_tracks["tracks"]:
serialized_track = Serialize.track(data=track)
print(serialized_track)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
11 changes: 7 additions & 4 deletions examples/top_tracks_city.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import asyncio
from shazamio import Shazam, serialize_track
from shazamio import Shazam, Serialize


async def main():
shazam = Shazam()
top_ten_moscow_tracks = await shazam.top_city_tracks(country_code='RU', city_name='Moscow', limit=10)
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)
for track in top_ten_moscow_tracks["tracks"]:
serialized = Serialize.track(data=track)
# SERIALIZE FROM DATACLASS FACTORY
print(serialized)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
10 changes: 5 additions & 5 deletions examples/top_tracks_country.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import asyncio
from shazamio import Shazam, serialize_track
from shazamio import Shazam, Serialize


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", 5)
for track in top_five_track_from_amsterdam["tracks"]:
serialized = Serialize.track(data=track)
print(serialized)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

7 changes: 4 additions & 3 deletions examples/top_tracks_genre_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

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


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
10 changes: 6 additions & 4 deletions examples/top_tracks_genre_world.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import asyncio
from shazamio import Shazam, serialize_track, GenreMusic
from shazamio import Shazam, Serialize, GenreMusic


async def main():
shazam = Shazam()
top_rock_in_the_world = await shazam.top_world_genre_tracks(genre=GenreMusic.ROCK, limit=10)
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)
for track in top_rock_in_the_world["tracks"]:
serialized_track = Serialize.track(data=track)
print(serialized_track)


Expand Down
7 changes: 4 additions & 3 deletions examples/top_world_tracks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import asyncio
from shazamio import Shazam, serialize_track
from shazamio import Shazam, Serialize


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)
for track in top_world_tracks["tracks"]:
serialized = Serialize.track(track)
print(serialized)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
16 changes: 10 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "shazamio"
version = "0.0.6"
description = "Is a asynchronous framework from reverse engineered Shazam API written in Python 3.6+ with asyncio and aiohttp."
description = "Is a asynchronous framework from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp."
authors = ["dotX12"]
license = "MIT License"
keywords = ["python", "shazam", "music", "recognize", "api", "async", "asyncio", "aiohttp", "identification"]
Expand All @@ -14,12 +14,15 @@ include = [
]

[tool.poetry.dependencies]
python = "^3.6"
numpy = "^1.20.1"
aiohttp = "^3.7.4"
pydub = "^0.24.1"
python = "^3.8"
numpy = "^1.22.1"
aiohttp = "^3.8.1"
pydub = "^0.25.1"
dataclass-factory = "^2.10.1"
aiofiles = "^0.6.0"
aiofiles = "^0.8.0"
pytest = "^7.1.2"
pytest-asyncio = "^0.18.3"
anyio = "^3.6.1"

[build-system]
requires = ["poetry-core>=1.0.0", "wheel>=0.36,<1.0", "poetry>=1.1,<2", "virtualenv==20.0.33"]
Expand All @@ -28,4 +31,5 @@ build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "-scoped"
asyncio_mode = "auto"
filterwarnings = ["ignore::DeprecationWarning"]
16 changes: 10 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
aiofiles
aiohttp
async-timeout==3.0.1
aiofiles~=0.8.0
aiohttp~=3.8.1
attrs==20.3.0
chardet==3.0.4
dataclass-factory
dataclass-factory==2.10.1
idna==3.1
multidict==5.1.0
numpy
pydub==0.24.1
numpy~=1.22.1
pydub==0.25.1
typing-extensions==3.7.4.3
yarl==1.6.3

pytest~=7.1.2
setuptools~=60.7.0
pytest-asyncio~=0.18.3
anyio~=3.6.1
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/dotX12/ShazamIO",
install_requires=['aiohttp', 'pydub', 'numpy', 'aiofiles', 'dataclass-factory',],
install_requires=[
"aiohttp",
"pydub",
"numpy",
"aiofiles",
"dataclass-factory",
],
packages=setuptools.find_packages(),
python_requires='>=3.6',

python_requires=">=3.8",
)
7 changes: 1 addition & 6 deletions shazamio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@
from .converter import Geo
from .enums import GenreMusic

__all__ = (
'Serialize',
'Shazam',
'Geo',
'GenreMusic'
)
__all__ = ("Serialize", "Shazam", "Geo", "GenreMusic")
Loading

0 comments on commit 7ec7a3d

Please sign in to comment.