1 # -*- coding: utf-8 -*-
3 Fetching similar artists from last.fm web services
6 # standard library import
9 # third parties components
12 from ...lib.plugin import Plugin
13 from ...lib.track import Track
16 class RandomFallBack(Plugin):
18 def __init__(self, daemon):
19 super().__init__(daemon)
21 if not self.plugin_conf:
23 self.mode = self.plugin_conf.get('flavour', None)
24 if self.mode not in ['pure', 'sensible', 'genre']:
25 self.log.warning('Bad value for flavour, '
26 '{} not in ["pure", "sensible", "genre"]'.format(self.mode))
29 def get_played_artist(self,):
30 """Constructs list of already played artists.
32 duration = self.daemon.config.getint('sima', 'history_duration')
33 tracks_from_db = self.daemon.sdb.get_history(duration=duration)
34 # Construct Track() objects list from database history
35 artists = [ tr[-1] for tr in tracks_from_db ]
38 def callback_need_track_fb(self):
39 art = random.choice(self.player.list('artist'))
40 self.log.debug('Random art: {}'.format(art))
41 if self.mode == 'sensitive':
42 played_art = self.get_played_artist()
44 art = random.choice(self.player.list('artist'))
45 if art not in played_art:
47 trk = random.choice(self.player.find_track(art))
48 self.log.info('random fallback ({}): {}'.format(self.mode, trk))
54 # vim: ai ts=4 sw=4 sts=4 expandtab