2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2009, 2010 Efrim <efrim@azylum.org> {{{
6 # This program 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 # This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
24 from time import sleep
26 from lib.mpdclass import MPDClass
27 from lib.startop import StartOpt
34 'sw': ['-c', '--crossfade'],
38 'help': 'fade out/fade in over t seconds.'},
42 class Nalbum(StartOpt, MPDClass):
48 'description': 'Jump to next album in playlist.',
53 StartOpt.__init__(self, self.__class__.script_info, NALBUM_OPTS)
54 MPDClass.__init__(self)
57 def _fade(self, io='out'):#{{{
59 end_volum => End volume value
60 mpd_vol => Start volume value
62 mpd_vol = int(self.init_vol)
64 end_volum = mpd_vol / 10
65 mpd_vol = self.init_vol
67 end_volum = int(self.init_vol)
68 mpd_vol = int(self.init_vol) / 10
69 span = float(end_volum - mpd_vol)
70 step = span / float(10*self.cli_options.time)
73 self.client.setvol(int(mpd_vol))
74 if abs(mpd_vol - end_volum) < 1:
75 self.client.setvol(end_volum)
79 def _get_next(self):#{{{
80 """Retrieve playlist from current song to the end."""
81 if 'song' not in self.client.status():
82 print "No current song set in MPD!"
83 self.client.disconnect()
85 current_album = str(self.client.currentsong().get('album', 'TAG MISSING'))
86 current_song_pos = int(self.client.currentsong().get('pos'))
87 print 'Current album: "%s"' % current_album
88 next_album_pos = current_song_pos
90 while album == current_album:
92 pl_length = int(self.client.status().get('playlistlength')) - 1
93 if pl_length < next_album_pos:
94 print 'Next album not found in the playlitst!'
95 self.client.disconnect()
97 album = self.client.playlistinfo(next_album_pos)[0].get('album', 'TAG MISSING')
98 print 'Next album appears to be: "%s"' % album
99 return next_album_pos#}}}
103 print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port)
105 self.init_vol = int(self.client.status().get('volume'))
106 if self.cli_options.time:
107 print 'Cross fading next album'
109 self.client.play(self._get_next())
110 if self.cli_options.time:
112 self.client.disconnect()
117 if __name__ == '__main__':
120 except KeyboardInterrupt:
121 sys.stdout.write('exit')
124 # vim: ai ts=4 sw=4 sts=4 expandtab