Skip to content

Commit

Permalink
Merge pull request #57 from dotX12/dev
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
dotX12 authored May 5, 2023
2 parents d45aae2 + d7f5000 commit 20f3d41
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ from shazamio import Shazam
async def main():
shazam = Shazam()
track_id = 546891609
related = await shazam.related_tracks(track_id=track_id, limit=5, start_from=2)
related = await shazam.related_tracks(track_id=track_id, limit=5, offset=2)
# ONLY №3, №4 SONG
print(related)

Expand Down
2 changes: 1 addition & 1 deletion examples/related_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
async def main():
shazam = Shazam()
track_id = 546891609
related = await shazam.related_tracks(track_id=track_id, limit=5, start_from=2)
related = await shazam.related_tracks(track_id=track_id, limit=5, offset=2)
# ONLY №3, №4 SONG
print(related)

Expand Down
1 change: 1 addition & 0 deletions examples/top_artist_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def main():
),
)
serialized = Serialize.artist_v2(about_artist)
print(serialized)
for i in serialized.data[0].views.top_songs.data:
pprint(i.attributes.name)

Expand Down
6 changes: 4 additions & 2 deletions examples/top_tracks_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@


async def main():
shazam = Shazam()
shazam = Shazam(language="GB")
top_ten_moscow_tracks = await shazam.top_city_tracks(
country_code="RU", city_name="Moscow", limit=10
country_code="RU",
city_name="Moscow",
limit=10,
)
print(top_ten_moscow_tracks)
# ALL TRACKS DICT
Expand Down
115 changes: 81 additions & 34 deletions shazamio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,29 @@ class Shazam(Converter, Geo, Request):
"""Is asynchronous framework for reverse engineered Shazam API written in Python 3.7 with
asyncio and aiohttp."""

def __init__(self, language: str = "ES"):
def __init__(self, language: str = "en-US", endpoint_country: str = "GB"):
super().__init__(language=language)
self.language = language
self.endpoint_country = endpoint_country

async def top_world_tracks(self, limit: int = 200, start_from: int = 0) -> Dict[str, Any]:
async def top_world_tracks(self, limit: int = 200, offset: int = 0) -> Dict[str, Any]:
"""
Search top world tracks
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs.
:param start_from: A parameter that determines with which song to display the request.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict tracks
"""
return await self.request(
"GET",
ShazamUrl.TOP_TRACKS_WORLD.format(
limit,
start_from,
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
),
headers=self.headers(),
)
Expand All @@ -67,7 +69,10 @@ async def artist_about(

return await self.request(
"GET",
ShazamUrl.SEARCH_ARTIST_V2.format(artist_id, language=self.language),
ShazamUrl.SEARCH_ARTIST_V2.format(
endpoint_country=self.endpoint_country,
artist_id=artist_id,
),
params=params_dict,
headers=self.headers(),
)
Expand All @@ -83,8 +88,9 @@ async def track_about(self, track_id: int) -> Dict[str, Any]:
return await self.request(
"GET",
ShazamUrl.ABOUT_TRACK.format(
track_id,
language=self.language,
endpoint_country=self.endpoint_country,
track_id=track_id,
),
headers=self.headers(),
)
Expand All @@ -93,7 +99,7 @@ async def top_country_tracks(
self,
country_code: Union[CountryCode, str],
limit: int = 200,
start_from: int = 0,
offset: int = 0,
) -> Dict[str, Any]:
"""
Get the best tracks by country code
Expand All @@ -102,18 +108,19 @@ async def top_country_tracks(
:param country_code: ISO 3166-3 alpha-2 code. Example: RU,NL,UA
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs.
:param start_from: A parameter that determines with which song to display the request.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict songs
"""
return await self.request(
"GET",
ShazamUrl.TOP_TRACKS_COUNTRY.format(
country_code,
limit,
start_from,
language=self.language,
endpoint_country=self.endpoint_country,
country_code=country_code,
limit=limit,
offset=offset,
),
headers=self.headers(),
)
Expand All @@ -123,7 +130,7 @@ async def top_city_tracks(
country_code: Union[CountryCode, str],
city_name: str,
limit: int = 200,
start_from: int = 0,
offset: int = 0,
) -> Dict[str, Any]:
"""
Retrieving information from an artist profile
Expand All @@ -134,7 +141,7 @@ async def top_city_tracks(
Example: Budapest, Moscow
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs.
:param start_from: A parameter that determines with which song to display the request.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict songs
Expand All @@ -143,16 +150,20 @@ async def top_city_tracks(
return await self.request(
"GET",
ShazamUrl.TOP_TRACKS_CITY.format(
city_id,
limit,
start_from,
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
city_id=city_id,
),
headers=self.headers(),
)

async def top_world_genre_tracks(
self, genre: Union[GenreMusic, int], limit: int = 100, start_from: int = 0
self,
genre: Union[GenreMusic, int],
limit: int = 100,
offset: int = 0,
) -> Dict[str, Any]:
"""
Get world tracks by certain genre
Expand All @@ -168,14 +179,20 @@ async def top_world_genre_tracks(
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs.
:param start_from: A parameter that determines with which song to display the request.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter
to your own.
:return: dict songs
"""
return await self.request(
"GET",
ShazamUrl.GENRE_WORLD.format(genre, limit, start_from, language=self.language),
ShazamUrl.GENRE_WORLD.format(
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
genre=genre,
),
headers=self.headers(),
)

Expand All @@ -184,7 +201,7 @@ async def top_country_genre_tracks(
country_code: str,
genre: Union[GenreMusic, int],
limit: int = 200,
start_from: int = 0,
offset: int = 0,
) -> Dict[str, Any]:
"""
The best tracks by a genre in the country
Expand All @@ -199,21 +216,29 @@ async def top_country_genre_tracks(
REGIONAL_MEXICANO = 18
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs
:param start_from: A parameter that determines with which song to display the request.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict songs
"""
return await self.request(
"GET",
ShazamUrl.GENRE_COUNTRY.format(
country_code, genre, limit, start_from, language=self.language
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
country=country_code,
genre=genre,
),
headers=self.headers(),
)

async def related_tracks(
self, track_id: int, limit: int = 20, start_from: int = 0
self,
track_id: int,
limit: int = 20,
offset: int = 0,
) -> Dict[str, Any]:
"""
Similar songs based song id
Expand All @@ -222,49 +247,70 @@ async def related_tracks(
https://www.shazam.com/track/549952578/
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs
:param start_from: A parameter that determines with which song to display the request.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict tracks
"""
return await self.request(
"GET",
ShazamUrl.RELATED_SONGS.format(track_id, start_from, limit, language=self.language),
ShazamUrl.RELATED_SONGS.format(
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
track_id=track_id,
),
headers=self.headers(),
)

async def search_artist(self, query: str, limit: int = 10) -> Dict[str, Any]:
async def search_artist(
self,
query: str,
limit: int = 10,
offset: int = 0,
) -> Dict[str, Any]:
"""
Search all artists by prefix or fullname
:param query: Artist name or search prefix
:param limit: Determines how many artists the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 artists.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict artists
"""
return await self.request(
"GET",
ShazamUrl.SEARCH_ARTIST.format(
query,
limit,
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
query=query,
),
headers=self.headers(),
)

async def search_track(self, query: str, limit: int = 10) -> Dict[str, Any]:
async def search_track(self, query: str, limit: int = 10, offset: int = 0) -> Dict[str, Any]:
"""
Search all tracks by prefix
:param query: Track full title or prefix title
:param limit: Determines how many songs the maximum can be in the request.
Example: If 5 is specified, the query will return no more than 5 songs.
:param offset: A parameter that determines with which song to display the request.
The default is 0. If you want to skip the first few songs, set this parameter to
your own.
:return: dict songs
"""
return await self.request(
"GET",
ShazamUrl.SEARCH_MUSIC.format(
query,
limit,
language=self.language,
endpoint_country=self.endpoint_country,
limit=limit,
offset=offset,
query=query,
),
headers=self.headers(),
)
Expand Down Expand Up @@ -322,9 +368,10 @@ async def send_recognize_request(self, sig: DecodedMessage) -> Dict[str, Any]:
return await self.request(
"POST",
ShazamUrl.SEARCH_FROM_FILE.format(
str(uuid.uuid4()).upper(),
str(uuid.uuid4()).upper(),
language=self.language,
endpoint_country=self.endpoint_country,
uuid_1=str(uuid.uuid4()).upper(),
uuid_2=str(uuid.uuid4()).upper(),
),
headers=self.headers(),
json=data,
Expand Down
Loading

0 comments on commit 20f3d41

Please sign in to comment.