2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2009,2010,2012,2019 kaliko <kaliko@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/>.
23 from time import sleep
24 from os.path import basename
31 class Nalbum(musicpd.MPDClient):
33 'prog': basename(__file__),
34 'description': 'Jump to next album in playlist.',
35 'epilog': 'Set MPD host/port in env. var'
39 musicpd.MPDClient.__init__(self)
40 self.args = self._get_args()
44 parser = argparse.ArgumentParser(**self.__class__.script_info)
45 parser.add_argument('--version', action='version',
46 version='v%s' % VERSION)
47 parser.add_argument('-c', '--cross-fade', type=int, dest='time',
48 help='fade out/fade in over t seconds.',)
49 args = parser.parse_args()
52 def _setvol(self, vol):
54 Sometimes while fading in on next album, MPD fails.
56 "exception: Failed to set mixer for 'My Pulse Output': disconnected"
57 python-musicpd then raises "[52@0] {setvol} problems setting volume"
61 except musicpd.CommandError as err:
62 print('MPD raised "%s"' % err)
63 print('Try to set the output with \'always_on "yes"\'')
64 if 'problems setting volume' in str(err):
66 self._setvol(int(vol))
68 def _fade(self, mpd_vol, io='out'):
70 end_volum => End volume value
71 start_vol => Start volume value
74 end_volum = mpd_vol // 10
78 start_vol = mpd_vol // 10
79 # print(start_vol, end_volum)
80 span = float(end_volum - start_vol)
81 step = span / float(10*self.args.time)
86 self._setvol(int(start_vol))
87 if abs(start_vol - end_volum) < 1.1*abs(step):
88 self._setvol(end_volum)
93 """Retrieve playlist from current song to the end."""
94 if 'song' not in self.status():
95 print('No current song set in MPD!')
98 current_album = str(self.currentsong().get('album', 'TAG MISSING'))
99 current_song_pos = int(self.currentsong().get('pos'))
100 print('Current album: "%s"' % current_album)
101 next_album_pos = current_song_pos
102 album = current_album
103 while album == current_album:
105 pl_length = int(self.status().get('playlistlength')) - 1
106 if pl_length < next_album_pos:
107 print('Next album not found in the playlitst!')
110 album = self.playlistinfo(next_album_pos)[
111 0].get('album', 'TAG MISSING')
112 print('Next album appears to be: "%s"' % album)
113 return next_album_pos
117 nalbum = self._get_next()
118 init_vol = int(self.status().get('volume', 0))
120 print('Cross fading next album')
124 self._fade(init_vol, io='in')
130 if __name__ == '__main__':
133 except KeyboardInterrupt:
134 sys.stdout.write('exit')
137 # vim: ai ts=4 sw=4 sts=4 expandtab