]> kaliko git repositories - mpd-sima.git/blob - sima/plugins/internal/randomfallback.py
Get version from sima.core in setup script
[mpd-sima.git] / sima / plugins / internal / randomfallback.py
1 # -*- coding: utf-8 -*-
2 """
3 Fetching similar artists from last.fm web services
4 """
5
6 # standart library import
7 import random
8
9 # third parties componants
10
11 # local import
12 from ...lib.plugin import Plugin
13 from ...lib.track import Track
14
15
16 class RandomFallBack(Plugin):
17
18     def __init__(self, daemon):
19         Plugin.__init__(self, daemon)
20         self.daemon = daemon
21         ##
22         self.to_add = list()
23
24     def get_history(self):
25         """Constructs list of Track for already played titles.
26         """
27         duration = self.daemon.config.getint('sima', 'history_duration')
28         tracks_from_db = self.daemon.sdb.get_history(duration=duration,)
29         # Construct Track() objects list from database history
30         played_tracks = [Track(artist=tr[-1], album=tr[1], title=tr[2],
31                                file=tr[3]) for tr in tracks_from_db]
32         return played_tracks
33
34     def callback_need_track_fb(self):
35         mode = self.plugin_conf.get('flavour')
36         art = random.choice(self.player.list('artist'))
37         self.log.debug('Random art: {}'.format(art))
38         trk  = random.choice(self.player.find_track(art))
39         self.log.info('random fallback ({}): {}'.format(mode, trk))
40         return [trk]
41
42
43
44 # VIM MODLINE
45 # vim: ai ts=4 sw=4 sts=4 expandtab