kopia lustrzana https://github.com/Michael-K-Stein/SpotiFile
Implement audio features scraping
rodzic
36ead220fa
commit
383ee9e9dd
|
@ -12,6 +12,8 @@ class SpotifyClient:
|
|||
|
||||
user_data = None
|
||||
|
||||
_api_token = os.getenv('api-token')
|
||||
|
||||
def __init__(self, sp_dc=None, sp_key=None):
|
||||
self.dc = sp_dc
|
||||
self.key = sp_key
|
||||
|
@ -115,7 +117,7 @@ class SpotifyClient:
|
|||
prem_keys[cookie['name']] = cookie['value']
|
||||
return prem_keys
|
||||
|
||||
def get(self, url: str) -> Response:
|
||||
def get(self, url: str, dev:bool=False) -> Response:
|
||||
with requests.session() as session:
|
||||
session.proxies = self._proxy
|
||||
|
||||
|
@ -123,7 +125,7 @@ class SpotifyClient:
|
|||
'User-Agent': self.__USER_AGENT,
|
||||
'Accept': 'application/json',
|
||||
'Client-Token': self._client_token,
|
||||
'Authorization': f'Bearer {self._access_token}',
|
||||
'Authorization': f'Bearer {self._access_token if not dev else self._api_token}',
|
||||
'Origin': 'https://open.spotify.com',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
|
|
|
@ -107,8 +107,8 @@ class SpotifyScraper:
|
|||
for track in self.scrape_album_tracks(album.spotify_id):
|
||||
yield track
|
||||
|
||||
def get(self, url: str) -> Response:
|
||||
return self._client.get(url)
|
||||
def get(self, url: str, dev:bool=False) -> Response:
|
||||
return self._client.get(url, dev=dev)
|
||||
|
||||
def post(self, url: str, payload=None) -> Response:
|
||||
return self._client.post(url, payload=payload)
|
||||
|
@ -125,6 +125,13 @@ class SpotifyScraper:
|
|||
except Exception as ex:
|
||||
return ''
|
||||
|
||||
def get_tracks_features(self, track_ids: list[str]) -> dict[str,str]:
|
||||
resp = self.get(f'https://api.spotify.com/v1/audio-features?ids={",".join(track_ids)}', dev=True).json()
|
||||
features = {}
|
||||
for feature in resp['audio_features']:
|
||||
features[feature['id']] = feature
|
||||
return features
|
||||
|
||||
def get_category_playlist_ids(self, category_id: str, limit=50, offset=0) -> str:
|
||||
playlist_ids = []
|
||||
current_offset = offset
|
||||
|
|
Ładowanie…
Reference in New Issue