Giter Club home page Giter Club logo

ytube_music_player's Introduction

yTube Music Player

hacs_badge

mini-media-player

The purpose of this integration is to provide easy access to media (Tracks/Playlists/Albums) of your YouTube Music premium subscription. The integration will let you login to your account and present you a GUI similar to the YouTube website, where you can select your playlist/album/.. but in HomeAssistant, actually in the "Media Browser" of HomeAssistant.

Once you've selected what you want to listen (e.g. a Playlist) it will grab the YouTube ID (everything has unique IDs at YouTube) decode it to a streaming URL and forward that URL to a HomeAssistant media_player of your choice, the "remote_player". This works great in combination with Google Chromecasts but other media_player might work as well, as long as they can stream from a URL (the Alexa integration can't do this to my knowledge).

Media_player in Homeassistant are not designed to play multiple tracks, so the playback on the remote_player will usually just stop, once it reaches the end of the track. We as user often don't want that. We want to listen to a complete album or a playlist with multiple tracks. Hence this integration will buffer the playlist and supervise the status of the remote_player. Once it detects that the playback stopped it will start the next track of the playback ... so this integration is kind of a DJ, always making sure that you're entertained. :)

This integration will show up in homeassistant as media_player + (optional) sensor. The media_player itself is required to offer the media_browser dialog, the sensor will provide extra information like the buffered playlist.

Features

  • Browse through all you library tracks / artists / playlists showing names and covers of the media
  • Either plays straight from the playlist or creates a radio based on the playlist
  • Forwards the streaming data to any generic mediaplayer
  • Keeps auto_playing as long as it is turned on
  • On the fly change of the remove_player (playlist will stay the same, and position in track will be submitted to next player)

Support

If you like what I've done and you want to help: buy me a coffee/beer. Thanks!

Beer

Overview / Step - by - step guide

  1. Initial setup: Videotutorial
  • (required) install the component via HACS see Installation
  • (required) configure the component via config flow, see details for the see Setup

you can now use it via the media browser and the default mediaplayer card, but please read on ...

  1. Mini-media-player Videotutorial
  1. (optional for mpd / sonos) install the automation to fix see auto-advancing
  2. (optional) install automations

if you find a bug, or want some extra informations

  1. (debug) enable debug info

Installation via HACS

Please install this custom component via HACS.

Once you've installed HACS follow this Guide and install the yTube_music_player from the default HACS repository.

Setup

Please use the config flow of Home Assistant

  1. Go to Settings -> Devices -> "Add integration" -> "YouTube Music Player"
    1. If the integration didn't show up in the list please REFRESH the page
  2. The integration will interact with the YouTube Music server via Googles oAuth method. You have to grand access for that. Copy the shown URL to a separate browser window and follow the instructions on the screen.
  3. On the second page you can configure the name of the player (handy if you want multiple players), define the default "remote player" and the oAuth file location (also needed if you want multiple player)
  4. The last (and optional) page shows several checkboxes for dropdown field. You can leave the default values, or pick the items you want to use. (see below)

Installation went fine, what now?

At this point you should have a new entity called media_player.ytube_music_player (or similar if you've changed the name). Open the media_browser, make sure this new media_player is selected (lower right corner). You'll see an overview of differnt types like playlists / albums etc. Go, open a section and click play on one of those items. At this point you should hear some music from the remote_player.

@pathofleastresisor build a great custom card for the ytube_music_player that you can find here. I really recommend to use this card to ease the navigation within YouTube.

polr-ytube-media-card

Ok, the media_browser and polr-ytube-media-card are nice, but what if you want a little more? Like automations, or call it via Node-Red or Appdaemon .. I mean, we're in HomeAssistant, right? Well you don't have to use the media_browser. You can start a playback directly. All you need to know is the 'type' of the media (playlist / album / track / ..) and the 'id'.

The easiest way to get those information is to start the playback once with the media_browser and then (while it is still playing) checkout the media_player state. Go to 'development tools' -> 'states' and find media_player.ytube_music_player. It will display some attributes. Note _media_id (e.g. 'PL1ua59sKbGkcgVVsiMuPxlq5vaIJn4Ise') and _media_type (e.g. 'playlist') Once you have those information, stop the playback. Go to the service tab ('development tools' -> 'services') and find the service called 'Media Player: Play media'. Click on 'fill example data' and you should see something like this:

service: media_player.play_media
target:
  entity_id: media_player.ytube_music_player
data:
  media_content_id: https://home-assistant.io/images/cast/splash.png
  media_content_type: music

Replace the 'https://home-assistant.io/images/cast/splash.png' with your 'id' from _media_id above and music with the _media_type and hit 'call service'.
Now the same music should start playing. Neat right? From here you can go on and create your automations. (Also see 'Automations' section below).

Shortcuts

The screenshot below shows the mini-media-player from kalkih (https://github.com/kalkih/mini-media-player)

mini-media-player

This mediaplayer offers shortcuts, which can be used to directly start the playback of a album or playback. It can even be used to change the remote_player with a single click.

- type: 'custom:mini-media-player'
  entity: media_player.ytube_music_player
  artwork: cover
  hide:
    shuffle: false
    icon_state: false
  shortcuts:
    columns: 3
    buttons:
      - name: Badezimmer
        type: source
        id: badezimmer
      - name: Keller
        type: source
        id: keller
      - name: Laptop
        type: source
        id: bm_8e5f874f_8dfcb60f
      - name: My Likes
        type: channel
        id: PLZvjm51R8SGuxxxxxxx-A17Kp3jZfg6pg
      - name: Lala
        type: playlist
        id: PLZvjm51R8SGuxxxxxxx-A17Kp3jZfg6pg

Services

There are multiple services available the most important once are media_player.select_source and media_player.play_media.
media_player.select_source will change the 'remote_player', just pass the entity_id of the new remote speaker to it.

mini-media-player shortcut type service call details
source media_player.select_source source=id and entity_id=[this] selects the media_player that plays the music. id can be an entity_id like media_player.speaker123 or just the name speaker123

To start a playback use the media_player.play_media service.

type for mini-media-player or media_content_type for the service call details
playlist plays a playlist from YouTube. You can get the playlist Id from the Youtube Music website. Open a playlist from the library and copy the id from the link e.g. https://music.youtube.com/playlist?list=PL6H6TfFpYvpersxxxxxxxxxaPueTqieF. You can also use media_content_id: all_library_tracks to start a playlist with all tracks from your library.
channel Starts a radio based on a playlist. So the id has to be a playlist_id
vid_channel Starts a radio based on a videoId. So the id has to be a video_id
album plays an album. You can get the album Id from the Youtube Music website. Open an album from the library https://music.youtube.com/library/albums and copy the Id from the links
track will play only one dedicated track
history will play a playlist from your recent listen music on the website or the app the music that you play with this component will not show up in the list
user_tracks this type will play the uploaded tracks of a user
user_album uploaded album of a user
user_artist play all uploaded tracks of an artists

All calls to media_player.play_media need three arguments: media_content_id is the equivalent of the shortcut id, media_content_type represents the type (e.g. album) and the entity_id is always media_player.ytube_music_player

You can also select the music you want to listen to via the media_browser and look up the media_content_type and media_content_id in the attributs of the player.

In addition the following special commands are also available:

Service parameter details
ytube_music_player.rate_track entity_id: media_player.ytube_media_player, rating: thumb_up / thumb_down / thumb_middle / thumb_toggle_up_middle, rate_track, song_id: ID of the track Rates the currently playing song (or if provided: the song_id). The current rating is available as 'likeStatus' attribute of the player entity_id. middle means that the rating will be 'indifferent' so basically removes your previous rating
ytube_music_player.limit_count entity_id: media_player.ytube_media_player, limit: number of tracks Limits the amount of tracks that is loaded into the playlist, e.g. to stop playing after 3 tracks. Setting -1 as value disables the feature again.
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: reload_dropdowns Reloads the dropdown list of all media_players and also the playlists. Might be nice to reload those lists without reboot HA
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: interrupt_start Special animal 1/2: This will stop the current track, but note the position in the track. It will also store the track number in the playlist and the playlist. Finally it will UNTRACK the media_player. As result you can e.g. play another sound on that player, like a door bell or a warning
ytube_music_player.start_radio entity_id: media_player.ytube_media_player Starts a radio, based on the current playing track
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: interrupt_resume Special animal 2/2: This is the 2nd part and will resume the playback
ytube_music_player.add_to_playlist entity_id: media_player.ytube_media_player, song_id: define the ID of the song you want to add. Skip this parameter if you want to add the song that is currently playing, playlist_id: define the ID of the playlist, skip this if you've started a channel based on your own playlist and want to add the song to that playlist Adds a song to a playlist
ytube_music_player.remove_from_playlist entity_id: media_player.ytube_media_player, song_id: define the ID of the song you want to remove. Skip this parameter if you want to remove the song that is currently playing, playlist_id: define the ID of the playlist, skip this if you want to remove the song from the current playlist (requires that you've started playing via playlist) Removes a song from a playlist
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: off_is_idle Some media_player integrations, like MPD or OwnTone server, switch to off state at the end of a song instead of switching to idle state. Calling this method will make YTube music player detect an off state also as "idle" state. Consequence ofcourse is that manual turning off of the remote player will also trigger next song.
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: paused_is_idle Some media_player integrations, like Sonos, will switch to paused at the end of a song instead of switching to idle state. Calling this method will make YTube music player detect a paused state also as "idle" state. Consequence ofcourse is that manual pausing of the remote player will also trigger next song.
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: idle_is_idle If the idle detection method was changed by calling the off_is_idle or paused_id_idle method, this service call will reset the idle detection back to the default behavior where the next song is only started when the remote media_player switches to the actual idle state.
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: ignore_paused_on_media_change Some media_player integrations, like OwnTone server, temporarily switch to paused when next/prev track is manually selected or when a new position in the current track is selected (seek). By default YTube music player will always try to sync its state with the remote player, hence in this case pause playback on next/prev track or seek actions. Calling this method will make YTube music player ignore next playing -> paused state change of the remote player whenever a manual next/prev track or seek action is performed.
ytube_music_player.call_method entity_id: media_player.ytube_media_player, command: do_not_ignore_paused_on_media_change This call will reset a previous ignore_paused_on_media_change call.

Dropdowns, Buttons and Marksdowns

The player can controlled with shortcut from the mini-media-player, with direct calls to the offered services or simply by turing the player on. However certain extra informations are required to controll what will be played and where to support the "one-click-turn-on" mode. These are presented in the form of drop-down fields, as shown in the screenshot below. Go to the 'options' dialog (configflow) and choose the dropdowns you want to use.

The player attributes contain addition informations, like the playlist and if available the lyrics of the track lyrics The yaml setup is available at package/markdown.yaml

Automations

Play my favorite playlist in random mode on my kitchen speaker (kuche)

alias: ytube morning routine
sequence:
  - service: media_player.select_source
    data:
      source: kuche
      entity_id: media_player.ytube_music_player
  - service: media_player.shuffle_set
    data:
      shuffle: true
      entity_id: media_player.ytube_music_player
  - service: media_player.play_media
    data:
      entity_id: media_player.ytube_music_player
      media_content_id: PL6H6TfFpYvpersEdHECeWkocaPueTqieF
      media_content_type: playlist
mode: single

Interrupt current playback, play a "DingDong" and resume playback

alias: dingdong
sequence:
  - service: ytube_music_player.call_method
    entity_id: media_player.ytube_music_player
    data:
      command: interrupt_start
  - variables:
      vol: '{{ state_attr("media_player.keller_2", "volume_level") }}'
  - service: media_player.volume_set
    entity_id: media_player.keller_2
    data:
      volume_level: 1
  - service: media_player.play_media
    entity_id: media_player.keller_2
    data:
      media_content_id: 'http://192.168.2.84:8123/local/dingdong.mp3'
      media_content_type: music
  - delay: '00:00:02'
  - service: media_player.volume_set
    entity_id: media_player.keller_2
    data:
      volume_level: 0
  - service: ytube_music_player.call_method
    entity_id: media_player.ytube_music_player
    data:
      command: interrupt_resume
  - service: media_player.volume_set
    entity_id: media_player.keller_2
    data:
      volume_level: '{{vol}}'
mode: single

Play a radio on the current track:

alias: RadioOnSong
sequence:
  - service: media_player.play_media
    data:
      media_content_id: >
        {{state_attr("media_player.ytube_music_player","_media_id") }}
      media_content_type: vid_channel
    entity_id: media_player.ytube_music_player

Proxy

Some media_players have issues playing the forwarded streams from YTube music player. E.g. Playback on Sonos speakers returns a "mime-type unknown" error. Also many DLNA devices are quite picky about the stream and may fail to play it for several reasons (e.g. URL too long, invalid format). A workaround is to use a proxy that will in turn stream a compatible file to the problem device.

Method 1: Built-in proxy

YTube music player provides a simple built-in proxy functionality where it will download the current track and place it in a local folder (e.g. /config/www) and forward a predefined url pointing to that downloaded track to the target media_player.

Update 01/2022: Playback using the proxy is currently flawed. YouTube Music reduced the download speed to something close to real-time. The solution below relied on a fast download and thus won't work any more (will take ~3min to buffer the song before it can be played).

This feature can be activated by providing two settings:

  1. proxy_path | This is the local folder, that the component is using to STORE the file. The easiest way it to provide your www folder. Be aware: If you're using a docker image (or HassOS) that the component looks from INSIDE the image. So for most users the path will be /config/www
  2. proxy_url | The path will be send to your Sonos speaker. So typically this should be something like http://192.168.1.xxx:8123/local. Please note that https will only work if you have a valid ssl-certificat, otherwise the Sonos will not connect.

You can also use a dedicated server, if you don't want to use homeassistant as http server, or you have some special SSL setup. If you're running docker anyway you could try docker run --restart=always --name nginx-ytube-proxy -p 8080:80 -v /config/www:/usr/share/nginx/html:ro -d nginx This will spin up server on port 8080 that serves /config/www so your proxy_url would have to be http://192.168.1.xxx:8080.

You can use this also with other speakers, but it will in general add some lack as the component has to download the track before it will start the playback. So if you don't need it: don't use it. If you have further question or if this is working for you please provide some feedback at #38 as I can't test this on my own easily. Thanks!

Method 2: OwnTone server as proxy

OwnTone server through the OwnTone HA integration is able to play the stream provided by YTube music player and can output the stream to either OwnTone server configured targets (by default it should detect DLNA and AirPlay devices on the network) or serve the stream as a file http://SERVER_ADDRESS:3689/stream.mp3 in real-time.

  • Set up OwnTone server

    You can set up an independent OwnTone server using the instructions here or you can use the OwnTone server HA addon by @a-marcel. Note: Currently only the beta version from this repo seems to work with recent versions of HA.

  • Install the HA OwnTone integration

    After installation, it should automatically detect your OwnTone server. See the OwnTone integration page for more information.

  • After a restart of HA you should now be able to select the OwnTone server as target speaker

    However the OwnTone server/integration has a few odities of its own: it will turn to state 'off' instead of 'idle' at the end of a track and it will shortly switch to state 'paused' when next/previous track is selected or when performing a seek in the current track. YTube music player can handle this, but requires some extra service calls to know about this behavior:

    • Send commands off_is_idle and ignore_paused_on_media_change to the YTube music player entity.

As mentioned above, OwnTone should auto-detect DLNA and Airplay devices automatically, if they are in the same subnet as the OwnTone server. If that is the case, you can set the current output of OwnTone server using the OwnTone integration.

For other devices like e.g. Sonos speakers, or if you have problems with the auto-detection of OwnTone, you can use HA media_player integrations (Sonos, DLNA, ...) to play the URL http://SERVER_ADDRESS:3689/stream.mp3 which should contain the YTube music stream when YTube music player is streaming to the OwnTone media_player.

Example automation to set up YTube music player when OwnTone server is set as target speaker:

alias: Set YT Music player settings according to selected speakers
mode: single
trigger:
  - platform: state
    entity_id:
      - select.ytube_music_player_speaker
    from: null
    to: null
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: select.ytube_music_player_speaker
            state: OwnTone server                
        sequence:
          - alias: Detect OFF state also as idle
            service: ytube_music_player.call_method
            data:
              entity_id: media_player.ytube_music_player
              command: off_is_idle
          - alias: Ignore PLAYING to PAUSED transition after media change
            service: ytube_music_player.call_method
            data:
              entity_id: media_player.ytube_music_player
              command: ignore_paused_on_media_change
    default:
      - alias: Only detect IDLE state as idle
        service: ytube_music_player.call_method
        data:
          entity_id: media_player.ytube_music_player
          command: idle_is_idle
      - alias: Do NOT ignore PLAYING to PAUSED transitions
        service: ytube_music_player.call_method
        data:
          entity_id: media_player.ytube_music_player
          command: do_not_ignore_paused_on_media_change

Example automation to play the OwnTone server stream on Sonos speakers:

alias: Play OwnTone stream on Sonos
mode: single
trigger:
  - platform: state
    entity_id:
      - media_player.owntone_server
    to: playing
action:
  - service: media_player.play_media
    data:
      media_content_type: music
      media_content_id: http://[server IP]:3689/stream.mp3
    target:
      entity_id: media_player.sonos

Auto Advance

When playing a playlist / album / radio the natural expectation is to play the next track once the last has finished. Ytube_music_player can't offload this task to the remote_player (the one that actually plays the music) as most players don't support playlists.

Thus Ytube_music_player has to track the status the remote_player and detect the 'end of track' to start the next track from the list.

Most player I've tested (Chromecast / Google Home / Browser Mod) will transistion from playing to idle. As a result the code of Ytube_music_player will play the next track whenever this state transition happens.

Sadly not all player follow this logic. E.g. MPD based media_player will transition from playing to off at the end of a tack, some sonos speaker will switch to paused. I've added special commands to Ytube_music_player to overcome those issues. This will change the way ytube_music_player will react on state changes. E.g. if the off_is_idle command was sent, ytube_music_player will advance to the next track whenever the remote_player will transition from playing to off. This will enable auto-next-track.

Off is Idle / Paused is idle / Idle is idle

Some media_players like MPD or OwnTone server will transition to off instead of idle at the end of each track as mentioned above. Other media_players like Sonos may transition to paused instead of idle. You can set Ytube_music_player to handle this by performing a service call with command off_is_idle or paused_is_idle.

The drawback is obviously that you can't switch off the playback on the remote_player anymore (meaning the off button of media_player.mpd) because ytube_music_player will understand this as the end of the track. You can of course still shutdown the playback by turning off ytube_music_player.

To reset this behavior and only start a next song when an actual transition to idle is detected, send the command idle_is_idle.

If you will only use e.g. MPD as target player, you can do this during startup of homeassistant using this automation from @lightzhuk in your configuration:

- alias: mpd_fix
  initial_state: true
  trigger:
    - platform: homeassistant
      event: start
  action:
    - delay: 00:00:12
    - service: ytube_music_player.call_method
      entity_id: media_player.ytube_music_player
      data:
        command: off_is_idle

Or you can add an automation triggered on the select.ytube_music_player_speaker entity to set this behavior depending on the selected target:

alias: Set YT Music player auto advance detection according to selected speakers
mode: single
trigger:
  - platform: state
    entity_id:
      - select.ytube_music_player_speaker
    from: null
    to: null
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: select.ytube_music_player_speaker
                state: Mpd
              - condition: state
                entity_id: select.ytube_music_player_speaker
                state: OwnTone server                
        sequence:
          - service: ytube_music_player.call_method
            data:
              entity_id: media_player.ytube_music_player
              command: off_is_idle
      - conditions:
          - condition: state
            entity_id: select.ytube_music_player_speaker
            state: Sonos
        sequence:
          - service: ytube_music_player.call_method
            data:
              entity_id: media_player.ytube_music_player
              command: paused_is_idle
    default:
      - service: ytube_music_player.call_method
        data:
          entity_id: media_player.ytube_music_player
          command: idle_is_idle

Debug Information

I've added extensive debugging information to the component. So if you hit an error, please see if you can get as many details as possible for the issue by enabling the debug-log-level for the component. This will produce quite a lot extra information in the log (configuration -> logs).

There are two ways to enable the debug output (as of 20210303):

1. Reroute debug output to error via service

  • Open Developer tools
  • open service tab
  • call service below
service: ytube_music_player.call_method
data:
  entity_id: media_player.ytube_music_player <-- replace this with your player 
  command: debug_as_error
  parameters: [0]

This will instantly post all messages as errors until you reboot homeassistant: Debug as error

2. Let Homeassistant show debug information

  • edit the configuration.yaml and add the logger section
  • Please keep in mind that a restart of Homeassistant is needed to apply this change.
logger:
  default: info
  logs:
    custom_components.ytube_music_player: debug

Multiple accounts

Not yet tested, but should work in general. Please create two entities via the Config_flow and use different paths for the header file

FAQ

  • [Q] Where are the input_select fields?
    [A] After Version 20240420.02,You can find the options in advanced settings to choose the select entities you want to use,they will be automatically added to Home Assistant.
    Existing users can continue using the original input_select(s) which are created by the yaml.If you want to use the new select(s), follow these steps:
    1.) Setting the IDs of the original inputs to a blank space character will permanently delete this field.
    2.) Use checkboxes in the advance configuration to choose the new select entities you want to use.
    3.) If everything is working correctly(after adjusting your dashboard and automations), delete the YAML file used to create the old input entities.

  • [Q] Where can I find the ID for e.g. a playlist?
    [A] simply start the playlist / album / track via the media_browser. Once the music is playing open the developer tools -> states and search for your media_player.ytube_music_player. Note the _media_type and the _media_id and use them for your service calls / shortcuts

  • [Q] I get 'malformed used input' what should I do?
    [A] I can't really explain what happens here, but simply remove the integration (on the integration page, no need to remove it via HACS) and set it up once more.

  • [Q] What is legacy radio?
    [A] YouTube Music offers differnt ways to play a radio. The 'legacy' version would choose a random track from that playlist and create a radio based on that single track. The 'non legacy' version will be based on the complete playlist. At least for me the 'legacy' way offers more variaty, the 'non legacy' is mostly the same list.

  • [Q] What is Shuffle vs Random vs Shuffle Random
    [A] Once shuffle is enabled you can choose the method:
    1.) Shuffle will shuffle the playlist on generation and the play straight 1,2,3,..., this is the default
    2.) Random will NOT shuffle the playlist on generation but pick the tracks randomly, repeats can happen
    3.) Shuffle Random will shuffle the playlist on generation and pick the next random, repeats can happen
    You can change the mode when you add the select.ytube_music_player_play_mode

  • [Q] Can I search for items
    [A] yes, please have a look at this little clip https://youtu.be/6pQJa0tvVMQ
    basically call the service ytube_music_player.search and open the media_browser after that. There should be a new item that contains the results

  • [Q] Why is my playlist limited to 25 entries
    [A] This is the default number that this integration will load. You can change this number via the configuration menu: "configuration" -> "integration" -> "ytube_music_player" -> "configure" -> "Show advance configuration" -> "Limit of simultaniously loaded tracks". Raising that number will increase loading time slightly. Please also make sure that didn't define a lower "limit_count" (see service section)

Credits

This is based on the gmusic mediaplayer of tprelog (https://github.com/tprelog/HomeAssistant-gmusic_player), ytmusicapi (https://github.com/sigma67/ytmusicapi) and pytube (https://github.com/nficano/pytube). This project is not supported nor endorsed by Google. Its aim is not the abuse of the service but the one to improve the access to it. The maintainers are not responsible for misuse.

ytube_music_player's People

Contributors

apxubatop avatar chmielad avatar denvers avatar drulikar avatar felixfischer avatar koljawindeler avatar leandroissa avatar lukaszp2 avatar mang1985 avatar mrueg avatar nemesis24 avatar pathofleastresistor avatar robinr1 avatar simonmannsfeld avatar stboch avatar tprelog avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ytube_music_player's Issues

cookie issue on latest release 20200110

Hello,
the integration fails to set up via the config flow, due to cookie error (on v. 20200110).
Error says 'Something with your cookie wasn't right. Format and fields are ok but the login failed'.

Previous version worked fine.
Tried different browsers, different PCs and log out - log in.

Raising this issue to see if it is something wrong with my cookie or a more general problem.

Thanks for your work.

Support other mediaplayer

Currently cast devices work fine (but will log an error) many other devices aren't working. This could be due to the very long url or something completely different .. might be worth to look into

Playlists & Media Library won't load - Errors in log

Hello,

I just updated to the newest version, 20201229, and am able to see the music player. However it's not loading any of my playlists. Also when browsing media all the folder are empty and when I click on one it pops up saying "Media Browsing Error - unknown error". Below are my logs.

2020-12-29 08:24:48 ERROR (SyncWorker_5) [custom_components.ytube_music_player.media_player] Traceback (most recent call last): File "/config/custom_components/ytube_music_player/media_player.py", line 608, in _update_playlists self._playlists = self._api.get_library_playlists(limit = 99) File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 32, in get_library_playlists playlists = parse_content_list(results['items'][1:], parse_playlist) File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/browsing.py", line 165, in parse_content_list contents.append(parse_func(result['musicTwoRowItemRenderer'])) File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/browsing.py", line 202, in parse_playlist 'title': nav(data, TITLE_TEXT), File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 167, in nav raise err File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 161, in nav root = root[k] KeyError: 'runs' 2020-12-29 08:24:48 ERROR (SyncWorker_5) [custom_components.ytube_music_player.media_player] thanks, Kolja 2020-12-29 08:24:48 ERROR (SyncWorker_5) [custom_components.ytube_music_player.media_player] ============= ytube_music_player Integration Error ================ 2020-12-29 08:25:14 ERROR (Thread-10) [homeassistant.components.cast.media_player] Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address 2020-12-29 08:25:15 ERROR (SyncWorker_3) [custom_components.ytube_music_player.media_player] playlists empty 2020-12-29 08:25:15 ERROR (SyncWorker_3) [custom_components.ytube_music_player.media_player] playlists empty 2020-12-29 08:25:15 ERROR (SyncWorker_3) [custom_components.ytube_music_player.media_player] Out of range! Number of tracks in track_queue == (0) 2020-12-29 08:25:21 ERROR (SyncWorker_1) [custom_components.ytube_music_player.media_player] playlists empty 2020-12-29 08:25:21 WARNING (SyncWorker_3) [pychromecast.controllers] STOP command requested but no session is active. 2020-12-29 08:25:21 ERROR (SyncWorker_1) [custom_components.ytube_music_player.media_player] playlists empty 2020-12-29 08:25:21 ERROR (SyncWorker_1) [custom_components.ytube_music_player.media_player] Out of range! Number of tracks in track_queue == (0) 2020-12-29 08:25:21 WARNING (SyncWorker_0) [pychromecast.controllers] STOP command requested but no session is active. 2020-12-29 08:25:21 WARNING (SyncWorker_5) [pychromecast.controllers] STOP command requested but no session is active. 2020-12-29 08:25:26 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139687220588752] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 18, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1066, in websocket_browse_media payload = await player.async_browse_media(media_content_type, media_content_id) File "/config/custom_components/ytube_music_player/media_player.py", line 1172, in async_browse_media response = await build_item_response(self.hass, self._api, payload) File "/config/custom_components/ytube_music_player/browse_media.py", line 58, in build_item_response media = await hass.async_add_executor_job(media_library.get_library_playlists,BROWSER_LIMIT) AttributeError: 'NoneType' object has no attribute 'get_library_playlists'

Song progression when speaker is a chromecast?

Hi,

thank you for your excellent work, it's truly awesome!

I might simply be dumb, but I haven't find how to show the progression of the currently playing song when speaker is a chrome cast device. Is it expected behaviour or have I did something wrong?

EDIT : using the media-mini-player from kalkih.

Thanks!

Cannot find the repo in HACS

as above trying to install via HACS, but cannot find it. when I search nothing comes back. I am new to HA. Thanks in advance

media_player.turn_off results in "AttributeError: 'list' object has no attribute 'lower'"

I'm not sure when this started, but when I call the 'media_player.turn_off' service with 'media_player.ytube_music_player', I get the following in my log file:

2020-12-29 00:12:18 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139751139782368] 'list' object has no attribute 'lower'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 558, in async_turn_off
    await self.hass.async_add_executor_job(self.turn_off)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ytube_music_player/media_player.py", line 319, in turn_off
    _player = self.hass.states.get(self._remote_player)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1048, in get
    return self._states.get(entity_id.lower())
AttributeError: 'list' object has no attribute 'lower'

I believe it's because hass.states.get() is expecting a single entity_id and it's being passed a list of entity_ids.

hi there is a issue with intergration

hi i am having a issue where my one keeps i select a playlist and forever keeps looping on the loading then cancels forever i dont know how to fix and would greatly appricate some help

Thanks

ghost

ValueError: invalid literal for int() with base 10: '1,224'

2020-12-16 20:55:11 ERROR (SyncWorker_4) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
File "/config/custom_components/ytube_music_player/media_player.py", line 407, in _update_playlists
extra_info = self._api.get_playlist(playlistId=playlist['playlistId'])
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/playlists.py", line 91, in get_playlist
song_count = to_int(
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/helpers.py", line 71, in to_int
return locale.atoi(number)
File "/usr/local/lib/python3.8/locale.py", line 330, in atoi
return int(delocalize(string))
ValueError: invalid literal for int() with base 10: '1,224'
2020-12-16 20:55:11 ERROR (SyncWorker_4) [custom_components.ytube_music_player.media_player]
thanks, Kolja
2020-12-16 20:55:11 ERROR (SyncWorker_4) [custom_components.ytube_music_player.media_player] ============= ytube_music_player Integration Error ================

[Request] - Custom Card

Hello

I've set up your integration today and it does work! Great work!

I've noticed though with my current setup I'm using the following card - https://github.com/kalkih/mini-media-player
And there are some issues which may be improved by having your own custom card

For example, switching what speaker it plays too with the input select doesn't change unless the power is switched off and then back on which loses the current song

It would be really cool (if possible of course) to have the following card

image

But have the input selects integrated into the actual media player card as buttons where then the functionality can be applied

No module named 'integrationhelper'

Hi, i'm trying to add new integration with config flow in HA and i'm getting this error, any idea what (if anything) i'm doing wrong?

Logger: homeassistant.config_entries
Source: config_entries.py:537
First occurred: 18:51:14 (2 occurrences)
Last logged: 19:00:55

Error occurred loading configuration flow for integration ytube_music_player: No module named 'integrationhelper'

Stop after every track

Enable DEBUG Output
Logger: custom_components.ytube_music_player.media_player
Source: custom_components/ytube_music_player/media_player.py:306
Integration: YouTube Music Player (documentation, issues)
First occurred: 17:05:39 (1 occurrences)
Last logged: 17:05:39

self._state is: (playing).

Describe the bug
Traceback (most recent call last):
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/ytube_music_player/media_player.py", line 433, in _sync_player
if _player.state == 'playing' and _player.attributes['media_position']>0:
TypeError: '>' not supported between instances of 'str' and 'int'

Version
20210106

Additional context
Stop after each track. If I switch the track to manual then I hear the next one. But when playing after each track, stop. I'm using speakers connected to the pi. media player mpd addon. Thank you.

Thanks

Service end point for reload speaker list and albums

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Call service to refresh drop downs

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

HA detected I/O inside the event loop

Enable DEBUG Output
Please see: https://github.com/KoljaWindeler/ytube_music_player/#debug-information

Describe the bug
A clear and concise description of what the bug is, ideally a homeassistant log with debug enabled

Two Log entries from HA asking me to send them to you.

Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for ytube_music_player doing I/O at custom_components/ytube_music_player/const.py, line 245: api = YTMusic(user_input[CONF_HEADER_PATH])
Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for ytube_music_player doing I/O at custom_components/ytube_music_player/const.py, line 246: api.get_library_songs()

Version
please provide the version you are using (see HACS)
20200110

To Reproduce
Steps to reproduce the behavior:
Just start HA with the addin installed. (Used the new way btw aka removed all remnants of the former way from configuration.yaml and cleanly reinstalled it)

Additional context
Add any other context about the problem here.

Thanks

Player wouldnt turn on.

Hi,
Im getting following error last couple of days without changing much in the config and the player would not turno on.
Previously it worked just fine.

Logger: custom_components.ytube_music_player.media_player
Source: custom_components/ytube_music_player/media_player.py:857
Integration: YouTube Music Player (documentation)
First occurred: 8:56:13 (1 occurrences)
Last logged: 8:56:13

Traceback (most recent call last): File "/config/custom_components/ytube_music_player/media_player.py", line 410, in _update_playlists self._playlists = self._api.get_library_playlists(limit = 99) File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 29, in get_library_playlists results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST), File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 148, in nav raise err File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 142, in nav root = root[k] KeyError: 'contents'

When i try to start player im getting this

Logger: custom_components.ytube_music_player.media_player
Source: custom_components/ytube_music_player/media_player.py:221
Integration: YouTube Music Player (documentation)
First occurred: 9:23:56 (19 occurrences)
Last logged: 15:00:40

Can't start the player, no header file

Im on latest version but this issue was discovered on the previous version of the component

Add support for MediaSource

Hi,
The work you've done is great and I'm looking forward to it being developed further.
One thing that I think would be very useful is to add MediaSource support, so one could browse YouTube music from a side panel or - even better - from any player which supports MediaSource (currently Chromecasts). The rationale behind is that one doesn't have to add another entity to the UI to browse files. For instance I'd love to be able to pick a YouTube music playlist directly from my Chromecast entity in the UI. That's what Media Source is all about.

I mean this thing here: https://github.com/home-assistant/core/tree/dev/homeassistant/components/media_source

Looks like Xbox and Netatmo integration added it so far, so not too many examples, but still something to explore.

Keep on doing the great work!

Buy you a coffee or beer

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I really like what you're doing here. I appreciate all the work you have already done and I'm looking forward to some of the future improvements you have mentioned in the forum. I know this is a lot of work and I want to help, however I am unable to contribute quality code so I would like to have another way I can contribute.

Describe the solution you'd like
A clear and concise description of what you want to happen.

I would like a link to buy you a coffee or something similar

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Becoming GitHub sponsor

Additional context
Add any other context or screenshots about the feature request here.

NA

Error on boot

Can you pls check why I am receiving this error:

Logger: homeassistant.components.media_player
Source: custom_components/ytube_music_player/media_player.py:74
Integration: Media player (documentation, issues)
First occurred: 8:57:39 PM (1 occurrences)
Last logged: 8:57:39 PM

Error while setting up ytube_music_player platform for media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_

platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ytube_music_player/media_player.py", line 43, in setup_platform
    add_entities([yTubeMusicComponent(hass, config)], True)
  File "/config/custom_components/ytube_music_player/media_player.py", line 74, in __init__
    self._api = YTMusic(config.get(CONF_HEADER_PATH, default_header_file))
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 96, in __init__
    self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/helpers.py", line 57, in sapisid_from_cookie
    return cookie['__Secure-3PAPISID'].value
KeyError: '__Secure-3PAPISID'

System Health

version 1.0.0b0
installation_type Home Assistant OS
dev false
hassio true
docker true
virtualenv false
python_version 3.8.6
os_name Linux
os_version 5.4.81
arch x86_64
timezone Europe/Brussels
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Hass.io
host_os HassOS 4.19
update_channel beta
supervisor_version 2020.12.4
docker_version 19.03.12
disk_total 19.0 GB
disk_used 10.6 GB
healthy true
supported true
board ova
supervisor_api ok
version_api ok
installed_addons Terminal & SSH (8.6.0), AppDaemon 4 (0.3.2), WireGuard (0.4.0), Mosquitto broker (5.1), Home Assistant Google Drive Backup (0.102.0), SSH & Web Terminal (7.8.0), Visual Studio Code (2.9.1), API Consumer (0.101), Check Home Assistant configuration (3.6.0), TasmoBackup (1.04.02), chrony (1.1.2), JupyterLab Lite (0.3.1)
Lovelace
dashboards 2
mode storage
views 18
resources 27

Playlists not coming through, also clarification on usage

Enable DEBUG Output
Please see: https://github.com/KoljaWindeler/ytube_music_player/#debug-information

Describe the bug
A clear and concise description of what the bug is, ideally a homeassistant log with debug enabled

Great work on this, thank you very much. I have playlists in youtube music that aren't coming through either to the media browser or the input_select.

Version
please provide the version you are using (see HACS) latest from HACS

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

I've added some playlists, and can play them from ytube fine if I specify the id, but I can't see them in homeassistant.

image

Only 'Your Likes' is available.

image

Additional context
Add any other context about the problem here.

Thanks

Error with version 20201221

Hi. Just updated to the new version via HACS. (20201221) The following error shows up in the logs. I've tried to regenerate the header file but did not fix it.

2020-12-21 18:35:28 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.ytube_music_player
2020-12-21 18:35:28 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.ytube_music_player
2020-12-21 18:35:28 INFO (MainThread) [homeassistant.setup] Setup of domain scene took 3.6 seconds
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player]
============= ytube_music_player Integration Error ================
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player] unfortunately we hit an error in the sub api, please open a ticket at
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player] https://github.com/sigma67/ytmusicapi/issues
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player] and paste the following output:
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
File "/config/custom_components/ytube_music_player/media_player.py", line 91, in __init__
self._api = ytmusicapi.YTMusic(config.get(CONF_HEADER_PATH, default_header_file))
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 96, in __init__
self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/helpers.py", line 57, in sapisid_from_cookie
return cookie['__Secure-3PAPISID'].value
KeyError: '__Secure-3PAPISID'
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player]
thanks, Kolja
2020-12-21 18:35:28 ERROR (SyncWorker_19) [custom_components.ytube_music_player.media_player] ============= ytube_music_player Integration Error ================

Thanks

Log File Error

Enable DEBUG Output
Please see: https://github.com/KoljaWindeler/ytube_music_player/#debug-information

Describe the bug

I installed the integration, added the cookie, and the full_control yaml view in the packages folder. The playlists do not seem to load and the following error shows up in the log.

2021-01-10 22:07:35 ERROR (SyncWorker_0) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
File "/config/custom_components/ytube_music_player/media_player.py", line 705, in _update_playlists
self._playlists = self._api.get_library_playlists(limit = 99)
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 39, in get_library_playlists
get_continuations(results, 'gridContinuation', limit - len(playlists),
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 86, in get_continuations
contents = get_continuation_contents(results, parse_func)
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 129, in get_continuation_contents
return parse_func(continuation[term])
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 37, in
parse_func = lambda contents: parse_content_list(contents, parse_playlist)
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/browsing.py", line 165, in parse_content_list
contents.append(parse_func(result['musicTwoRowItemRenderer']))
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/browsing.py", line 202, in parse_playlist
'title': nav(data, TITLE_TEXT),
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 167, in nav
raise err
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 161, in nav
root = root[k]
KeyError: 'runs'

2021-01-10 22:07:35 ERROR (SyncWorker_0) [custom_components.ytube_music_player.media_player]

Version
20200110

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Additional context
Add any other context about the problem here.

Thanks

Unable to play from playlist

Can't seem to get the player to work after I redid my playlists on Youtube Music. Now it just errors when I try to cast to my speaker group.

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/ytube_music_player/media_player.py:691
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 1:14:16 AM (1 occurrences)
Last logged: 1:14:16 AM

[548279126960] object of type 'NoneType' has no len()
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 748, in async_toggle
    await self.async_turn_on()
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 550, in async_turn_on
    await self.hass.async_add_executor_job(self.turn_on)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ytube_music_player/media_player.py", line 280, in turn_on
    self._play()
  File "/config/custom_components/ytube_music_player/media_player.py", line 680, in _play
    self._get_track()
  File "/config/custom_components/ytube_music_player/media_player.py", line 691, in _get_track
    _LOGGER.debug("Playing track nr "+str(self._next_track_no)+" / "+str(len(self._tracks)))
TypeError: object of type 'NoneType' has no len()

I can not see the media_player entity in lovelace

Information:
Home Assistant 2020.12.1
Home Assistant OS 5.9
Supervisor | 2020.12.7

Steps:

  1. Add repository in HACS
  2. Open Configuration -> Integrations -> "add integration" -> "YouTube Music Player"
  3. Paste the cookie into the indicated field
    3.1 Extract cookie youtube music and paste the following text in the installation HACS.

Captura de pantalla 2020-12-28 a las 11 37 59

accept-language: es-ES,es;q=0.9,en;q=0.8,th;q=0.7,pt;q=0.6
authorization: SAPISIDHASH <STRING>
content-length: 967
content-type: application/json
cookie: VISITOR_INFO1_LIVE<STRING>
origin: https://music.youtube.com
referer: https://music.youtube.com/
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36
x-client-data: CI<STRING>
Decoded:
message ClientVariations {
  // Active client experiment variation IDs.
  repeated int32 variation_id = [3300106, 3300133, 3300164, 3313321, 3318700, 3318774, 3319460, 3320540, 3329132, 3329546, 3329602];
}
x-goog-authuser: 0
x-goog-visitor-id: CgtzaWFyTEROM3RhSSid36b_BQ%3D%3D
x-origin: https://music.youtube.com
x-youtube-ad-signals: dt=1609<STRING>
x-youtube-client-name: 67
x-youtube-client-version: 0.1
x-youtube-device: cbr=Chrome+Mobile&cbrand=google&cbrver=<STRING>
x-youtube-identity-token: <STRING>
x-youtube-page-cl: <STRING>
x-youtube-page-label: youtube.music.web.client_<STRING>
x-youtube-time-zone: Atlantic/Canary
x-youtube-utc-offset: 0
  1. Restart Hassio

  2. Copy the entity definition in configuration.yaml

media_player:
  - platform: ytube_music_player
    speakers:
      - cuarto_de_estar
      - en_toda_la_casa
      - mibox3
  1. Restart HAssio

  2. Now, I want to add the media_player entity in lovelace, but I don't see the entity.

  3. Go to Home assistsnat Logs

Captura de pantalla 2020-12-28 a las 11 31 53

Can you help me?

Add support for Adding Playlists and songs to MediaBrowser

Similar to Spotify App,
Add Contents of Playlists to MediaBrowser HA component...

*** things of note ***
Existing known issue would be the length the URL is vaild for and needing to refresh the content if we can't get the url when a song is requested.
Limits on enumerating all playlists and songs in those playlists. (Other people have described issues with this) These actions would also further the need to ensure these tasks are using asyncio.)

Input field for playmode

Add input field for shuffle/random mode. So the user CAN change the playmode without rebooting

Playlist with training space cannot be played

I discovered that one of my playlists would not work. Took me a bit to discover that the playlist name had a trailing space. "Christmas " instead of "Christmas". While it would show in the input select, you could not choose it.
I was able to work around the problem by removing the space in the playlist name, but you might want to account for this possible issue in code.

Several bugs in logs

Hi, i am having several bugs in logs, already tried to update my cookies, it was working properly, last week.

image

image

Add support for brand accounts

I reinstalled ytube_music_player but I get the same error.

Logger: homeassistant
Source: custom_components/ytube_music_player/media_player.py:387
First occurred: 19:07:51 (1 occurrences)
Last logged: 19:07:51

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ytube_music_player/media_player.py", line 356, in _update_sources
    self._update_playlists()
  File "/config/custom_components/ytube_music_player/media_player.py", line 387, in _update_playlists
    self._playlists = self._api.get_library_playlists(limit = 99)
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 29, in get_library_playlists
    results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 148, in nav
    raise err
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 142, in nav
    root = root[k]
KeyError: 'contents'

Sonos intergration?

Hi! I wonder if it’s able to play the music through Sonos speaker? I have the options to choose my sonos speakers and it starts to play but there is no sound coming out of the speaker.
Is this just compatibility issue or should I be able to play music through my Sonos speaker? Google devices works great to play music through.

get_playlist playlist KeyError: 'contents'

`Logger: custom_components.ytube_music_player.media_player
Source: custom_components/ytube_music_player/media_player.py:811
Integration: YouTube Music Player (documentation)
First occurred: 22:06:27 (1 occurrences)
Last logged: 22:06:27

Traceback (most recent call last): File "/config/custom_components/ytube_music_player/media_player.py", line 406, in _update_playlists extra_info = self._api.get_playlist(playlistId=playlist['playlistId']) File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/playlists.py", line 100, in get_playlist playlist['tracks'].extend(parse_playlist_items(results['contents'])) KeyError: 'contents'`

Seems like everything is set up correctly

  • HACS install worked normally
  • grabbed cookie and all seems to be fine with the configflow
  • config.yaml entered correctly
  • Seeing speakers and input selects in the ytube entities that were created
  • Im able to turn the ytube media player on and it speaks to my devices
  • input_select.ytube_music_player_playlist is borked and stuck on "loading"

Any ideas?

Long term - Multiple Accounts

I don't believe this is currently a feature of the solution, but I'd like to have multiple accounts. This could be multiple ytube music player instances... or whatever.

The use case is simple: she has a Nest mini in an area, I have a separate one elsewhere. We each have our own ytm accounts. I'd love to be able to play music for her with HA. I want that for me, too. Different music preferences, playlists, etc.

I know this won't be the near-term goal of the project, but if it can be part of a later version, I'd be a BIG fan.

Autoload all Mediaplayer

Try to get ALL Mediaplayer and autofill the list with them
If one mediaplayer is provided as configuration: preselect this one on load

Also add this option to the config flow

Reminder: Proxy setting to config flow

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Play continuous setting not initialised when HA starts

DEBUG Output after HA restart

2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _sync_player
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] media_player.chromecast: playing -> idle
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _get_track
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] - Playing track nr 1 / 1
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] play_media, media_type: track, media_id: 2yIGIQb9gSk
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] prepare_play
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] check_api
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _update_remote_player
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] media_stop
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] - media_stop -> media_player.chromecast
2021-01-20 19:23:56 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _get_cipher
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _tracks_to_attribute
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _play
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] _get_track
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] - Playing track nr 0 / 1
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] get_url
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] check_api
2021-01-20 19:23:59 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] - try to find URL on our own
2021-01-20 19:24:00 DEBUG (SyncWorker_3) [custom_components.ytube_music_player.media_player] - self decoded URL via cipher
2021-01-20 19:24:00 INFO (SyncWorker_7) [pychromecast.controllers] Not launching app CC1AD846 - already running
2021-01-20 19:24:00 DEBUG (SyncWorker_8) [custom_components.ytube_music_player.media_player] _sync_player
2021-01-20 19:24:00 DEBUG (SyncWorker_8) [custom_components.ytube_music_player.media_player] media_player.chromecast: idle -> idle
2021-01-20 19:24:01 DEBUG (SyncWorker_4) [custom_components.ytube_music_player.media_player] _sync_player
2021-01-20 19:24:01 DEBUG (SyncWorker_4) [custom_components.ytube_music_player.media_player] media_player.chromecast: idle -> playing
2021-01-20 19:24:02 DEBUG (SyncWorker_14) [custom_components.ytube_music_player.media_player] _sync_player
2021-01-20 19:24:02 DEBUG (SyncWorker_14) [custom_components.ytube_music_player.media_player] media_player.chromecast: playing -> playing
2021-01-20 19:24:16 DEBUG (SyncWorker_12) [custom_components.ytube_music_player.media_player] _sync_player
2021-01-20 19:24:16 DEBUG (SyncWorker_12) [custom_components.ytube_music_player.media_player] media_player.chromecast

DEBUG Output after set input_boolean.ytube_music_player_playcontinuous to ON and OFF again

2021-01-20 19:09:55 DEBUG (SyncWorker_11) [custom_components.ytube_music_player.media_player] _sync_player
2021-01-20 19:09:55 DEBUG (SyncWorker_11) [custom_components.ytube_music_player.media_player] media_player.chromecast: playing -> idle
2021-01-20 19:09:55 DEBUG (SyncWorker_11) [custom_components.ytube_music_player.media_player] _get_track
2021-01-20 19:09:55 DEBUG (SyncWorker_11) [custom_components.ytube_music_player.media_player] - Playing track nr 1 / 1
2021-01-20 19:09:55 INFO (SyncWorker_11) [custom_components.ytube_music_player.media_player] - End of playlist and playcontinuous is off
2021-01-20 19:09:55 DEBUG (SyncWorker_11) [custom_components.ytube_music_player.media_player] _turn_off_media_player

Describe the bug
Even though having the input_boolean ytube_music_player_playcontinuous to false, after HA restart, it does not take the input_boolean state.

Version
ytube_music_player 20210118
HA 2021.1.3

To Reproduce

  1. Set the input_boolean to false
  2. Restart HA
  3. Call service to play single track:
- service: media_player.play_media
    data:
      entity_id: media_player.ytube_music_player
      media_content_id: BzsrqaLgdpk
      media_content_type: track
  1. It never stops playing...

Thanks

Uploads of music in YouTube music unavailable via YouTube api

The existing method to get youtube urls only works from music released via YouTube Music. Music uploaded via the music app return as unplayable on the YouTube site.

@KoljaWindeler at first pass looked at seeing if I could change the url to the music.youtube site instead of just YouTube while the js base is the same the regex used to find the cipher code might need to be adjusted to this new site. Was going to do more debugging and digging and see if I can get it working

input_select playlist not populating

DEBUG Output

Logger: custom_components.ytube_music_player.media_player
Source: custom_components/ytube_music_player/media_player.py:688
Integration: YouTube Music Player (documentation, issues)
First occurred: 13:40:52 (1 occurrences)
Last logged: 13:40:52

playlists empty

Describe the bug
Got your integration to work fine, it's playing my playlist when I hardcode it into the custom media player card.
However when opening the playlists folder in the media browser the folder is empty.
Also the input_select playlist stays on 'No playlists found'.
Tried multiple restarts, but the list and the media browser stay empty.

Version
Latest (20210102)

Problem with integration

What I can get working: setting everything up, and pressing power on or play to play a random song.

Where I'm stuck: trying to use Mini Media Player to set up shortcut buttons to play specific channels or playlists. I get the below error when pressing on such a button.

- name: Name
  type: channel
  id: UCUJ3KuIIgvh8eVItvb-EdFQ

(For this https://music.youtube.com/channel/UCUJ3KuIIgvh8eVItvb-EdFQ)

See error log below.

Logger: custom_components.ytube_music_player.media_player
Source: custom_components/ytube_music_player/media_player.py:1171
Integration: YouTube Music Player (documentation, issues)
First occurred: 1:08:18 PM (1 occurrences)
Last logged: 1:08:18 PM

Traceback (most recent call last): File "/config/custom_components/ytube_music_player/media_player.py", line 984, in play_media self._tracks = self._api.get_playlist(playlistId=media_id)['tracks'] File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/playlists.py", line 66, in get_playlist results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)[0]['musicPlaylistShelfRenderer'] File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 167, in nav raise err File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 161, in nav root = root[k] KeyError: 'contents'

Just got these errors

============= ytube_music_player Integration Error ================
2021-01-03 11:04:46 ERROR (SyncWorker_2) [custom_components.ytube_music_player.media_player] unfortunately we hit an error in the sub api, please open a ticket at
2021-01-03 11:04:46 ERROR (SyncWorker_2) [custom_components.ytube_music_player.media_player] https://github.com/sigma67/ytmusicapi/issues
2021-01-03 11:04:46 ERROR (SyncWorker_2) [custom_components.ytube_music_player.media_player] and paste the following output:

2021-01-03 11:04:46 ERROR (SyncWorker_2) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
File "/config/custom_components/ytube_music_player/media_player.py", line 133, in check_api
self._api = ytmusicapi.YTMusic(self._header_file)
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 96, in init
self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/helpers.py", line 57, in sapisid_from_cookie
return cookie['__Secure-3PAPISID'].value
KeyError: '__Secure-3PAPISID'

2021-01-03 11:04:46 ERROR (SyncWorker_2) [custom_components.ytube_music_player.media_player]
thanks, Kolja
2021-01-03 11:04:46 ERROR (SyncWorker_2) [custom_components.ytube_music_player.media_player] ============= ytube_music_player Integration Error ================

Thanks

Do you want me to add GitHub actions?

If you want, I can add some advanced CI to your repo in a PR. Let me know if you want that.

  • Do you want to enable auto-formatting?
  • Do you want packaged or independent (I recommend packaged because I can send updates)?

Integration not showing up

Hi,

The integration never shows up for me under Configuration -> Integrations -> Add Integration. I have tried several different browsers, cleared the browser cache, restarted HA all to no avail.

Any ideas?

Thanks,

Mark

Error: Cookie wasn't right while setting up integration.

Enable DEBUG Output
Please see: https://github.com/KoljaWindeler/ytube_music_player/#debug-information

Describe the bug
A clear and concise description of what the bug is, ideally a homeassistant log with debug enabled

Version
please provide the version you are using (see HACS)

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Open Configuration -> Integrations -> "add integration" -> "YouTube Music Player".'
  2. Paste Cookie
  3. Click on 'Submit'
  4. See error
    Something with your cookie wasn't right. Format and fields are ok but the login failed
    Additional context
    Something with your cookie wasn't right. Format and fields are ok but the login failed

I am using Google 2 factor authentication

Thanks

Component not working

============= ytube_music_player Integration Error ================
2021-01-07 15:30:32 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] unfortunately we hit an error in the sub api, please open a ticket at
2021-01-07 15:30:32 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] https://github.com/sigma67/ytmusicapi/issues
2021-01-07 15:30:32 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] and paste the following output:

2021-01-07 15:30:32 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
File "/config/custom_components/ytube_music_player/media_player.py", line 143, in check_api
self._api = ytmusicapi.YTMusic(self._header_file)
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 96, in init
self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
File "/usr/local/lib/python3.8/site-packages/ytmusicapi/helpers.py", line 57, in sapisid_from_cookie
return cookie['__Secure-3PAPISID'].value
KeyError: '__Secure-3PAPISID'

2021-01-07 15:30:32 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player]
thanks, Kolja
2021-01-07 15:30:32 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] ============= ytube_music_player Integration Error ================

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.