ldsz / plugin.audio.spotify

Unofficial spotify plugin for Kodi 19
GNU General Public License v3.0
47 stars 17 forks source link

Shutdown/reboot blocked by spotify plugin #10

Open Elkropac opened 3 years ago

Elkropac commented 3 years ago

Hi, when i want reboot or shutdown computer from kodi, it fails, with this in log:

2021-04-25 16:48:29.089 T:1227    ERROR <general>: [25/Apr/2021:16:48:29] ENGINE Error in 'stop' listener <bound method ServerAdapter.stop of <cherrypy._cpserver.Server object at 0x7f841853d8b0>>
                                                   Traceback (most recent call last):
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/process/wspbus.py", line 336, in block
                                                       self.wait(states.EXITING, interval=interval, channel='main')
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/process/wspbus.py", line 376, in wait
                                                       time.sleep(interval)
                                                   SystemExit

                                                   During handling of the above exception, another exception occurred:

                                                   Traceback (most recent call last):
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/process/wspbus.py", line 230, in publish
                                                       output.append(listener(*args, **kwargs))
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/process/servers.py", line 278, in stop
                                                       self.httpserver.stop()
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cheroot/server.py", line 1951, in stop
                                                       self.requests.stop(self.shutdown_timeout)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cheroot/workers/threadpool.py", line 242, in stop
                                                       if worker is not current and worker.isAlive():
                                                   AttributeError: 'WorkerThread' object has no attribute 'isAlive'

It seem, isAlive method was changed to is_alive in python 3.9. Cheroot included in plugin is really old (6.4.0?). Newest version is 8.5.2 with this fixed.

I don't know, if cheroot and cherypy could be easily upgraded.

I changed isAlive to is_alive, for myself, in /resources/lib/cheroot/workers/threadpool.py and I can reboot computer from kodi now

ldsz commented 3 years ago

Hi, I'm running some tests but cheroot can be upgraded to the last version. It's not the same for Cherrypy, as I remember some functions were removed or changed.

Elkropac commented 3 years ago

So, it worked? I will try this updated version

ldsz commented 3 years ago

I have an issue with spotify connect, the first song is ok but the next one is not playing. Local playback is ok for me.

Elkropac commented 3 years ago

I have this in logs

2021-04-27 12:11:51.639 T:1086    ERROR <general>: [27/Apr/2021:12:11:51] HTTP
                                                   Traceback (most recent call last):
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/_cprequest.py", line 638, in respond
                                                       self._do_respond(path_info)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/_cprequest.py", line 697, in _do_respond
                                                       response.body = self.handler()
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/lib/encoding.py", line 219, in __call__
                                                       self.body = self.oldhandler(*args, **kwargs)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/_cpdispatch.py", line 54, in __call__
                                                       return self.callable(*self.args, **self.kwargs)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/httpproxy.py", line 204, in nexttrack
                                                       return self.silence(20)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/httpproxy.py", line 199, in silence
                                                       return cherrypy.lib.static.serve_fileobj(output_buffer.read(), content_type="audio/wav", name="%s.wav" % duration, debug=True)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/lib/static.py", line 184, in serve_fileobj
                                                       return _serve_fileobj(fileobj, content_type, content_length, debug=debug)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/lib/static.py", line 195, in _serve_fileobj
                                                       r = httputil.get_ranges(request.headers.get('Range'), content_length)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/lib/httputil.py", line 91, in get_ranges
                                                       stop = content_length - 1
                                                   TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

When i changed line 199 in httpproxy.py to

return cherrypy.lib.static.serve_fileobj(output_buffer.read(), content_type="audio/wav", name="20.wav", debug=True)

I don't know python, so i just removed the formated print :) I guess, this problem will be on more places.

This error goes away. It still behaves strangely, it drops connection on every track change

ldsz commented 3 years ago

You have a NoneType for content_length because the file is empty or doesn't exist. I have the same. The code is ok but I'm missing the log about the file not requested or downloaded.

The first error is :

2021-04-26 20:59:02.556 T:4644 ERROR : [26/Apr/2021:20:59:02] TOOLS.STATIC os has no fstat attribute 2021-04-26 20:59:02.556 T:4644 ERROR : [26/Apr/2021:20:59:02] TOOLS.STATIC Content-Type: 'audio/wav' 2021-04-26 20:59:02.556 T:4644 ERROR : [26/Apr/2021:20:59:02] TOOLS.STATIC Content-Disposition: None

Elkropac commented 3 years ago

Have you found out something?

Everytime i try to seek in song or to skip to next song (using spotify connect), i get this in log

2021-04-29 23:51:11.057 T:3055    ERROR <general>: [29/Apr/2021:23:51:11] NATIVE_ADAPTER Traceback (most recent call last):
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/_cpnative_server.py", line 89, in respond
                                                       self.send_response(
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cherrypy/_cpnative_server.py", line 117, in send_response
                                                       req.write(seg)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cheroot/server.py", line 1133, in write
                                                       self.conn.wfile.write(chunk)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cheroot/makefile.py", line 438, in write
                                                       res = super().write(val, *args, **kwargs)
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cheroot/makefile.py", line 36, in write
                                                       self._flush_unlocked()
                                                     File "/home/prehravac/.kodi/addons/plugin.audio.spotify/resources/lib/cheroot/makefile.py", line 45, in _flush_unlocked
                                                       n = self.raw.write(bytes(self._write_buf))
                                                     File "/usr/lib/python3.9/socket.py", line 722, in write
                                                       return self._sock.send(b)
                                                   ConnectionResetError: [Errno 104] Connection reset by peer

I cannot figure out, which connection is reset. (I think it is download of wav file in proxy)

For a while, i thought, there is problem of 127.0.0.1 vs ::1 vs localhost connection, because i got this on wireshark image in roughtly the same time as the error in log.

But even after trying to let the http proxy listen to all ip addresses (suboptimal - opens it to network) , i still get connectionresets in log

ldsz commented 3 years ago

I'm not sure to found a solution for now. I commented cherrypy.expose to have a simple solution :

With that modification I can update cheroot and cherrypy to the last version.

Elkropac commented 3 years ago

Ok, thanks. I will try to debug more, maybe with strace. Can you show me picture of your sound selection, i think, i don't see your options there (i use pulseaudio to be able to send in another sounds/music from bluetooth and home assistant)

Elkropac commented 3 years ago

It works now, strange. Today, I tested it with my wifes phone and it connects and changes tracks without problem. I have kodi plugin logged in on her account, but until today, i was testing spotify connect with my phone (and my account). There seems to be problem, when re-login to another account is involved.