Tyzer34 / plexMusicPlayer

Playback music with Alexa from your Plex Server!
https://medium.com/@Tyzer34/plex-alexa-the-perfect-wedding-38b14b41faf0#.b71cd6lsn
GNU General Public License v3.0
35 stars 19 forks source link

Plex Music Deploy errors #3

Closed tdelesio closed 7 years ago

tdelesio commented 7 years ago

First of all, this has been exactly what I've been looking to to. I want to be able to put on music using my echo. I saw this and was very excited to see that this application solves the problem. I tried to deploy the application to heroku (which I've never used before) and got it up and running. When I interact with the echo however, it times out. I was testing using hte service simulator on developer.amazon.com as well. A couple of questions first before I post the error:

  1. I have multiple plex clients running on my network and my plex server is a headless ubuntu server. What plex client is supposed to play when music is executed by the echo?
  2. From your instructions, you download a file from the server. The ip that is returned is the local ip of the server. I assume that I should be using the outside ip address instead of the local one as the call is coming from heroku.com? Is it possible to use a domain instead of an ip as I have DDNS setup?

Now the error: I asked alexa: "ask plex to play counting stars" via the developer.amazon.com service simulator.

heroku logs: Traceback (most recent call last): 2017-01-03T17:26:17.499331+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app 2017-01-03T17:26:17.499332+00:00 app[web.1]: response = self.full_dispatch_request() 2017-01-03T17:26:17.499332+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request 2017-01-03T17:26:17.499333+00:00 app[web.1]: rv = self.handle_user_exception(e) 2017-01-03T17:26:17.499334+00:00 app[web.1]: reraise(exc_type, exc_value, tb) 2017-01-03T17:26:17.499334+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception 2017-01-03T17:26:17.499335+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise 2017-01-03T17:26:17.499336+00:00 app[web.1]: raise value 2017-01-03T17:26:17.499336+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request 2017-01-03T17:26:17.499338+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request 2017-01-03T17:26:17.499339+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask_ask/core.py", line 516, in _flask_view_func 2017-01-03T17:26:17.499339+00:00 app[web.1]: result = self._map_intent_to_view_func(self.request.intent)() 2017-01-03T17:26:17.499337+00:00 app[web.1]: rv = self.dispatch_request() 2017-01-03T17:26:17.499338+00:00 app[web.1]: return self.view_functionsrule.endpoint 2017-01-03T17:26:17.499345+00:00 app[web.1]: speech, playlist = methods.processQuery(artist, MediaType.Artist) 2017-01-03T17:26:17.499340+00:00 app[web.1]: File "/app/plexmusicplayer/intents/plex_intents.py", line 26, in playArtist 2017-01-03T17:26:17.499346+00:00 app[web.1]: File "/app/plexmusicplayer/methods.py", line 80, in processQuery 2017-01-03T17:26:17.499346+00:00 app[web.1]: json_obj = getJsonFromPlex(searchQueryUrl) 2017-01-03T17:26:17.499347+00:00 app[web.1]: File "/app/plexmusicplayer/methods.py", line 23, in getJsonFromPlex 2017-01-03T17:26:17.499348+00:00 app[web.1]: response = requests.get(url) 2017-01-03T17:26:17.499348+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/requests/api.py", line 70, in get 2017-01-03T17:26:17.499349+00:00 app[web.1]: return request('get', url, params=params, kwargs) 2017-01-03T17:26:17.499349+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/requests/api.py", line 56, in request 2017-01-03T17:26:17.499350+00:00 app[web.1]: return session.request(method=method, url=url, kwargs) 2017-01-03T17:26:17.499351+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/requests/sessions.py", line 488, in request 2017-01-03T17:26:17.499351+00:00 app[web.1]: resp = self.send(prep, send_kwargs) 2017-01-03T17:26:17.499352+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/requests/sessions.py", line 609, in send 2017-01-03T17:26:17.499353+00:00 app[web.1]: r = adapter.send(request, kwargs) 2017-01-03T17:26:17.499353+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/requests/adapters.py", line 487, in send 2017-01-03T17:26:17.499354+00:00 app[web.1]: raise ConnectionError(e, request=request) 2017-01-03T17:26:17.499355+00:00 app[web.1]: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='68.84.99.171.ee51a749bffb4ba6a60b868cba10a375.plex.direct', port=32400): Max retries exceeded with url: /search?query=counting%20stars&X-Plex-Token=&type=8 (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f5d1b42fba8>: Failed to establish a new connection: [Errno -5] No address associated with hostname',)) 2017-01-03T17:26:17.524319+00:00 heroku[router]: at=info method=POST path="/plex" host=alexaplexmusic.herokuapp.com request_id=d1abdda2-2a76-4e19-8fd5-075c7e3b5f9c fwd="72.21.217.104" dyno=web.1 connect=2ms service=179ms status=500 bytes=456

I'm not sure what that fwd ip is as that is not my external ip that is listed. Any idea?

Tyzer34 commented 7 years ago

Hi! Thank you first of all for your interest in this project! Firstly, I would like to point out, that you'd better exclude your Plex token from your post (found at the last part of the error stack). The error is produced because the PLEX_URL env variable isn't set correctly. You used dots for the ip address up front, but it should actually be '-' in between, leading to this Plex URL: https://68-84-99-171.ee51a749bffb4ba6a60b868cba10a375.plex.direct:32400 As for your other questions:

  1. This application does not couple with any Plex client. It just grabs the stream urls from your music content delivered by Plex and transmits them to the Echo device.
  2. It should be possible to use a domain name, if an SSL certificate is set up for your server. The reason that I am using the plex website as a relay to get the stream url's, instead of directly accessing my own Plex server, is because they can deliver content streams over HTTPS. Alexa utterly refuses to play HTTP content, so only streams over HTTPS can be provided to the Echo devices. Hope this helps!
tdelesio commented 7 years ago

Thanks for the feedback. I removed my token. After I asked the question and went back and looked at the code. I saw in the code how it just streams to the device. I guess in theory I could then connect the echo back to my receiver as a bluetooth device. My ultimate goal is to be able to tell alexa to play my music so that it plays off my receiver. I made the change you suggested and changed the ip address from . to - and the error went away but it seams to have generated a new error.

[2017-01-04 19:24:45,351] ERROR in app: Exception on /plex [POST] 2017-01-04T19:24:45.355352+00:00 app[web.1]: Traceback (most recent call last): 2017-01-04T19:24:45.355354+00:00 app[web.1]: response = self.full_dispatch_request() 2017-01-04T19:24:45.355353+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app 2017-01-04T19:24:45.355355+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request 2017-01-04T19:24:45.355355+00:00 app[web.1]: rv = self.handle_user_exception(e) 2017-01-04T19:24:45.355356+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception 2017-01-04T19:24:45.355357+00:00 app[web.1]: reraise(exc_type, exc_value, tb) 2017-01-04T19:24:45.355357+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise 2017-01-04T19:24:45.355358+00:00 app[web.1]: raise value 2017-01-04T19:24:45.355359+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request 2017-01-04T19:24:45.355359+00:00 app[web.1]: rv = self.dispatch_request() 2017-01-04T19:24:45.355361+00:00 app[web.1]: return self.view_functionsrule.endpoint 2017-01-04T19:24:45.355360+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request 2017-01-04T19:24:45.355361+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.5/site-packages/flask_ask/core.py", line 516, in _flask_view_func 2017-01-04T19:24:45.355362+00:00 app[web.1]: result = self._map_intent_to_view_func(self.request.intent)() 2017-01-04T19:24:45.355362+00:00 app[web.1]: File "/app/plexmusicplayer/intents/plex_intents.py", line 26, in playArtist 2017-01-04T19:24:45.355363+00:00 app[web.1]: speech, playlist = methods.processQuery(artist, MediaType.Artist) 2017-01-04T19:24:45.355365+00:00 app[web.1]: File "/app/plexmusicplayer/methods.py", line 56, in parseArtistJson 2017-01-04T19:24:45.355364+00:00 app[web.1]: File "/app/plexmusicplayer/methods.py", line 91, in processQuery 2017-01-04T19:24:45.355364+00:00 app[web.1]: artist, server, playlist = parseArtistJson(json_obj) 2017-01-04T19:24:45.355365+00:00 app[web.1]: artist = json_obj['MediaContainer']['Directory']['@title'] 2017-01-04T19:24:45.355372+00:00 app[web.1]: KeyError: 'Directory' 2017-01-04T19:24:45.362227+00:00 heroku[router]: at=info method=POST path="/plex" host=alexaplexmusic.herokuapp.com request_id=fcc4a663-0197-4e01-8a36-d825b99d58d5 fwd="72.21.217.112" dyno=web.1 connect=1ms service=395ms status=500 bytes=456

Tyzer34 commented 7 years ago

If you connect to a bluetooth receiver via the Echo, it is possible to have your Plex music playback on that receiver!

The error generated comes from the fact that the requested Artist (as litterary written by Alexa Voice Services) could not be found on your Plex device. Yesterday, I added a fix so that this error is caught and an appropriate response is given back. You should thus update your Heroku server with the latest version of PlexMusicPlayer. To do this, open a terminal (or command prompt), navigate to the folder where you have cloned this Git repository from and execute the following commands:

git pull
git push heroku master

git pull should update your local copy to the latest version, while git push heroku master updates the copy on your deployed Heroku server.

tdelesio commented 7 years ago

I figured that out after playing around with a couple more artists. I got it to work both on my echo and got my echo to play through the receiver. I just updated the code base. This is very cool as it now works. Now I need to write something to switch the inputs on my receiver. Thank you for your help.

Tyzer34 commented 7 years ago

Happy to help! Good luck!