]> kaliko git repositories - python-musicpd.git/blob - README.rst
Add suport for environment variables MPD_HOST/MPD_PORT/XDG_RUNTIME_DIR
[python-musicpd.git] / README.rst
1 ==============
2 python-musicpd
3 ==============
4
5 Getting python-musicpd
6 ----------------------
7
8 The latest release of python-musicpd can be found at
9 http://pypi.python.org/pypi/python-musicpd.
10
11
12 Getting the latest source code
13 ------------------------------
14
15 If you would instead like to use the latest source code, you can grab a copy
16 of the development version from git by running the command:
17
18   git clone git://git.kaliko.me/python-musicpd.git
19
20
21 Installing from source
22 ----------------------
23
24 To install python-musicpd from source, simply run the command::
25
26   python3 setup.py install
27
28 You can use the `--help` switch to `setup.py` for a complete list of commands
29 and their options.  See the `Installing Python Modules`_ document for more details.
30
31
32 Using the client library
33 ------------------------
34
35 The client library can be used as follows::
36
37     client = musicpd.MPDClient()       # create client object
38     client.connect()                   # use MPD_HOST/MPD_PORT if set else
39                                        #   test ${XDG_RUNTIME_DIR}/mpd/socket for existence
40                                        #   fallback to localhost:6600
41                                        # `connect` support host/port argument as well
42     print client.mpd_version           # print the mpd version
43     print client.cmd('one', 2)         # print result of the command "cmd one 2"
44     client.close()                     # send the close command
45     client.disconnect()                # disconnect from the server
46
47 A list of supported commands, their arguments (as MPD currently understands
48 them), and the functions used to parse their responses can be found in
49 `doc/commands.txt`.  See the `MPD protocol documentation`_ for more
50 details.
51
52 Command lists are also supported using `command_list_ok_begin()` and
53 `command_list_end()` ::
54
55     client.command_list_ok_begin()       # start a command list
56     client.update()                      # insert the update command into the list
57     client.status()                      # insert the status command into the list
58     results = client.command_list_end()  # results will be a list with the results
59
60 Provide a 2-tuple as argument for command supporting ranges (cf. `MPD protocol documentation`_ for more details).
61 Possible ranges are: "START:END", "START:" and ":" ::
62
63     # An intelligent clear
64     # clears played track in the queue, currentsong included
65     pos = client.currentsong().get('pos', 0)
66     # the 2-tuple range object accepts str, no need to convert to int
67     client.delete((0, pos))
68     # missing end interpreted as highest value possible, pay attention still need a tuple.
69     client.delete((pos,))  # purge queue from current to the end
70
71 A notable case is the `rangeid` command allowing an empty range specified
72 as a single colon as argument (i.e. sending just ":")::
73
74     # sending "rangeid :" to clear the range, play everything
75     client.rangeid(())  # send an empty tuple
76
77 Empty start in range (i.e. ":END") are not possible and will raise a CommandError.
78
79
80 Commands may also return iterators instead of lists if `iterate` is set to
81 `True`::
82
83     client.iterate = True
84     for song in client.playlistinfo():
85         print song['file']
86
87 Each command have a *send\_<CMD>* and a *fetch\_<CMD>* variant, which allows to
88 send a MPD command and then fetch the result later.
89 This is useful for the idle command::
90
91     >>> client.send_idle()
92     # do something else or use function like select()
93     # http://docs.python.org/howto/sockets.html#non-blocking-sockets
94     # ex. select([client], [], [])
95     >>> events = client.fetch_idle()
96
97     # more complex use for example, with glib/gobject:
98     >>> def callback(source, condition):
99     >>>    changes = client.fetch_idle()
100     >>>    print changes
101     >>>    return False  # removes the IO watcher
102
103     >>> client.send_idle()
104     >>> gobject.io_add_watch(client, gobject.IO_IN, callback)
105     >>> gobject.MainLoop().run()
106
107 Contacting authors
108 ------------------
109
110 You can contact the original author by emailing J. Alexander Treuman
111 <jat⊘spatialrift.net>.  He can also be found idling in #mpd on
112 irc.freenode.net as jat.
113
114 The current maintainer can be found on xmpp chat room <kaliko.me⊘conf.azylum.org>
115 or you can contact him by email/xmpp <kaliko⊘azylum.org>.
116
117  .. _Installing Python Modules: http://docs.python.org/3/install/
118  .. _MPD protocol documentation: http://www.musicpd.org/doc/protocol/