added spotify chart puller
This commit is contained in:
parent
28c76bbd83
commit
f715286e9c
0
spotfm/charts/__init__.py
Normal file
0
spotfm/charts/__init__.py
Normal file
30
spotfm/charts/chart.py
Normal file
30
spotfm/charts/chart.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from spotframework.net.network import Network as SpotNetwork
|
||||||
|
from spotframework.model.uri import Uri
|
||||||
|
from fmframework.net.network import Network as FmNetwork
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
||||||
|
fmnet: FmNetwork,
|
||||||
|
period: FmNetwork.Range,
|
||||||
|
limit: int,
|
||||||
|
username: str = None):
|
||||||
|
logger.info(f'pulling {period.name} chart')
|
||||||
|
|
||||||
|
chart = fmnet.get_top_tracks(period=period, username=username, limit=limit)
|
||||||
|
|
||||||
|
spotify_chart = []
|
||||||
|
for track in chart:
|
||||||
|
spotify_search = spotnet.search(query_types=[Uri.ObjectType.track],
|
||||||
|
track=track.name,
|
||||||
|
artist=track.artist.name,
|
||||||
|
response_limit=5).tracks
|
||||||
|
if len(spotify_search) > 0:
|
||||||
|
spotify_chart.append(spotify_search[0])
|
||||||
|
else:
|
||||||
|
logger.warning('no search tracks returned')
|
||||||
|
|
||||||
|
return spotify_chart
|
||||||
|
|
Loading…
Reference in New Issue
Block a user