Merge lp:~gawhelan/exaile/DBus-enqueue into lp:exaile/0.3.3

Proposed by Graham Whelan
Status: Merged
Merged at revision: 1826
Proposed branch: lp:~gawhelan/exaile/DBus-enqueue
Merge into: lp:exaile/0.3.3
Diff against target: None lines
To merge this branch: bzr merge lp:~gawhelan/exaile/DBus-enqueue
Reviewer Review Type Date Requested Status
Johannes Sasongko Approve
Review via email: mp+4959@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Graham Whelan (gawhelan) wrote :

Added an enqueue method to the DBus interface. This accepts a list of filenames and adds them to the current playlist.

This also enables enqueuing from the command line, accepting a list of filenames or reading a null separated list from stdin.

This allows for the following usage:

Add a single track
$ exaile $HOME/Music/Artist/Album/track01.mp3

Add multiple tracks
$ exaile $HOME/Music/Artist/Album/track01.mp3 $HOME/Music/Artist/Album/track02.mp3

Add all tracks within a folder
$ exaile $HOME/Music/Artist/Album/*.mp3

Add all tracks within a folder and it's sub-folders
$ find $HOME/Music/Artist -name *.mp3 -print0 | exaile -

Revision history for this message
Johannes Sasongko (sjohannes) wrote :

Thanks, they would be quite handy indeed.

Just one question about this bit:

+ # if '-' is the first argument then we look for a null
+ # separated list of filenames from stdin.
+ # This enables: find PATH -name *.mp3 -print0 | exaile -
+ if args[0] == '-':
+ args = sys.stdin.read().split('\0')

Do you think it will be better to allow newline characters as the separator as well? I know files may have newline chars in them, but it's not common at all, and I'm guessing the convenience of doing `cat list_of_files.txt | exaile -` outweighs the limitation.

In any case, I'm approving the merge, pending your response.

review: Approve
lp:~gawhelan/exaile/DBus-enqueue updated
1820. By Graham Whelan

Changed command line to accept a newline-separated list of files rather than a null-separated list

Revision history for this message
Graham Whelan (gawhelan) wrote :

Johannes Sasongko wrote:
"Do you think it will be better to allow newline characters as the separator as well? I know files may have newline chars in them, but it's not common at all, and I'm guessing the convenience of doing `cat list_of_files.txt | exaile -` outweighs the limitation."

I considered using newline as the separator but I decided to play it safe and use null. I think you're right though, the convenience of using newline does outweigh the limitations, so I've changed it.

I don't think it's necessary to support both. You could add a `-0` option which accepts a null-separated list, but like you said, filenames containing newline chars are so rare I doubt it would be of much use.

Revision history for this message
Johannes Sasongko (sjohannes) wrote :

Thanks. I've merged your latest changes to trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'xl/xldbus.py'
--- xl/xldbus.py 2009-03-24 23:16:10 +0000
+++ xl/xldbus.py 2009-03-26 23:55:26 +0000
@@ -13,6 +13,7 @@
13# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.13# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1414
15from xl.nls import gettext as _15from xl.nls import gettext as _
16from xl.track import Track
16import dbus, dbus.service, gobject, sys17import dbus, dbus.service, gobject, sys
17from optparse import OptionParser18from optparse import OptionParser
1819
@@ -38,12 +39,16 @@
38 'org.exaile.ExaileInterface')39 'org.exaile.ExaileInterface')
39 iface.test_service('testing dbus service')40 iface.test_service('testing dbus service')
4041
41 # check for one argument, if it doesn't begin with a it's probably42 # Assume that args are files to be added to the current playlist.
42 # a url43 # This enables: exaile PATH/*.mp3
43 args = sys.argv[2:]44 if args:
44 if not [x for x in args if x.startswith('-')]:45 # if '-' is the first argument then we look for a null
45 for arg in args:46 # separated list of filenames from stdin.
46 iface.play_file(arg)47 # This enables: find PATH -name *.mp3 -print0 | exaile -
48 if args[0] == '-':
49 args = sys.stdin.read().split('\0')
50 iface.enqueue(args)
51 do_exit = True
4752
48 info_commands = ('get_artist', 'get_title', 'get_album',53 info_commands = ('get_artist', 'get_title', 'get_album',
49 'get_length', 'get_rating')54 'get_length', 'get_rating')
@@ -153,3 +158,12 @@
153 Plays the specified file158 Plays the specified file
154 """159 """
155 self.exaile.gui.open_uri(filename)160 self.exaile.gui.open_uri(filename)
161
162 @dbus.service.method("org.exaile.ExaileInterface", "as")
163 def enqueue(self, filenames):
164 """
165 Adds the specified files to the current playlist
166 """
167 tracks = [Track(f) for f in filenames]
168 self.exaile.queue.current_playlist.add_tracks(tracks)
169