python-musicpd 0.8.0__tar.gz → 0.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/CHANGES.txt +21 -0
  2. python_musicpd-0.9.1/MANIFEST.in +3 -0
  3. python_musicpd-0.9.1/PKG-INFO +199 -0
  4. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/README.rst +2 -2
  5. python_musicpd-0.9.1/doc/source/_commands.rst +195 -0
  6. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/doc/source/commands.rst +3 -6
  7. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/doc/source/commands.txt +8 -1
  8. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/doc/source/conf.py +3 -3
  9. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/doc/source/contribute.rst +1 -1
  10. python_musicpd-0.9.1/doc/source/doc.rst +12 -0
  11. python_musicpd-0.9.1/doc/source/examples/client.py +94 -0
  12. python_musicpd-0.9.1/doc/source/examples/connect.py +29 -0
  13. python_musicpd-0.9.1/doc/source/examples/connect_host.py +17 -0
  14. python_musicpd-0.9.1/doc/source/examples/exceptions.py +59 -0
  15. python_musicpd-0.9.1/doc/source/examples/findadd.py +8 -0
  16. {python-musicpd-0.8.0 → python_musicpd-0.9.1/doc/source/examples}/musicpd.py +155 -98
  17. python_musicpd-0.9.1/doc/source/examples/playback.py +7 -0
  18. python_musicpd-0.9.1/doc/source/examples.rst +57 -0
  19. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/doc/source/index.rst +7 -7
  20. python_musicpd-0.9.1/doc/source/python-musicpd.svg +1417 -0
  21. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/doc/source/use.rst +89 -27
  22. python_musicpd-0.9.1/musicpd.py +813 -0
  23. python_musicpd-0.9.1/pyproject.toml +37 -0
  24. python_musicpd-0.9.1/python_musicpd.egg-info/PKG-INFO +199 -0
  25. python_musicpd-0.9.1/python_musicpd.egg-info/SOURCES.txt +28 -0
  26. python_musicpd-0.9.1/python_musicpd.egg-info/requires.txt +3 -0
  27. python_musicpd-0.9.1/setup.cfg +4 -0
  28. python-musicpd-0.8.0/MANIFEST.in +0 -2
  29. python-musicpd-0.8.0/PKG-INFO +0 -34
  30. python-musicpd-0.8.0/doc/source/doc.rst +0 -15
  31. python-musicpd-0.8.0/python_musicpd.egg-info/PKG-INFO +0 -34
  32. python-musicpd-0.8.0/python_musicpd.egg-info/SOURCES.txt +0 -18
  33. python-musicpd-0.8.0/setup.cfg +0 -44
  34. python-musicpd-0.8.0/setup.py +0 -10
  35. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/LICENSE.txt +0 -0
  36. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/python_musicpd.egg-info/dependency_links.txt +0 -0
  37. {python-musicpd-0.8.0 → python_musicpd-0.9.1}/python_musicpd.egg-info/top_level.txt +0 -0
@@ -1,6 +1,27 @@
1
1
  python-musicpd Changes List
2
2
  ===========================
3
3
 
4
+ Changes in 0.9.1
5
+ ----------------
6
+
7
+ * Add playlistlength command
8
+ * Add stickernames command
9
+ * Add searchcount command
10
+ * Improved documentation, add supported commands rtype
11
+
12
+ Changes in 0.9.0
13
+ ----------------
14
+
15
+ * Use right SPDX identifier for license headers
16
+ * mpd_version attribute init to empty string instead of None
17
+ * Fixed send_noidle (introduced with e8daa719)
18
+ * Improved Range object to deal with window parameter
19
+ * Add logging
20
+ * Switch to pyproject.toml (setuptools build system)
21
+ * The connect sequence raises ConnectionError only on error,
22
+ previously getaddrinfo or unix socket connection error raised an OSError
23
+ * Improved documentation, add examples
24
+
4
25
  Changes in 0.8.0
5
26
  ----------------
6
27
 
@@ -0,0 +1,3 @@
1
+ include CHANGES.txt
2
+ graft doc/source
3
+ global-exclude *~ *.py[cod] *.so
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-musicpd
3
+ Version: 0.9.1
4
+ Summary: An MPD (Music Player Daemon) client library written in pure Python.
5
+ Author-email: Kaliko Jack <kaliko@azylum.org>
6
+ License: GNU LESSER GENERAL PUBLIC LICENSE
7
+ Version 3, 29 June 2007
8
+
9
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
10
+ Everyone is permitted to copy and distribute verbatim copies
11
+ of this license document, but changing it is not allowed.
12
+
13
+
14
+ This version of the GNU Lesser General Public License incorporates
15
+ the terms and conditions of version 3 of the GNU General Public
16
+ License, supplemented by the additional permissions listed below.
17
+
18
+ 0. Additional Definitions.
19
+
20
+ As used herein, "this License" refers to version 3 of the GNU Lesser
21
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
22
+ General Public License.
23
+
24
+ "The Library" refers to a covered work governed by this License,
25
+ other than an Application or a Combined Work as defined below.
26
+
27
+ An "Application" is any work that makes use of an interface provided
28
+ by the Library, but which is not otherwise based on the Library.
29
+ Defining a subclass of a class defined by the Library is deemed a mode
30
+ of using an interface provided by the Library.
31
+
32
+ A "Combined Work" is a work produced by combining or linking an
33
+ Application with the Library. The particular version of the Library
34
+ with which the Combined Work was made is also called the "Linked
35
+ Version".
36
+
37
+ The "Minimal Corresponding Source" for a Combined Work means the
38
+ Corresponding Source for the Combined Work, excluding any source code
39
+ for portions of the Combined Work that, considered in isolation, are
40
+ based on the Application, and not on the Linked Version.
41
+
42
+ The "Corresponding Application Code" for a Combined Work means the
43
+ object code and/or source code for the Application, including any data
44
+ and utility programs needed for reproducing the Combined Work from the
45
+ Application, but excluding the System Libraries of the Combined Work.
46
+
47
+ 1. Exception to Section 3 of the GNU GPL.
48
+
49
+ You may convey a covered work under sections 3 and 4 of this License
50
+ without being bound by section 3 of the GNU GPL.
51
+
52
+ 2. Conveying Modified Versions.
53
+
54
+ If you modify a copy of the Library, and, in your modifications, a
55
+ facility refers to a function or data to be supplied by an Application
56
+ that uses the facility (other than as an argument passed when the
57
+ facility is invoked), then you may convey a copy of the modified
58
+ version:
59
+
60
+ a) under this License, provided that you make a good faith effort to
61
+ ensure that, in the event an Application does not supply the
62
+ function or data, the facility still operates, and performs
63
+ whatever part of its purpose remains meaningful, or
64
+
65
+ b) under the GNU GPL, with none of the additional permissions of
66
+ this License applicable to that copy.
67
+
68
+ 3. Object Code Incorporating Material from Library Header Files.
69
+
70
+ The object code form of an Application may incorporate material from
71
+ a header file that is part of the Library. You may convey such object
72
+ code under terms of your choice, provided that, if the incorporated
73
+ material is not limited to numerical parameters, data structure
74
+ layouts and accessors, or small macros, inline functions and templates
75
+ (ten or fewer lines in length), you do both of the following:
76
+
77
+ a) Give prominent notice with each copy of the object code that the
78
+ Library is used in it and that the Library and its use are
79
+ covered by this License.
80
+
81
+ b) Accompany the object code with a copy of the GNU GPL and this license
82
+ document.
83
+
84
+ 4. Combined Works.
85
+
86
+ You may convey a Combined Work under terms of your choice that,
87
+ taken together, effectively do not restrict modification of the
88
+ portions of the Library contained in the Combined Work and reverse
89
+ engineering for debugging such modifications, if you also do each of
90
+ the following:
91
+
92
+ a) Give prominent notice with each copy of the Combined Work that
93
+ the Library is used in it and that the Library and its use are
94
+ covered by this License.
95
+
96
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
97
+ document.
98
+
99
+ c) For a Combined Work that displays copyright notices during
100
+ execution, include the copyright notice for the Library among
101
+ these notices, as well as a reference directing the user to the
102
+ copies of the GNU GPL and this license document.
103
+
104
+ d) Do one of the following:
105
+
106
+ 0) Convey the Minimal Corresponding Source under the terms of this
107
+ License, and the Corresponding Application Code in a form
108
+ suitable for, and under terms that permit, the user to
109
+ recombine or relink the Application with a modified version of
110
+ the Linked Version to produce a modified Combined Work, in the
111
+ manner specified by section 6 of the GNU GPL for conveying
112
+ Corresponding Source.
113
+
114
+ 1) Use a suitable shared library mechanism for linking with the
115
+ Library. A suitable mechanism is one that (a) uses at run time
116
+ a copy of the Library already present on the user's computer
117
+ system, and (b) will operate properly with a modified version
118
+ of the Library that is interface-compatible with the Linked
119
+ Version.
120
+
121
+ e) Provide Installation Information, but only if you would otherwise
122
+ be required to provide such information under section 6 of the
123
+ GNU GPL, and only to the extent that such information is
124
+ necessary to install and execute a modified version of the
125
+ Combined Work produced by recombining or relinking the
126
+ Application with a modified version of the Linked Version. (If
127
+ you use option 4d0, the Installation Information must accompany
128
+ the Minimal Corresponding Source and Corresponding Application
129
+ Code. If you use option 4d1, you must provide the Installation
130
+ Information in the manner specified by section 6 of the GNU GPL
131
+ for conveying Corresponding Source.)
132
+
133
+ 5. Combined Libraries.
134
+
135
+ You may place library facilities that are a work based on the
136
+ Library side by side in a single library together with other library
137
+ facilities that are not Applications and are not covered by this
138
+ License, and convey such a combined library under terms of your
139
+ choice, if you do both of the following:
140
+
141
+ a) Accompany the combined library with a copy of the same work based
142
+ on the Library, uncombined with any other library facilities,
143
+ conveyed under the terms of this License.
144
+
145
+ b) Give prominent notice with the combined library that part of it
146
+ is a work based on the Library, and explaining where to find the
147
+ accompanying uncombined form of the same work.
148
+
149
+ 6. Revised Versions of the GNU Lesser General Public License.
150
+
151
+ The Free Software Foundation may publish revised and/or new versions
152
+ of the GNU Lesser General Public License from time to time. Such new
153
+ versions will be similar in spirit to the present version, but may
154
+ differ in detail to address new problems or concerns.
155
+
156
+ Each version is given a distinguishing version number. If the
157
+ Library as you received it specifies that a certain numbered version
158
+ of the GNU Lesser General Public License "or any later version"
159
+ applies to it, you have the option of following the terms and
160
+ conditions either of that published version or of any later version
161
+ published by the Free Software Foundation. If the Library as you
162
+ received it does not specify a version number of the GNU Lesser
163
+ General Public License, you may choose any version of the GNU Lesser
164
+ General Public License ever published by the Free Software Foundation.
165
+
166
+ If the Library as you received it specifies that a proxy can decide
167
+ whether future versions of the GNU Lesser General Public License shall
168
+ apply, that proxy's public statement of acceptance of any version is
169
+ permanent authorization for you to choose that version for the
170
+ Library.
171
+
172
+ Project-URL: Homepage, https://kaliko.me/python-musicpd/
173
+ Keywords: mpd,Music Player Daemon
174
+ Classifier: Development Status :: 5 - Production/Stable
175
+ Classifier: Intended Audience :: Developers
176
+ Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
177
+ Classifier: Natural Language :: English
178
+ Classifier: Operating System :: OS Independent
179
+ Classifier: Programming Language :: Python :: 3
180
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
181
+ Requires-Python: >=3.6
182
+ Description-Content-Type: text/x-rst
183
+ License-File: LICENSE.txt
184
+ Provides-Extra: sphinx
185
+ Requires-Dist: Sphinx>=5.3.0; extra == "sphinx"
186
+
187
+ Music Player Daemon client module
188
+ *********************************
189
+
190
+ An MPD (Music Player Daemon) client library written in pure Python.
191
+
192
+ ----
193
+
194
+ :Documentation: https://kaliko.gitlab.io/python-musicpd
195
+ :MPD Protocol: https://www.musicpd.org/doc/html/protocol.html
196
+ :Code: https://gitlab.com/kaliko/python-musicpd
197
+ :Dependencies: None
198
+ :Compatibility: Python 3.6+
199
+ :Licence: GNU LGPLv3
@@ -1,5 +1,5 @@
1
- Python MusicPlayerDaemon client module
2
- ***************************************
1
+ Music Player Daemon client module
2
+ *********************************
3
3
 
4
4
  An MPD (Music Player Daemon) client library written in pure Python.
5
5
 
@@ -0,0 +1,195 @@
1
+ Below the commands list last updated for v0.9.1.
2
+
3
+ Querying MPD’s status
4
+ ^^^^^^^^^^^^^^^^^^^^^
5
+
6
+ Protocol documentation: `Querying MPD’s status <https://mpd.readthedocs.io/en/latest/protocol.html#querying-mpd-s-status>`_
7
+
8
+ * **clearerror** -> None
9
+ * **currentsong** -> dict
10
+ * **idle** -> list
11
+ * **status** -> dict
12
+ * **stats** -> dict
13
+
14
+ Playback Option
15
+ ^^^^^^^^^^^^^^^
16
+
17
+ Protocol documentation: `Playback Option <https://mpd.readthedocs.io/en/latest/protocol.html#playback-options>`_
18
+
19
+ * **consume** -> None
20
+ * **crossfade** -> None
21
+ * **mixrampdb** -> None
22
+ * **mixrampdelay** -> None
23
+ * **random** -> None
24
+ * **repeat** -> None
25
+ * **setvol** -> None
26
+ * **getvol** -> dict
27
+ * **single** -> None
28
+ * **replay_gain_mode** -> None
29
+ * **replay_gain_status** -> str
30
+ * **volume** -> None
31
+
32
+ Controlling playback
33
+ ^^^^^^^^^^^^^^^^^^^^
34
+
35
+ Protocol documentation: `Controlling playback <https://mpd.readthedocs.io/en/latest/protocol.html#controlling-playback>`_
36
+
37
+ * **next** -> None
38
+ * **pause** -> None
39
+ * **play** -> None
40
+ * **playid** -> None
41
+ * **previous** -> None
42
+ * **seek** -> None
43
+ * **seekid** -> None
44
+ * **seekcur** -> None
45
+ * **stop** -> None
46
+
47
+ The Queue
48
+ ^^^^^^^^^
49
+
50
+ Protocol documentation: `The Queue <https://mpd.readthedocs.io/en/latest/protocol.html#the-queue>`_
51
+
52
+ * **add** -> None
53
+ * **addid** -> str
54
+ * **clear** -> None
55
+ * **delete** -> None
56
+ * **deleteid** -> None
57
+ * **move** -> None
58
+ * **moveid** -> None
59
+ * **playlist** -> list
60
+ * **playlistfind** -> list[dict]
61
+ * **playlistid** -> list[dict]
62
+ * **playlistinfo** -> list[dict]
63
+ * **playlistsearch** -> list[dict]
64
+ * **plchanges** -> list[dict]
65
+ * **plchangesposid** -> list[dict]
66
+ * **prio** -> None
67
+ * **prioid** -> None
68
+ * **rangeid** -> None
69
+ * **shuffle** -> None
70
+ * **swap** -> None
71
+ * **swapid** -> None
72
+ * **addtagid** -> None
73
+ * **cleartagid** -> None
74
+
75
+ Stored playlists
76
+ ^^^^^^^^^^^^^^^^
77
+
78
+ Protocol documentation: `Stored playlists <https://mpd.readthedocs.io/en/latest/protocol.html#stored-playlists>`_
79
+
80
+ * **listplaylist** -> list
81
+ * **listplaylistinfo** -> list[dict]
82
+ * **listplaylists** -> dict
83
+ * **load** -> None
84
+ * **playlistadd** -> None
85
+ * **playlistclear** -> None
86
+ * **playlistdelete** -> None
87
+ * **playlistlength** -> dict
88
+ * **playlistmove** -> None
89
+ * **rename** -> None
90
+ * **rm** -> None
91
+ * **save** -> None
92
+
93
+ The music database
94
+ ^^^^^^^^^^^^^^^^^^
95
+
96
+ Protocol documentation: `The music database <https://mpd.readthedocs.io/en/latest/protocol.html#the-music-database>`_
97
+
98
+ * **albumart** -> dict
99
+ * **count** -> dict
100
+ * **getfingerprint** -> dict
101
+ * **find** -> list[dict]
102
+ * **findadd** -> None
103
+ * **list** -> list
104
+ * **listall** -> list[dict]
105
+ * **listallinfo** -> list[dict]
106
+ * **listfiles** -> list[dict]
107
+ * **lsinfo** -> list[dict]
108
+ * **readcomments** -> dict
109
+ * **readpicture** -> dict
110
+ * **search** -> list[dict]
111
+ * **searchadd** -> None
112
+ * **searchaddpl** -> None
113
+ * **searchcount** -> dict
114
+ * **update** -> str
115
+ * **rescan** -> str
116
+
117
+ Mounts and neighbors
118
+ ^^^^^^^^^^^^^^^^^^^^
119
+
120
+ Protocol documentation: `Mounts and neighbors <https://mpd.readthedocs.io/en/latest/protocol.html#mounts-and-neighbors>`_
121
+
122
+ * **mount** -> None
123
+ * **unmount** -> None
124
+ * **listmounts** -> list[dict]
125
+ * **listneighbors** -> list[dict]
126
+
127
+ Stickers
128
+ ^^^^^^^^
129
+
130
+ Protocol documentation: `Stickers <https://mpd.readthedocs.io/en/latest/protocol.html#stickers>`_
131
+
132
+ * **sticker get** -> str
133
+ * **sticker set** -> None
134
+ * **sticker delete** -> None
135
+ * **sticker list** -> list
136
+ * **sticker find** -> list[dict]
137
+ * **stickernames** -> list
138
+
139
+ Connection settings
140
+ ^^^^^^^^^^^^^^^^^^^
141
+
142
+ Protocol documentation: `Connection settings <https://mpd.readthedocs.io/en/latest/protocol.html#connection-settings>`_
143
+
144
+ * **password** -> None
145
+ * **ping** -> None
146
+ * **binarylimit** -> None
147
+ * **tagtypes** -> list
148
+ * **tagtypes disable** -> None
149
+ * **tagtypes enable** -> None
150
+ * **tagtypes clear** -> None
151
+ * **tagtypes all** -> None
152
+
153
+ Partition Commands
154
+ ^^^^^^^^^^^^^^^^^^
155
+
156
+ Protocol documentation: `Partition Commands <https://mpd.readthedocs.io/en/latest/protocol.html#partition-commands>`_
157
+
158
+ * **partition** -> None
159
+ * **listpartitions** -> list
160
+ * **newpartition** -> None
161
+ * **delpartition** -> None
162
+ * **moveoutput** -> None
163
+
164
+ Audio output devices
165
+ ^^^^^^^^^^^^^^^^^^^^
166
+
167
+ Protocol documentation: `Audio output devices <https://mpd.readthedocs.io/en/latest/protocol.html#audio-output-devices>`_
168
+
169
+ * **disableoutput** -> None
170
+ * **enableoutput** -> None
171
+ * **toggleoutput** -> None
172
+ * **outputs** -> list[dict]
173
+ * **outputset** -> None
174
+
175
+ Reflection
176
+ ^^^^^^^^^^
177
+
178
+ Protocol documentation: `Reflection <https://mpd.readthedocs.io/en/latest/protocol.html#reflection>`_
179
+
180
+ * **config** -> dict
181
+ * **commands** -> list
182
+ * **notcommands** -> list
183
+ * **urlhandlers** -> list
184
+ * **decoders** -> list[dict]
185
+
186
+ Client to Client
187
+ ^^^^^^^^^^^^^^^^
188
+
189
+ Protocol documentation: `Client to Client <https://mpd.readthedocs.io/en/latest/protocol.html#client-to-client>`_
190
+
191
+ * **subscribe** -> None
192
+ * **unsubscribe** -> None
193
+ * **channels** -> list
194
+ * **readmessages** -> list[dict]
195
+ * **sendmessage** -> None
@@ -1,5 +1,5 @@
1
- .. SPDX-FileCopyrightText: 2018-2021 kaliko <kaliko@azylum.org>
2
- .. SPDX-License-Identifier: GPL-3.0-or-later
1
+ .. SPDX-FileCopyrightText: 2018-2024 kaliko <kaliko@azylum.org>
2
+ .. SPDX-License-Identifier: LGPL-3.0-or-later
3
3
 
4
4
  .. _commands:
5
5
 
@@ -13,7 +13,4 @@ Get current available commands:
13
13
  import musicpd
14
14
  print(' '.join([cmd for cmd in musicpd.MPDClient()._commands.keys()]))
15
15
 
16
-
17
- List, last updated for v0.6.0:
18
-
19
- .. literalinclude:: commands.txt
16
+ .. include:: _commands.rst
@@ -7,7 +7,7 @@ status -> fetch_object
7
7
  stats -> fetch_object
8
8
 
9
9
  == Playback Option Commands
10
- consume <bool> -> fetch_nothing
10
+ consume <str> -> fetch_nothing
11
11
  crossfade <int> -> fetch_nothing
12
12
  mixrampdb <str> -> fetch_nothing
13
13
  mixrampdelay <int> -> fetch_nothing
@@ -133,3 +133,10 @@ commands -> fetch_list
133
133
  notcommands -> fetch_list
134
134
  urlhandlers -> fetch_list
135
135
  decoders -> fetch_plugins
136
+
137
+ == Client to Client
138
+ subscribe <str> -> self._fetch_nothing,
139
+ unsubscribe <str> -> self._fetch_nothing,
140
+ channels -> self._fetch_list,
141
+ readmessages -> self._fetch_messages,
142
+ sendmessage <str> <str> -> self._fetch_nothing,
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  # SPDX-FileCopyrightText: 2018-2021 kaliko <kaliko@azylum.org>
3
- # SPDX-License-Identifier: GPL-3.0-or-later
3
+ # SPDX-License-Identifier: LGPL-3.0-or-later
4
4
  #
5
5
  # Python MPD Module documentation build configuration file, created by
6
6
  # sphinx-quickstart on Mon Mar 12 14:37:32 2018.
@@ -76,7 +76,7 @@ release = VERSION
76
76
  #
77
77
  # This is also used if you do content translation via gettext catalogs.
78
78
  # Usually you set "language" from the command line for these cases.
79
- language = None
79
+ #language = None
80
80
 
81
81
  # There are two options for replacing |today|: either, you set today to some
82
82
  # non-false value, then it is used:
@@ -438,7 +438,7 @@ epub_exclude_files = ['search.html']
438
438
 
439
439
 
440
440
  # Example configuration for intersphinx: refer to the Python standard library.
441
- intersphinx_mapping = {'https://docs.python.org/': None}
441
+ intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
442
442
 
443
443
  # autodoc config
444
444
  autodoc_member_order = 'bysource'
@@ -1,5 +1,5 @@
1
1
  .. SPDX-FileCopyrightText: 2018-2021 kaliko <kaliko@azylum.org>
2
- .. SPDX-License-Identifier: GPL-3.0-or-later
2
+ .. SPDX-License-Identifier: LGPL-3.0-or-later
3
3
 
4
4
  Contributing
5
5
  =============
@@ -0,0 +1,12 @@
1
+ .. SPDX-FileCopyrightText: 2018-2023 kaliko <kaliko@azylum.org>
2
+ .. SPDX-License-Identifier: LGPL-3.0-or-later
3
+
4
+ musicpd namespace
5
+ =================
6
+
7
+ .. automodule:: musicpd
8
+ :members:
9
+ :no-undoc-members:
10
+
11
+
12
+ .. vim: spell spelllang=en
@@ -0,0 +1,94 @@
1
+ """Plain client class
2
+ """
3
+ import logging
4
+ import select
5
+ import sys
6
+
7
+ import musicpd
8
+
9
+
10
+ class MyClient(musicpd.MPDClient):
11
+ """Plain client inheriting from MPDClient"""
12
+
13
+ def __init__(self):
14
+ # Set logging to debug level
15
+ logging.basicConfig(level=logging.DEBUG,
16
+ format='%(levelname)-8s %(module)-8s %(message)s')
17
+ self.log = logging.getLogger(__name__)
18
+ super().__init__()
19
+ # Set host/port/password after init to overrides defaults
20
+ # self.host = 'example.org'
21
+ # self.port = 4242
22
+ # self.pwd = 'secret'
23
+
24
+ def connect(self):
25
+ """Overriding explicitly MPDClient.connect()"""
26
+ try:
27
+ super().connect(host=self.host, port=self.port)
28
+ if hasattr(self, 'pwd') and self.pwd:
29
+ self.password(self.pwd)
30
+ except musicpd.ConnectionError as err:
31
+ # Catch socket error
32
+ self.log.error('Failed to connect: %s', err)
33
+ sys.exit(42)
34
+
35
+ def _wait_for_changes(self, callback):
36
+ select_timeout = 10 # second
37
+ while True:
38
+ self.send_idle() # use send_ API to avoid blocking on read
39
+ _read, _, _ = select.select([self], [], [], select_timeout)
40
+ if _read: # tries to read response
41
+ ret = self.fetch_idle()
42
+ # do something
43
+ callback(ret)
44
+ else: # cancels idle
45
+ self.noidle()
46
+
47
+ def callback(self, *args):
48
+ """Method launch on MPD event, cf. monitor method"""
49
+ self.log.info('%s', args)
50
+
51
+ def monitor(self):
52
+ """Continuously monitor MPD activity.
53
+ Launch callback method on event.
54
+ """
55
+ try:
56
+ self._wait_for_changes(self.callback)
57
+ except (OSError, musicpd.MPDError) as err:
58
+ self.log.error('%s: Something went wrong: %s',
59
+ type(err).__name__, err)
60
+
61
+ if __name__ == '__main__':
62
+ cli = MyClient()
63
+ # You can overrides host here or in init
64
+ #cli.host = 'example.org'
65
+ # Connect MPD server
66
+ try:
67
+ cli.connect()
68
+ except musicpd.ConnectionError as err:
69
+ cli.log.error(err)
70
+
71
+ # Monitor MPD changes, blocking/timeout idle approach
72
+ try:
73
+ cli.socket_timeout = 20 # seconds
74
+ ret = cli.idle()
75
+ cli.log.info('Leaving idle, got: %s', ret)
76
+ except TimeoutError as err:
77
+ cli.log.info('Nothing occured the last %ss', cli.socket_timeout)
78
+
79
+ # Reset connection
80
+ try:
81
+ cli.socket_timeout = None
82
+ cli.disconnect()
83
+ cli.connect()
84
+ except musicpd.ConnectionError as err:
85
+ cli.log.error(err)
86
+
87
+ # Monitor MPD changes, non blocking idle approach
88
+ try:
89
+ cli.monitor()
90
+ except KeyboardInterrupt as err:
91
+ cli.log.info(type(err).__name__)
92
+ cli.send_noidle()
93
+ cli.disconnect()
94
+
@@ -0,0 +1,29 @@
1
+ import logging
2
+
3
+ import musicpd
4
+
5
+ # Set logging to debug level
6
+ # it should log messages showing where defaults come from
7
+ logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')
8
+ log = logging.getLogger()
9
+
10
+ client = musicpd.MPDClient()
11
+ # use MPD_HOST/MPD_PORT env var if set else
12
+ # test ${XDG_RUNTIME_DIR}/mpd/socket for existence
13
+ # fallback to localhost:6600
14
+ # connect support host/port argument as well
15
+ client.connect()
16
+
17
+ status = client.status()
18
+ if status.get('state') == 'play':
19
+ current_song_id = status.get('songid')
20
+ current_song = client.playlistid(current_song_id)[0]
21
+ log.info(f'Playing : {current_song.get("file")}')
22
+ next_song_id = status.get('nextsongid', None)
23
+ if next_song_id:
24
+ next_song = client.playlistid(next_song_id)[0]
25
+ log.info(f'Next song : {next_song.get("file")}')
26
+ else:
27
+ log.info('Not playing')
28
+
29
+ client.disconnect()
@@ -0,0 +1,17 @@
1
+ import sys
2
+ import logging
3
+
4
+ import musicpd
5
+
6
+ # Set logging to debug level
7
+ logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')
8
+
9
+ client = musicpd.MPDClient()
10
+ try:
11
+ client.connect(host='example.lan')
12
+ client.password('secret')
13
+ client.status()
14
+ except musicpd.MPDError as err:
15
+ print(f'An error occured: {err}')
16
+ finally:
17
+ client.disconnect()