This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.

Youtube app

I am planning to create a simple Youtube app, which enables us playback youtube video.
For now this is an extension to chromecast app https://github.com/matjaz/com.google.chromecast/tree/rewrite

I am planning to create following
triggers
- youtube media changed (have url token)
actions
- search youtube (have query argument); triggers change
- get playlist (first, one random, all, all shuffle); triggers change
- play music on Homey (future... when media manager is documented/working)

Because how flows currently work, we need two flows for that.
1.
- when say something (text ->)
- search youtube (-> text)
2.
- when youtube media changes (url ->)
- cast media to chromecast (-> url)


We could use (global) variables, but that needs variables API as I suggested.
Maybe we could add global app events (with new built in general trigger onAppEvent(app, event))
Or implement more advanced actions as suggested here.

Thoughts & suggestions welcome!
«134

Comments

  • First version can be found here https://github.com/matjaz/homey-youtube
  • Why would you global variables? 
  • For sharing state/events between apps. But having a second thought it would be better to use global message bus+api. My idea is to be able link apps together in the flow editor.

    Like what I am doing with Youtube and Chromecast app. You need two flows; 1. to make a youtube search and 2. for  search result to play on Chromecast.
  • If there would be a way to implement it in my variable manager, let me know. I'm more than happy to help out

  • The App works perfect.
    Thank you!
    I managed to get a video played only by voice. But I guess the "Resume listening" flow card does not work yet, I have to say "Ok Homey" again to trigger the 2nd flow.

  • @MatjaLipu GREAT WORK! Really does the trick. In the "search youtube"-card however, teh text tag can't be added. Works fine when searching the playlist card or live card.  Same goes for the chromecast card which says search youtube. But reading the post I bet it's a work in progress. Congrats though on the apps. Brilliantly done.
  • Thank you for your acknowledgment.

    Here is a short description of an app.

    Youtube app
    • "Search Youtube (live)" card; entered text (or token) is searched on youtube (you can also select you want to play best match or random search result)
    • "Get Youtube playlist" card; fetched tracks list and triggers "Youtube media changed", depending on the selected mode:
      • Next - plays next track every time Get Youtube playlist card is triggered
      • Shuffle - selects random track from playlist
      • First - plays only first track
    • "Search Youtube" card; is a convenient for easily search and play one fixed video

    Chromecast app
    • "Cast a video url" card; can play any supported media from URL
    • "Cast a YouTube video" card; is a convenient for easily search and play one fixed video.

    Hope this explains it.
  • Greate app thanks ! (also thanks for the chromecast app  :) ) loving it
  • @MatjaLipu thanks for the guide. Still can't get the playlist to work though. Could you post a screenshot how to implement it in a flow?
  • Thanks for the already great Youtube app. I'm very curious to see which extra function will be added to the Youtube app in the future. It indeed works great with the Chromecast app.

    Just for testing purposes I created three flows. I will describe the flows below to show other people what is possibel with these apps:
    Flow 1: When on is pressed on the KaKu remote get Youtube playlist and play first song
    Flow 2: When Youtube media changed cast url on Chromecast
    Flow 3: When off is pressed on the  KaKu remote get Youtube playlist and shuffle (play random) song

    So now I can use my KaKu remote (or any other remote) to control my jukebox during parties ;).

    Two questions/remarks:
    - Is it possible to keep the playlist running until I want it to stop? I have to click the off button on the KaKu remote after the end of every song.
    - The field in which you have to enter the url is too small and does not size good in the Homey flow cards.
  • WimstradamusWimstradamus Member
    edited February 2016
    i would be nice if you can filter the text token when searching youtube. 
    Exemple i say; he homey Youtube Adele - Hello, and i can filter "Youtube". so it searches for "Adele Hello" instead of "Youtube Adele Hello" 
    (like couchpotato app)
  • Peao said:
    The App works perfect.
    Thank you!
    I managed to get a video played only by voice. But I guess the "Resume listening" flow card does not work yet, I have to say "Ok Homey" again to trigger the 2nd flow.


    When i copy your flows homey react on flow 2 immediately (because of "when you say anything")
    is there a way you can enable flow 2 only if flow1 ended? could't find how, can't drag "flow" in "when" section.
  • Peao said:
    The App works perfect.
    Thank you!
    I managed to get a video played only by voice. But I guess the "Resume listening" flow card does not work yet, I have to say "Ok Homey" again to trigger the 2nd flow.


    When i copy your flows homey react on flow 2 immediately (because of "when you say anything")
    is there a way you can enable flow 2 only if flow1 ended? could't find how, can't drag "flow" in "when" section.
    You have to turn flow 2 off. You can do this when you click on the drop down menue under the flows name and uncheck the 2nd flow.
  • Awesome idea!
    Thank you so much for making this!
  • MatjaLipuMatjaLipu Member
    edited February 2016
    Added support (0.2.0)
    • playlist autoplay
    • speech support
    • play music directly on Homey (experimental)
    • search using api (for other apps)
  • I'd like a speech command to trigger a flow playing a YouTube playlist on a chromecast device. What flow(s) do I need for this to work? This is what I currently have (2 flows):

    Is this correct?

  • MatjaLipuMatjaLipu Member
    edited February 2016
    This looks OK.
    Since you selected First only first item from playlist will be played. "Next" plays all in order, shuffle will play random item. Since 0.2 playlists also supports autoplay.

    Playlist URL should be in the following format https://www.youtube.com/playlist?list=PLueiy8sWqybzUoXf0gD4MXpTJDsiNgdyi
    What do you have?
    Try with some debug flow notification to see what text you get from speech.
  • Thanks for the update MatjaLipu! However, I'm still not able to get the playlist autoplay working in version 0.2. I have about the same flows as Brinkie is using except I have it on shuffle. Furthermore, the link is in the same format as you used as an example in your previous post (I even tried your playlist URL).


  • Sorry for that. Autoplay is supported in (upcoming) 0.3 version.
    Also added more lax speech commands:
    • "watch Adele from YouTube"; triggers "YouTube media changed"
    • "play Adele from YouTube"; plays music on Homey
    You can also skip "from".
  • MatjaLipu said:
    This looks OK.
    Since you selected First only first item from playlist will be played. "Next" plays all in order, shuffle will play random item. Since 0.2 playlists also supports autoplay.

    Playlist URL should be in the following format https://www.youtube.com/playlist?list=PLueiy8sWqybzUoXf0gD4MXpTJDsiNgdyi
    What do you have?
    Try with some debug flow notification to see what text you get from speech.
    Well, the led ring start a green rotation, so my speech command definately worked and the playlist url is comparable to yours. But the second flow (triggered by YouTube media change) never runs. Any ideas?
  • Can you help debug by installing local version with athom project --run? Throw some logs in lib/playlist and lib/util trigger function.
  • MatjaLipu said:
    Can you help debug by installing local version with athom project --run? Throw some logs in lib/playlist and lib/util trigger function.
    I'll give that a try and see what I can find.
  • @MatjaLipu What does this do in your app.json?

    "fluidArgs": true

  • @MatjaLipu Running the YouTube app locally now. It throws this exception after activating the first flow through speech:

    Archiving...
    Uploading to 192.168.2.xxx.yy...
    Running `com.youtube`...
    Debugging...
    YouTube ready
    [Error: Cannot read property '0' of undefined]

  • And at seconds attempt:

    TypeError: Cannot read property 'length' of undefined
        at selectNextInPlaylist (/lib/playlist.js:59:63)
        at Object.onFlowActionPlayListItems (/lib/playlist.js:28:5)
        at Object.emit (events.js:118:17)
        at /opt/homey-client/system/types/manager/apps/bootstrap/homey-app/manager/f
    low.js:1:188
        at /opt/homey-client/system/types/manager/apps/bootstrap/homey-app/helpers/c
    lient.js:1:852
        at Array.forEach (native)
        at process.<anonymous> (/opt/homey-client/system/types/manager/apps/bootstra
    p/homey-app/helpers/client.js:1:821)
        at process.emit (events.js:110:17)
        at handleMessage (child_process.js:324:10)
        at Pipe.channel.onread (child_process.js:352:11)

  • brinkiebrinkie Member
    edited February 2016

    @MatjaLipu Would you mind trying it yourself? I can't seem to understand the flow of your code. It has something to do with the playlist. Maybe with caching?

    At first my playlist was private, which I changed to unlisted. Still didn't work. This is my playlist id: PLCnbzXkuy4_ZnobZc2viz1qncZ9UGXkba

    Thanks for looking into this.

  • Ahhh, you need env.json in root
    {
        "YOUTUBE_KEY": "YouTube API key from google console"
    }
    Your playlist is working /w np.
  • So how do I set that key as a user of the app?
  • MatjaLipuMatjaLipu Member
    edited February 2016
    For users this key is stored in app store.
  • MatjaLipu said:
    For users this key is stored in app store.
    Ok, that explains it. I'll do some more testing.
Sign In or Register to comment.