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 difflib import get_close_matches
27 from itertools import dropwhile
30 from .meta import Artist
31 from .simastr import SimaStr
32 from ..utils.leven import levenshtein_ratio
34 def blacklist(artist=False, album=False, track=False):
35 #pylint: disable=C0111,W0212
36 field = (album, track)
38 def wrapper(*args, **kwargs):
39 if not args[0].database:
40 return func(*args, **kwargs)
42 boolgen = (bl for bl in field)
43 bl_fun = (cls.database.get_bl_album,
44 cls.database.get_bl_track,)
45 #bl_getter = next(fn for fn, bl in zip(bl_fun, boolgen) if bl is True)
46 bl_getter = next(dropwhile(lambda _: not next(boolgen), bl_fun))
47 #cls.log.debug('using {0} as bl filter'.format(bl_getter.__name__))
49 for elem in func(*args, **kwargs):
50 if bl_getter(elem, add_not=True):
51 #cls.log.debug('Blacklisted "{0}"'.format(elem))
53 if track and cls.database.get_bl_album(elem, add_not=True):
54 # filter album as well in track mode
55 # (artist have already been)
56 cls.log.debug('Blacklisted alb. "{0.album}"'.format(elem))
65 """Player interface to inherit from.
67 When querying player music library for tracks, Player instance *must* return
68 Track objects (usually a list of them)
70 Player instance should expose the following immutable attributes:
80 self.log = logging.getLogger('sima')
83 """Monitor player for change
85 * database player media library has changed
86 * playlist playlist modified
87 * options player options changed: repeat mode, etc…
88 * player player state changed: paused, stopped, skip track…
90 raise NotImplementedError
93 """Any cleanup necessary"""
96 def remove(self, position=0):
97 """Removes the oldest element of the playlist (index 0)
99 raise NotImplementedError
101 def find_track(self, artist, title=None):
103 Find tracks for a specific artist or filtering with a track title
104 >>> player.find_track(Artist('The Beatles'))
105 >>> player.find_track(Artist('Nirvana'), title='Smells Like Teen Spirit')
107 Returns a list of Track objects
109 raise NotImplementedError
111 def find_album(self, artist, album):
113 Find tracks by track's album name
114 >>> player.find_album('Nirvana', 'Nevermind')
116 Returns a list of Track objects
118 raise NotImplementedError
120 def search_albums(self, artist):
122 Find albums by artist's name
123 >>> art = Artist(name='Nirvana')
124 >>> player.search_albums(art)
126 Returns a list of string objects
128 raise NotImplementedError
130 def search_artist(self, artist):
132 Search artists based on a fuzzy search in the media library
133 >>> art = Artist(name='the beatles', mbid=<UUID4>) # mbid optional
134 >>> bea = player.search_artist(art)
136 >>> ['The Beatles', 'Beatles', 'the beatles']
138 Returns an Artist object
140 raise NotImplementedError
142 def disconnect(self):
143 """Closing client connection with the Player
145 raise NotImplementedError
148 """Connect client to the Player
150 raise NotImplementedError
154 raise NotImplementedError
158 raise NotImplementedError
162 raise NotImplementedError
166 raise NotImplementedError
170 raise NotImplementedError
173 # vim: ai ts=4 sw=4 sts=4 expandtab