2 # -*- coding: utf-8 -*-
3 # SPDX-FileCopyrightText: 2009,2010,2012,2019 kaliko <kaliko@azylum.org>
4 # SPDX-License-Identifier: GPL-3.0-or-later
10 from os.path import basename
17 class Nalbum(musicpd.MPDClient):
19 'prog': basename(__file__),
20 'description': 'Jump to next album in playlist.',
21 'epilog': 'Set MPD host/port in env. var'
25 musicpd.MPDClient.__init__(self)
26 self.args = self._get_args()
30 parser = argparse.ArgumentParser(**self.__class__.script_info)
31 parser.add_argument('--version', action='version',
32 version='v%s' % VERSION)
33 parser.add_argument('-c', '--cross-fade', type=int, dest='time',
34 help='fade out/fade in over t seconds.',)
35 args = parser.parse_args()
38 def _setvol(self, vol):
40 Sometimes while fading in on next album, MPD fails.
42 "exception: Failed to set mixer for 'My Pulse Output': disconnected"
43 python-musicpd then raises "[52@0] {setvol} problems setting volume"
47 except musicpd.CommandError as err:
48 print('MPD raised "%s"' % err)
49 print('Try to set the output with \'always_on "yes"\'')
50 if 'problems setting volume' in str(err):
52 self._setvol(int(vol))
54 def _fade(self, mpd_vol, io='out'):
56 end_volum => End volume value
57 start_vol => Start volume value
60 end_volum = mpd_vol // 10
64 start_vol = mpd_vol // 10
65 # print(start_vol, end_volum)
66 span = float(end_volum - start_vol)
67 step = span / float(10*self.args.time)
72 self._setvol(int(start_vol))
73 if abs(start_vol - end_volum) < 1.1*abs(step):
74 self._setvol(end_volum)
79 """Retrieve playlist from current song to the end."""
80 if 'song' not in self.status():
81 print('No current song set in MPD!')
84 current_album = str(self.currentsong().get('album', 'TAG MISSING'))
85 current_song_pos = int(self.currentsong().get('pos'))
86 print('Current album: "%s"' % current_album)
87 next_album_pos = current_song_pos
89 while album == current_album:
91 pl_length = int(self.status().get('playlistlength')) - 1
92 if pl_length < next_album_pos:
93 print('Next album not found in the playlitst!')
96 album = self.playlistinfo(next_album_pos)[
97 0].get('album', 'TAG MISSING')
98 print('Next album appears to be: "%s"' % album)
103 nalbum = self._get_next()
104 init_vol = int(self.status().get('volume', 0))
106 print('Cross fading next album')
110 self._fade(init_vol, io='in')
116 if __name__ == '__main__':
119 except KeyboardInterrupt:
120 sys.stdout.write('exit')
123 # vim: ai ts=4 sw=4 sts=4 expandtab