matjaz/homey-youtube

"no playlist items" error

gajdur opened this issue · 33 comments

Get YouTube playlist is giving back "no playlist items" error.

Debugging with athom project --run not showing nothing in the console

Searching Youtube is giving back "cannot read property 'map' of und...

3/4 - Running com.youtube, press CTRL+C to abort...
4/4 - Debugging...


YouTube ready
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]

try uncommenting line https://github.com/matjaz/homey-youtube/blob/master/lib/search.js#L44
and add Homey.log('search autocomplete result', result)

YouTube ready
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]

try with
Homey.log('search autocomplete result', result)

Hi Matjaz, the inputs above was with uncommented line and "Homey.log('search autocomplete result', result)".

please double check. original code is using result.items.. I just want to see what result is

Hi Matjaz, uncomenting Line 44:

3/4 - Running com.youtube, press CTRL+C to abort...
4/4 - Debugging...


YouTube ready
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]
[TypeError: Cannot read property '0' of undefined]

Using "Homey.log('search autocomplete result', result)":

3/4 - Running com.youtube, press CTRL+C to abort...
4/4 - Debugging...


YouTube ready
search autocomplete result { error: { errors: [ [Object] ], code: 400, message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
search autocomplete result { error: { errors: [ [Object] ], code: 400, message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
search autocomplete result { error: { errors: [ [Object] ], code: 400, message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
search autocomplete result { error: { errors: [ [Object] ], code: 400, message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
search autocomplete result { error: { errors: [ [Object] ], code: 400, message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]

ok, so response is some error. let's explore what it is
console.log(require('util').inspect(result, { depth: 10 }))

3/4 - Running com.youtube, press CTRL+C to abort...
YouTube ready
4/4 - Debugging...


{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }
[TypeError: Cannot read property 'map' of undefined]
[TypeError: Cannot read property 'map' of undefined]
{ error:
{ errors:
[ { domain: 'usageLimits',
reason: 'keyInvalid',
message: 'Bad Request' } ],
code: 400,
message: 'Bad Request' } }

Hi Matjaz, still having problems, uncommenting line 53:
[TypeError: Cannot read property '0' of undefined]

With: console.log(require('util').inspect(result, { depth: 10 }))
in when: Bad Request: usageLimits keyInvalid
[TypeError: Cannot read property '0' of undefined] into console

Greets

Aha, now I understand what's happening.
YouTube app requires YouTube API key.
If you've installed it from app store you get one from app store, but since you're installing it from github you need to provide your own.
You can obtain (YouTube Data API) server key from https://console.developers.google.com
and you should add it to (root) env.json.

{
    "YOUTUBE_KEY": "server-key-from-console",
}

Hi Matjaz, sorry for the late answer.

Do you mean to make a env.json file in the app root directory with the youtube API Key?

Tnx
Viktor

exactly. search for env.json on https://developers.athom.com/library/appstore/

Hi Matjaz

sorry, even after making a youtube server key and activating, making the env.json, still having the same problem: Bad Request: usageLimits keyInvalid

no success, still having the same error while searching and "no playlist items" when using playlist url

tryed now with uncommented logs lines into playlist.js
Playlist URL is ok:

3/4 - Running com.youtube, press CTRL+C to abort...
YouTube ready
4/4 - Debugging...


playlist items { url: 'https://www.youtube.com/playlist?list=PLvFYFNbi-IBFeP5ALr50hoOmKiYRMvzUq',
mode: 'next' }
playlist items { url: 'https://www.youtube.com/playlist?list=PLvFYFNbi-IBFeP5ALr50hoOmKiYRMvzUq',
mode: 'shuffle' }

error is still "no playlist items"

in /lib/youtube.js
after line params.key =..
add
console.log(endpoint, JSON.stringify(params)) to see what requests are being made.

1/4 - Archiving...
2/4 - Uploading to H2-HOMEY-1 @ 192.168.10.22:80...
3/4 - Running com.youtube, press CTRL+C to abort...
4/4 - Debugging...


YouTube ready
playlistItems {"part":"contentDetails","maxResults":50,"playlistId":"PLvFYFNbi-IBFeP5ALr50hoOmKiYRMvzUq"}
search {"part":"id,snippet","q":"","type":"video","maxResults":10}
search {"part":"id,snippet","q":"t","type":"video","maxResults":10}
search {"part":"id,snippet","q":"te","type":"video","maxResults":10}
search {"part":"id,snippet","q":"tes","type":"video","maxResults":10}
search {"part":"id,snippet","q":"test","type":"video","maxResults":10}
search {"part":"id,snippet","q":"tes","type":"video","maxResults":10}
search {"part":"id,snippet","q":"te","type":"video","maxResults":10}
search {"part":"id,snippet","q":"t","type":"video","maxResults":10}
search {"part":"id,snippet","q":"","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2c","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2cel","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2cell","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2cello","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2cellos","type":"video","maxResults":10}
search {"part":"id,snippet","q":"2ce","type":"video","maxResults":10}
search {"part":"id,snippet","q":"piano","type":"video","maxResults":10}
[TypeError: Cannot read property '0' of undefined]

tryed first with playlist, then search, then search live.

key param is missing. If you put log AFTER params.key = Homey.env.YOUTUBE_KEY line, then you haven't setup env.json correctly.

Try adding console.log('key', Homey.env.YOUTUBE_KEY) as first line in this function. it should display your key. Please double check.

p.s. 2cellos rocks!

Strange, "key undefined". I have env.json in the main folder with:

{
"YOUTUBE_KEY": "AIzaSyCYub6e8sxxxxxxxyyyyykV7GZdgijbg",
}

p.s. they are great, 2cellos, ex zemjaci :-)

without comma at the end. my bad. :(

:-) Sorry, me to. Not realised on developers.athom.com that only the first line is with.

Newbee here.

Hi Matjaz, now working fine like on the beginning. Can i ask you how you intend to use the "source" for streaming different videos on different chromecasts at once? I tryed now couple of flows but still having the same playlist on both casts.

Tnx

you need to add a condition checking source, to a flow containing media changed trigger.

Now i have something like that, must test tonight at home.

flow1
flow2

this wont work. source is url of video, playlist.. url is url of raw video played on chromecast. they are not the same.
you can just check if source contains playlist id or send token values to some chat/sms or sth to see what they are. see https://forum.athom.com/discussion/comment/29562/#Comment_29562

Hmmm, yes i see now the difference in source/url, maybe like this?
flow2

that looks ok.

Hi Matjaz, testing the new version now and is partially working:
when i start one chromecast with a playlist and couple seconds later the second chromecast with other playlist, everything is ok. But now after the first media change only one cast is working, the second one is no streaming more while the source is no more containing the playlist id.

Any idea how to proceed?

Tnx