Mic92 / python-mpd2

Python library which provides a client interface for the Music Player Daemon.
GNU Lesser General Public License v3.0
352 stars 119 forks source link

Connection lost when using find() #174

Open dgcampea opened 3 years ago

dgcampea commented 3 years ago

Originally reported at: https://github.com/SoongNoonien/mpdevil/issues/38

Using client.find("title", "<string here>") results in connection loss. Searching with mpc client works though.

mpd version: Music Player Daemon 0.22.9 (0.22.9) python-mpd2 version: 3.0.4

Code sample:

>>> from mpd import MPDClient
>>> client = MPDClient()
>>> client.connect("localhost", 6600)
>>> client.find("title", "spend winter")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 469, in mpd_command
    return wrapper(self, name, args, callback)
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 532, in _execute
    return retval()
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 457, in command_callback
    res = self._wrap_iterator(res)
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 706, in _wrap_iterator
    return list(iterator)
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 240, in _parse_objects
    for key, value in self._parse_pairs(lines):
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 235, in _parse_pairs
    for line in lines:
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 586, in _read_lines
    line = self._read_line()
  File "/app/lib/python3.8/site-packages/mpd/base.py", line 571, in _read_line
    raise ConnectionError("Connection lost while reading line")
mpd.base.ConnectionError: Connection lost while reading line
dgcampea commented 3 years ago

Notes:

Mic92 commented 3 years ago

tcpdump output might be helpful here of both mpc and python-mpd.

dgcampea commented 3 years ago

While investigating this, I think python-mpd find("title", "<string here>") is losing connection because it's parsing an empty mpd response and raising an exception. As a test:

$ nc localhost 6600
OK MPD 0.22.4
find title spend winter
OK

mpc search and python-mpd2 search() commands work, the reason mpc doesn't trigger "output buffer full" is because starting from libmpdclient 2.12 and mpd 2.12, mpc requests that mpd report the results with no tags at all. It's not in the documentation but python-mpd tagtypes() does accept arguments and maps them to the MPD protocol tagtypes, so to emulate mpc behavior, MPDClient.tagtypes("clear") should be done before searching and MPDClient.tagtypes("all") after the search is complete to return to the default tagtype state. I don't think this in particular is a python-mpd2 bug but it might be worth mentioning in the docs.