added spotify chart puller

This commit is contained in:
aj 2019-10-06 16:30:35 +01:00
parent 28c76bbd83
commit f715286e9c
2 changed files with 30 additions and 0 deletions

View File

30
spotfm/charts/chart.py Normal file
View 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