-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Scientific-Guy/master
v0.0.2 Update
- Loading branch information
Showing
12 changed files
with
219 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Spotify-Api.py ChangeLog | ||
|
||
--- | ||
|
||
## v0.0.2 - Stable Version | ||
|
||
- Custom Exceptions | ||
- Styled Source Codes | ||
- Cleared Unwanted Codes and Shrinked to look decent | ||
|
||
--- | ||
|
||
## v0.0.2 - Stable Dev Version | ||
|
||
- Initial Update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,48 @@ | ||
# Import Packages | ||
import requests | ||
from .Util import encodeURIComponent | ||
from .exceptions import LimitOutOfRangeError | ||
|
||
from .Exception import * | ||
|
||
# Album Class | ||
class Album(): | ||
|
||
def __init__(self, token: str): | ||
self.token = token | ||
|
||
def search(self, query: str, limit: int = 1): | ||
link = 'https://api.spotify.com/v1/search' | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('Limit must be under 50.') | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header, | ||
params={ | ||
'q': encodeURIComponent(query), | ||
'type': 'album', | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
|
||
def get(self, albumID: str): | ||
link = 'https://api.spotify.com/v1/albums/' + albumID | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header | ||
).json() | ||
|
||
def get_tracks(self, albumID: str, limit: int = 1): | ||
link = 'https://api.spotify.com/v1/albums/' + albumID + '/tracks' | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('Limit must be under 50.') | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header, | ||
params={ | ||
'offset': 0, | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
def __init__(self, token: str): | ||
self.token = token | ||
|
||
def search(self, query: str, limit: int = 1): | ||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('limit must be under 50') | ||
|
||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/search', | ||
headers={'Authorization': 'Bearer ' + self.token}, | ||
params={ | ||
'q': encodeURIComponent(query), | ||
'type': 'album', | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
|
||
def get(self, albumID: str): | ||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/albums/' + albumID, | ||
headers={'Authorization': 'Bearer ' + self.token} | ||
).json() | ||
|
||
def get_tracks(self, albumID: str, limit: int = 1): | ||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('limit must be under 50') | ||
|
||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/albums/' + albumID + '/tracks', | ||
headers={'Authorization': 'Bearer ' + self.token}, | ||
params={ | ||
'offset': 0, | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,63 @@ | ||
# Import Packages | ||
import requests | ||
from .Util import encodeURIComponent | ||
from .exceptions import LimitOutOfRangeError | ||
from .Exception import * | ||
|
||
# Artist Class | ||
class Artist(): | ||
|
||
def __init__(self, token: str): | ||
self.token = token | ||
|
||
def search(self, query: str, limit: int = 1): | ||
link = 'https://api.spotify.com/v1/search' | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('Limit must be under 50.') | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header, | ||
params={ | ||
'q': encodeURIComponent(query), | ||
'type': 'artist', | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
|
||
def get(self, artistID: str): | ||
link = 'https://api.spotify.com/v1/artists/' + artistID | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header | ||
).json() | ||
|
||
def albums(self, artistID: str, limit: int = 1): | ||
link = 'https://api.spotify.com/v1/artists/' + artistID + '/albums' | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('Limit must be under 50.') | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header, | ||
params={ | ||
'include_groups': 'single', | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
|
||
def top_tracks(self, artistID: str): | ||
link = 'https://api.spotify.com/v1/artists/' + artistID + '/top-tracks' | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header, | ||
params={ | ||
'country': 'US' | ||
} | ||
).json() | ||
|
||
def related_artists(self, artistID: str): | ||
link = 'https://api.spotify.com/v1/artists/' + artistID + '/related-artists' | ||
header = {'Authorization': 'Bearer ' + self.token} | ||
|
||
return requests.request( | ||
'GET', | ||
link, | ||
headers=header | ||
).json() | ||
def __init__(self, token: str): | ||
self.token = token | ||
|
||
def search(self, query: str, limit: int = 1): | ||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('limit must be under 50') | ||
|
||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/search', | ||
headers={'Authorization': 'Bearer ' + self.token}, | ||
params={ | ||
'q': encodeURIComponent(query), | ||
'type': 'artist', | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
|
||
def get(self, artistID: str): | ||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/artists/' + artistID, | ||
headers={'Authorization': 'Bearer ' + self.token} | ||
).json() | ||
|
||
def albums(self, artistID: str, limit: int = 1): | ||
if not 0 < limit < 50: | ||
raise LimitOutOfRangeError('limit must be under 50') | ||
|
||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/artists/' + artistID + '/albums', | ||
headers={'Authorization': 'Bearer ' + self.token}, | ||
params={ | ||
'include_groups': 'single', | ||
'limit': limit, | ||
'market': 'US' | ||
} | ||
).json() | ||
|
||
def top_tracks(self, artistID: str): | ||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/artists/' + artistID + '/top-tracks', | ||
headers={'Authorization': 'Bearer ' + self.token}, | ||
params={'country': 'US'} | ||
).json() | ||
|
||
def related_artists(self, artistID: str): | ||
return requests.request( | ||
'GET', | ||
'https://api.spotify.com/v1/artists/' + artistID + '/related-artists', | ||
headers={'Authorization': 'Bearer ' + self.token} | ||
).json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Base Error Class | ||
class SpotifyApiError(Exception): | ||
|
||
def __init__(self, message): | ||
self.message = message | ||
|
||
def __str__(self): | ||
return self.message | ||
|
||
# Limit out of range error | ||
class LimitOutOfRangeError(SpotifyApiError): | ||
|
||
def __init__(self, message): | ||
super().__init__(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.