From: kaliko Date: Sun, 7 Feb 2010 22:45:39 +0000 (+0000) Subject: * fixes some bugs on mtopls X-Git-Url: http://git.kaliko.me/?p=mpd-goodies.git;a=commitdiff_plain;h=86013a2622c1f21cc64ef81733d48023caaf75a9 * fixes some bugs on mtopls --- diff --git a/config.py b/config.py index 2bc8579..16f7bf7 100644 --- a/config.py +++ b/config.py @@ -14,7 +14,8 @@ # You can launch the script with leading environment variables: # $> MPD_HOST=pass@my_mpd_host script.py # -# More details in mpc manual (cf. man 1 mpc), section ENVIRONMENT +# More details about MPD's environment variables in mpc manual (cf. man 1 mpc), +# options --host/--port. ## Set JINGLE_TAG here. # diff --git a/lib/mpdutils.py b/lib/mpdutils.py index a64d239..ea58b89 100644 --- a/lib/mpdutils.py +++ b/lib/mpdutils.py @@ -73,7 +73,7 @@ def mpdAuth(client, secret):#{{{ return True#}}} -def mconnect(): +def mconnect():#{{{ """""" ## get connection id con_id, passwd = get_mpd_environ() @@ -95,7 +95,14 @@ def mconnect(): print 'ERROR: fail trying to pass auth. Check password?' client.disconnect() sys.exit(1) - return client + return client#}}} + +def collapse_tags(value): + if isinstance(value, list): + #self.__dict__[tag] = ", ".join(set(value)) + self.collapse_tags_bool = True + return ', '.join(set(value)) + return value#}}} # Script starts here if __name__ == '__main__': diff --git a/mtopls b/mtopls index 62ba286..78476c6 100755 --- a/mtopls +++ b/mtopls @@ -27,7 +27,7 @@ import sys from os import (access, F_OK, W_OK) from os.path import (dirname, isfile, join, abspath) -from lib.mpdutils import mconnect +from lib.mpdutils import (mconnect, collapse_tags) USAGE = """Usage: @@ -56,8 +56,8 @@ class MtoPls(object): self.current = self.cli.currentsong() self.cli.disconnect() self._consume_sopt() - self._create_playlist() self._controls_perm() + self._create_playlist() self._run() def _consume_sopt(self): @@ -85,7 +85,7 @@ class MtoPls(object): if not access(mpd_playlists, F_OK): sys.stderr.write('Error: No access to "%s"' % self.pls_path) sys.exit(1) - genre = self.current.get('genre', None) + genre = collapse_tags(self.current.get('genre', None)) if not genre: sys.stderr.write('Error: No genre set in %s\n' % self.current.get('file')) @@ -117,7 +117,7 @@ class MtoPls(object): # TODO: controls either file is already in playlist or not print >> sys.stdout, ('Writing to %s' % self.pls_path) fd = open(self.pls_path, 'a') - fd.write(self.current.get('file')) + fd.write(self.current.get('file') + '\n') fd.close() pass