added last.fm chart playlist engine source
This commit is contained in:
parent
8993682e48
commit
2f44c3b655
0
spotfm/engine/__init__.py
Normal file
0
spotfm/engine/__init__.py
Normal file
44
spotfm/engine/chart_source.py
Normal file
44
spotfm/engine/chart_source.py
Normal file
@ -0,0 +1,44 @@
|
||||
from fmframework.net.network import Network as FmNet
|
||||
from spotframework.net.network import Network as SpotNet
|
||||
|
||||
from spotframework.model.uri import Uri
|
||||
from spotframework.engine.playlistengine import TrackSource, SourceParameter
|
||||
from spotframework.engine.processor.abstract import AbstractProcessor
|
||||
|
||||
from spotfm.charts.chart import get_chart_of_spotify_tracks
|
||||
|
||||
from typing import List
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ChartSource(TrackSource):
|
||||
class Params(SourceParameter):
|
||||
def __init__(self,
|
||||
chart_range: FmNet.Range,
|
||||
limit: int = 50,
|
||||
processors: List[AbstractProcessor] = None):
|
||||
super().__init__(processors=processors, source_type=ChartSource)
|
||||
self.chart_range = chart_range
|
||||
self.limit = limit
|
||||
|
||||
def __init__(self, spotnet: SpotNet, fmnet: SpotNet):
|
||||
super().__init__(net=spotnet)
|
||||
self.fmnet = fmnet
|
||||
|
||||
def load(self):
|
||||
super().load()
|
||||
|
||||
def process(self, params: Params, uris: List[Uri] = None):
|
||||
# TODO add processor support?
|
||||
|
||||
tracks = get_chart_of_spotify_tracks(spotnet=self.net,
|
||||
fmnet=self.fmnet,
|
||||
period=params.chart_range,
|
||||
limit=params.limit)
|
||||
|
||||
if tracks is not None and len(tracks) > 0:
|
||||
return tracks
|
||||
else:
|
||||
logger.error('no tracks returned')
|
Loading…
Reference in New Issue
Block a user