]> kaliko git repositories - mpd-goodies.git/commitdiff
* Add next album command: nalbum
authorkaliko <kaliko@azylum.org>
Fri, 6 Aug 2010 09:56:50 +0000 (09:56 +0000)
committerkaliko <kaliko@azylum.org>
Fri, 6 Aug 2010 09:56:50 +0000 (09:56 +0000)
nalbum [new file with mode: 0755]

diff --git a/nalbum b/nalbum
new file mode 100755 (executable)
index 0000000..a0ed04f
--- /dev/null
+++ b/nalbum
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2009, 2010 Efrim <efrim@azylum.org> {{{
+#
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#  }}}
+
+
+import sys
+
+from lib.mpdclass import MPDClass
+from lib.startop import StartOpt
+
+NAME = 'nalbum'
+VERSION = '0.1'
+
+class Nalbum(StartOpt, MPDClass):
+    """
+    """
+    script_info = dict({
+        'version': VERSION,
+        'prog_name': NAME,
+        'description': 'Seek to next album in playlist.',
+        })
+
+    def __init__(self):
+        """"""
+        StartOpt.__init__(self, self.__class__.script_info, [])
+        MPDClass.__init__(self)
+        self._run()
+
+    def _get_next(self):
+        """Retrieve playlist from current song to the end."""
+        if 'song' not in self.client.status():
+            print "No current song set in MPD!"
+            self.client.disconnect()
+            sys.exit(0)
+        current_album = str(self.client.currentsong().get('album', 'TAG MISSING'))
+        current_song_pos = int(self.client.currentsong().get('pos'))
+        print 'Current album: "%s"' % current_album
+        next_album_pos = current_song_pos
+        album = current_album
+        while album == current_album:
+            next_album_pos += 1
+            pl_length = int(self.client.status().get('playlistlength')) - 1
+            if pl_length < next_album_pos:
+                print 'Next album not found in the playlitst!'
+                self.client.disconnect()
+                sys.exit(0)
+            album = self.client.playlistinfo(next_album_pos)[0].get('album', 'TAG MISSING')
+        print 'Next album appears to be: "%s"' % album
+        return next_album_pos
+
+    def _run(self):
+        """"""
+        print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port)
+        self.mpdConnect()
+        self.client.play(self._get_next())
+        self.client.disconnect()
+        sys.exit(0)
+
+
+# Script starts here
+if __name__ == '__main__':
+    try:
+        Nalbum()
+    except KeyboardInterrupt:
+        sys.stdout.write('exit')
+
+# VIM MODLINE
+# vim: ai ts=4 sw=4 sts=4 expandtab