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

Different results for two songs in the same album #23

Open Loginno opened 7 years ago

Loginno commented 7 years ago

Hi again,

There is a strange behavior related to indexing the songs, I guess. Please see the following two requests, for two songs from the same album (Dark side of the moon by Pink Floyd)

Successful request: "alexa ask my pc to play the song money by pink floyd"

Request #1: { "session": { "sessionId": "SessionId.ed583f0e-3820-4891-858f-1dd5e51bf2f0", "application": { "applicationId": "amzn1.ask.skill.7b83d8df-896f-4ea9-ac28-be42c5ce6665" }, "attributes": {}, "user": { "userId": "amzn1.ask.account.AELT5B7UNT6V6R4NCALAGQKCP7BXUAYP6OGGOXTFGX6MA76ZSBAA3FBNZ5PZKDUSE2SJEZBPKGICO75R3WWVTHMN2D4HZQGQHCX4GOP42BJCPV3PNUR3KMKBG3DH672VMOEHHXFPF4DLFFLHBGBC7QRX7OLAFIQVXAZYZCMXIO7AXTSQWSXB6N7IRXQP3GD44U2ZCOH6E5MNR2Y" }, "new": true }, "request": { "type": "IntentRequest", "requestId": "EdwRequestId.71a43879-0f08-4040-9def-91cb2f2072c7", "locale": "en-US", "timestamp": "2017-02-06T13:10:30Z", "intent": { "name": "PlexPlayTrackByArtistIntent", "slots": { "artist": { "name": "artist", "value": "pink Floyd" }, "track": { "name": "track", "value": "money" } } } }, "version": "1.0" }

Response: { "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "Playing Money by Pink Floyd from your PC." }, "shouldEndSession": true }, "sessionAttributes": {} }

Unsuccessful request: "alexa ask my pc to play the song time by pink floyd"

Request #2:

{ "session": { "sessionId": "SessionId.3ae42441-56ea-48c4-9350-2799f5c3f64d", "application": { "applicationId": "amzn1.ask.skill.7b83d8df-896f-4ea9-ac28-be42c5ce6665" }, "attributes": {}, "user": { "userId": "amzn1.ask.account.AELT5B7UNT6V6R4NCALAGQKCP7BXUAYP6OGGOXTFGX6MA76ZSBAA3FBNZ5PZKDUSE2SJEZBPKGICO75R3WWVTHMN2D4HZQGQHCX4GOP42BJCPV3PNUR3KMKBG3DH672VMOEHHXFPF4DLFFLHBGBC7QRX7OLAFIQVXAZYZCMXIO7AXTSQWSXB6N7IRXQP3GD44U2ZCOH6E5MNR2Y" }, "new": true }, "request": { "type": "IntentRequest", "requestId": "EdwRequestId.a160fe85-c146-4b97-b379-9acb72b4f5f9", "locale": "en-US", "timestamp": "2017-02-06T13:16:56Z", "intent": { "name": "PlexPlayTrackByArtistIntent", "slots": { "artist": { "name": "artist", "value": "pink Floyd" }, "track": { "name": "track", "value": "time" } } } }, "version": "1.0" }

Unsuccessful response:

{ "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "I was not able to find time by pink Floyd in your library." }, "shouldEndSession": true }, "sessionAttributes": {} }

Any ideas?

Loginno commented 7 years ago

Logs:

2017-02-06T13:15:01.903562+00:00 heroku[router]: at=info method=POST path="/plex" host=plexmusicshachar.herokuapp.com request_id=d4a41282-cee1-441c-a818-860d2ddcee27 fwd="72.21.217.82" dyno=web.1 connect=0ms service=55ms status=400 bytes=161 2017-02-06T13:15:07.336135+00:00 heroku[router]: at=info method=POST path="/plex" host=plexmusicshachar.herokuapp.com request_id=81076f27-2826-4f15-b6a2-58be8917f073 fwd="72.21.217.82" dyno=web.1 connect=1ms service=127ms status=400 bytes=161 2017-02-06T13:15:07.311138+00:00 app[web.1]: Current counter value: 0 2017-02-06T13:15:07.311156+00:00 app[web.1]: Playback stopped at 5.38 2017-02-06T13:15:09.059221+00:00 heroku[router]: at=info method=POST path="/plex" host=plexmusicshachar.herokuapp.com request_id=ec0b87b7-8243-404a-a4db-683a25fb24f9 fwd="72.21.217.82" dyno=web.1 connect=39ms service=115ms status=200 bytes=257 2017-02-06T13:16:56.290415+00:00 app[web.1]: [ip]/search?query=time&X-Plex-Token=[]&type=10 2017-02-06T13:16:57.281396+00:00 heroku[router]: at=info method=POST path="/plex" host=plexmusicshachar.herokuapp.com request_id=7c7842ed-02e6-4fd8-a3c3-68575a4113ce fwd="72.21.217.98" dyno=web.1 connect=1ms service=1025ms status=200 bytes=346 2017-02-06T13:16:57.263457+00:00 app[web.1]: parseTrackJson 2017-02-06T13:19:49.398619+00:00 app[web.1]: https://[ip]/search?query=Time&X-Plex-Token=[]&type=10 2017-02-06T13:19:50.340325+00:00 heroku[router]: at=info method=POST path="/plex" host=plexmusicshachar.herokuapp.com request_id=c9f3c38f-a5c3-47fa-9d18-f4c20a354cf9 fwd="72.21.217.96" dyno=web.1 connect=1ms service=1009ms status=200 bytes=346 2017-02-06T13:19:50.330956+00:00 app[web.1]: parseTrackJson

Loginno commented 7 years ago

More research on the same album:

Working: alexa ask my pc to play the song breathe by pink floyd alexa ask my pc to play the song money by pink floyd alexa ask my pc to play the song brain damage by pink floyd alexa ask my pc to play the song eclipse by pink floyd

Not working ("I was not able to find XXX by pink Floyd in your library.") alexa ask my pc to play the song time by pink floyd alexa ask my pc to play the song the great gig in the sky by pink floyd alexa ask my pc to play the song any color you like by pink floyd

Playing different song: alexa ask my pc to play the song on the run by pink floyd ("Playing - One Of These Days by Pink Floyd from your PC.")

jamesshaw1987 commented 7 years ago

If you visit https://[ip]/search?query=Time&X-Plex-Token=[token]&type=10 in a browser, what do you see?

You should probably remove your Plex token in the logs above by the way, don't want to give a helping hand to anyone looking to access your server.

Loginno commented 7 years ago

Thanks for the tip.

This is what I see:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

Loginno commented 7 years ago

Cannot show XML...

Text is here: https://justpaste.it/138qz

jamesshaw1987 commented 7 years ago

Right, thanks. The reason for the failure with this track then is that when searching Plex it returns results in pages of 15 (ordered alphabetically) and you have more than 15 tracks containing the word 'Time'. The Pink Floyd track you want doesn't appear in the first 15 results, so when the code tries to find the track by that artist it can't. We're a bit limited by what Plex allows in terms of searching, so not certain what solutions can be put in place for this. But there'll be some way of handling things better.

Loginno commented 7 years ago

Understood, but isn't there a way to search Plex by [track name] AND [artist name]? Because in that case it would be much fewer tracks. Another way to approach is by ordering the EXACTLY NAMED tracks first, for example: if [trackname] = "time" it would be higher order than if [trackname] contains "time". Then it would work.

Loginno commented 7 years ago

I remember searching for "back to black" without a lot of success, but "back to black by amy winehouse" worked!

jamesshaw1987 commented 7 years ago

There's nothing I'm aware of that allows that type of search in Plex unfortunately. The type flag at the end of the URL determines what Plex searches for (track, album or artist) and the string provided as the query is used to search in the designated field of the track metadata.

Loginno commented 7 years ago

Please see here: https://code.google.com/archive/p/plex-api/wikis/PlexWebAPIOverview.wiki

Advanced Filtering -> "When multiple parameters are passed, they are logically ANDed together."

Loginno commented 7 years ago

Referred to from here: https://docs.google.com/document/d/19bTQr99oKn2pOpHcVtqidokbq9zup-K-mFy8JmII6uQ/edit

Loginno commented 7 years ago

Hey, should your last fix solve this issue?

Loginno commented 7 years ago

(answering to myself) No it didn't... :(

kylebrandonwilson commented 7 years ago

So, there was some really strange stuff going on with the track intents because of the type defined in the intentSchema, we fixed that, but it sounds like that didn't help you much. The fuzzy matching bit might help with this a bit, but it only fuzzy matches on albums and artists currently not tracks or playlists (and there was a few small bugs in it on the first rollout that are fixed now)... I plan on extending it to attempt the query as is on the first go, then fuzzy match each piece individually to give the best response on the first go rather than just returning the first item on the list... I'll post here when I've got that done and we can see if it fixes what you are seeing.

jamesshaw1987 commented 7 years ago

Whilst it's worth a go, I'm not sure that'll help in this situation.

Without being able to specify both artist and song in the same query to Plex the other options are to either increase the number of results a query to Plex returns on a single page or to be able to fetch the next page of results from Plex. As the documentation of the Plex API (especially for music) is scant at best I'm not sure how this can be done or if it is even possible. I've tried making a few guesses at URL parameters (page=2, limit=20, offset=15, etc.), but haven't found anything that has an effect.

kylebrandonwilson commented 7 years ago

What I was imagining is isolating the best match for the artist, querying all of their songs and finding the best match amongst those...