1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2009-2014 Jack Kaliko <jack@azylum.org>
4 # This file is part of sima
6 # sima is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # sima is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with sima. If not, see <http://www.gnu.org/licenses/>.
22 # Add decorator to filter through history?
24 # standard library import
26 from itertools import dropwhile
30 def blacklist(artist=False, album=False, track=False):
31 #pylint: disable=C0111,W0212
32 field = (album, track)
34 def wrapper(*args, **kwargs):
35 if not args[0].database:
36 return func(*args, **kwargs)
38 boolgen = (bl for bl in field)
39 bl_fun = (cls.database.get_bl_album,
40 cls.database.get_bl_track,)
41 #bl_getter = next(fn for fn, bl in zip(bl_fun, boolgen) if bl is True)
42 bl_getter = next(dropwhile(lambda _: not next(boolgen), bl_fun))
43 #cls.log.debug('using {0} as bl filter'.format(bl_getter.__name__))
45 for elem in func(*args, **kwargs):
46 if bl_getter(elem, add_not=True):
47 #cls.log.debug('Blacklisted "{0}"'.format(elem))
49 if track and cls.database.get_bl_album(elem, add_not=True):
50 # filter album as well in track mode
51 # (artist have already been)
52 cls.log.debug('Blacklisted alb. "{0.album}"'.format(elem))
61 """Player interface to inherit from.
63 When querying player music library for tracks, Player instance *must* return
64 Track objects (usually a list of them)
66 Player instance should expose the following immutable attributes:
76 self.log = logging.getLogger('sima')
79 """Monitor player for change
81 * database player media library has changed
82 * playlist playlist modified
83 * options player options changed: repeat mode, etc…
84 * player player state changed: paused, stopped, skip track…
86 raise NotImplementedError
89 """Any cleanup necessary"""
92 def remove(self, position=0):
93 """Removes the oldest element of the playlist (index 0)
95 raise NotImplementedError
97 def find_track(self, artist, title=None):
99 Find tracks for a specific artist or filtering with a track title
100 >>> player.find_track(Artist('The Beatles'))
101 >>> player.find_track(Artist('Nirvana'), title='Smells Like Teen Spirit')
103 Returns a list of Track objects
105 raise NotImplementedError
107 def find_album(self, artist, album):
109 Find tracks by track's album name
110 >>> player.find_album('Nirvana', 'Nevermind')
112 Returns a list of Track objects
114 raise NotImplementedError
116 def search_albums(self, artist):
118 Find albums by artist's name
119 >>> art = Artist(name='Nirvana')
120 >>> player.search_albums(art)
122 Returns a list of string objects
124 raise NotImplementedError
126 def search_artist(self, artist):
128 Search artists based on a fuzzy search in the media library
129 >>> art = Artist(name='the beatles', mbid=<UUID4>) # mbid optional
130 >>> bea = player.search_artist(art)
132 >>> ['The Beatles', 'Beatles', 'the beatles']
134 Returns an Artist object
136 raise NotImplementedError
138 def disconnect(self):
139 """Closing client connection with the Player
141 raise NotImplementedError
144 """Connect client to the Player
146 raise NotImplementedError
150 #pylint: disable=C0111
151 raise NotImplementedError
155 #pylint: disable=C0111
156 raise NotImplementedError
160 #pylint: disable=C0111
161 raise NotImplementedError
165 #pylint: disable=C0111
166 raise NotImplementedError
170 #pylint: disable=C0111
171 raise NotImplementedError
174 # vim: ai ts=4 sw=4 sts=4 expandtab