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
1=== modified file 'xl/xldbus.py'
2--- xl/xldbus.py 2009-03-24 23:16:10 +0000
3+++ xl/xldbus.py 2009-03-26 23:55:26 +0000
4@@ -13,6 +13,7 @@
5 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6
7 from xl.nls import gettext as _
8+from xl.track import Track
9 import dbus, dbus.service, gobject, sys
10 from optparse import OptionParser
11
12@@ -38,12 +39,16 @@
13 'org.exaile.ExaileInterface')
14 iface.test_service('testing dbus service')
15
16- # check for one argument, if it doesn't begin with a it's probably
17- # a url
18- args = sys.argv[2:]
19- if not [x for x in args if x.startswith('-')]:
20- for arg in args:
21- iface.play_file(arg)
22+ # Assume that args are files to be added to the current playlist.
23+ # This enables: exaile PATH/*.mp3
24+ if args:
25+ # if '-' is the first argument then we look for a null
26+ # separated list of filenames from stdin.
27+ # This enables: find PATH -name *.mp3 -print0 | exaile -
28+ if args[0] == '-':
29+ args = sys.stdin.read().split('\0')
30+ iface.enqueue(args)
31+ do_exit = True
32
33 info_commands = ('get_artist', 'get_title', 'get_album',
34 'get_length', 'get_rating')
35@@ -153,3 +158,12 @@
36 Plays the specified file
37 """
38 self.exaile.gui.open_uri(filename)
39+
40+ @dbus.service.method("org.exaile.ExaileInterface", "as")
41+ def enqueue(self, filenames):
42+ """
43+ Adds the specified files to the current playlist
44+ """
45+ tracks = [Track(f) for f in filenames]
46+ self.exaile.queue.current_playlist.add_tracks(tracks)
47+