music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.32k stars 49 forks source link

BBC Radio stops intermittently #2715

Closed awesomeruss closed 1 month ago

awesomeruss commented 2 months ago

What version of Music Assistant has the issue?

2.2.0b2

What version of the Home Assistant Integration have you got installed?

2024.6.2

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

Listening to BBC Radio 6 from Radiobrowser. It starts up and works just fine for a while (anywhere from 5min to >1hr, but commonly less than 2hr), then it stops without warning. Radio X seems fine.

How to reproduce

Listen to the same radio station - see log for url

Music Providers

Problem occurs with radiobrowser

Player Providers

I'm running a bluetooth speaker through squeezelite

Full log output

Default log here (debug and verbose lines removed, as requested) music-assistant.log

The same log file with debug and verbose lines included, which may give more insight into the problem. music-assistant.log This is the most relevant bit, full log attached: 2024-08-02 12:53:22.124 VERBOSE (MainThread) [music_assistant.streams.media_stream] [http @ 0x559cab908800] Opening 'http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d320000.norewind.m3u8' for reading 2024-08-02 12:53:22.148 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#EXT-X-VERSION:3') 2024-08-02 12:53:22.148 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('## Created with Unified Streaming Platform(version=1.8.4)') 2024-08-02 12:53:22.149 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#EXT-X-INDEPENDENT-SEGMENTS') 2024-08-02 12:53:22.149 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#USP-X-TIMESTAMP-MAP:MPEGTS=3148807584,LOCAL=2024-08-02T12:53:13.600000Z') 2024-08-02 12:53:22.149 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#EXT-X-PROGRAM-DATE-TIME:2024-08-02T12:53:13.600000Z') 2024-08-02 12:53:28.559 VERBOSE (MainThread) [music_assistant.streams.media_stream] [http @ 0x559cab908800] Opening 'http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d320000.norewind.m3u8' for reading 2024-08-02 12:53:28.580 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#EXT-X-VERSION:3') 2024-08-02 12:53:28.581 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('## Created with Unified Streaming Platform(version=1.8.4)') 2024-08-02 12:53:28.581 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#EXT-X-INDEPENDENT-SEGMENTS') 2024-08-02 12:53:28.581 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#USP-X-TIMESTAMP-MAP:MPEGTS=3149959584,LOCAL=2024-08-02T12:53:26.400000Z') 2024-08-02 12:53:28.581 VERBOSE (MainThread) [music_assistant.streams.media_stream] [hls @ 0x559cab900880] Skip ('#EXT-X-PROGRAM-DATE-TIME:2024-08-02T12:53:26.400000Z') 2024-08-02 12:53:28.581 VERBOSE (MainThread) [music_assistant.streams.media_stream] [http @ 0x559cab92e300] Opening 'http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_6music/bbc_6music.isml/bbc_6music-audio=320000-269156755.ts' for reading 2024-08-02 12:53:28.605 VERBOSE (MainThread) [music_assistant.streams.media_stream] [http @ 0x559cab9392c0] Opening 'http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_6music/bbc_6music.isml/bbc_6music-audio=320000-269156756.ts' for reading 2024-08-02 12:53:28.655 VERBOSE (MainThread) [music_assistant.streams.media_stream] size= 71662kB time=00:06:55.99 bitrate=1411.2kbits/s speed=1.02x 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] video:0kB audio:71662kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000% 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] [Parsed_loudnorm_0 @ 0x559caba08bc0] 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] { 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] "input_i" : "-14.60", 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] "input_tp" : "-4.54", 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] "input_lra" : "3.70", 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] "input_thresh" : "-24.72", 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] "output_i" : "-17.15", 2024-08-02 12:53:28.656 VERBOSE (MainThread) [music_assistant.streams.media_stream] "output_tp" : "-7.09", 2024-08-02 12:53:28.657 VERBOSE (MainThread) [music_assistant.streams.media_stream] "output_lra" : "3.70", 2024-08-02 12:53:28.657 VERBOSE (MainThread) [music_assistant.streams.media_stream] "output_thresh" : "-27.27", 2024-08-02 12:53:28.657 VERBOSE (MainThread) [music_assistant.streams.media_stream] "normalization_type" : "linear", 2024-08-02 12:53:28.657 VERBOSE (MainThread) [music_assistant.streams.media_stream] "target_offset" : "0.15" 2024-08-02 12:53:28.657 VERBOSE (MainThread) [music_assistant.streams.media_stream] } 2024-08-02 12:53:28.663 DEBUG (MainThread) [music_assistant.streams.media_stream] Process ffmpeg with PID 262 stopped with returncode 0 2024-08-02 12:53:28.663 DEBUG (MainThread) [music_assistant.streams.media_stream] stream finished (with code 0) for radiobrowser://radio/5cb4a4cb-c811-43e2-8531-36e13bf48828 - seconds streamed: 416.0 2024-08-02 12:53:28.663 DEBUG (MainThread) [music_assistant.streams.media_stream] Loudness measurement for radiobrowser://radio/5cb4a4cb-c811-43e2-8531-36e13bf48828: LoudnessMeasurement(integrated=-14.6, true_peak=-4.54, lra=3.7, threshold=-24.72, target_offset=0.15) 2024-08-02 12:53:28.664 VERBOSE (MainThread) [music_assistant.audio.ffmpeg] [flac @ 0x55a3c4e82680] unable to rewrite FLAC header. 2024-08-02 12:53:28.664 VERBOSE (MainThread) [music_assistant.audio.ffmpeg] size= 45445kB time=00:06:56.00 bitrate= 894.9kbits/s speed=1.02x 2024-08-02 12:53:28.664 VERBOSE (MainThread) [music_assistant.audio.ffmpeg] video:0kB audio:45437kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.017809% 2024-08-02 12:53:28.668 DEBUG (MainThread) [music_assistant.audio.ffmpeg] Process ffmpeg with PID 261 stopped with returncode 0 2024-08-02 12:53:50.045 INFO (MainThread) [music_assistant.providers.spotify] Attempt 1/5 failed: Spotify Rate Limiter 2024-08-02 12:53:50.045 INFO (MainThread) [music_assistant.providers.spotify] Retrying in 9 seconds... 2024-08-02 12:54:01.347 INFO (MainThread) [music_assistant.providers.spotify] Attempt 1/5 failed: Spotify Rate Limiter 2024-08-02 12:54:01.347 INFO (MainThread) [music_assistant.providers.spotify] Retrying in 28 seconds...

Later in the log file I play RadioX for a while, stop it manually and go back to radio6. I then left the system unattended and did other stuff for a while, and radio6 stopped by itself. Strangely that incident has different (less) log output than above.

I'm using a beelink eq13 running docker on debian to host Home Assistant, Music Assistant, Squeezelite, and other related containers like portainer and nginx.

Additional information

I'm starting the stream from the main MA UI. Local playback and spotify are working just fine with the setup.

What version of Home Assistant Core are your running

2024.7.4

What type of installation are you running?

Home Assistant Container

On what type of hardware are you running?

Linux

OzGav commented 1 month ago

The instructions ask that you not NOT add debug level logs. Please edit your post and include only the default logs.

awesomeruss commented 1 month ago

Sorry - I had missed that instruction and from my own investigation to get this far I thought the additional content in the debug logs would be useful for understanding the cause. I've attached an edited log with the DEBUG and VERBOSE lines removed.

OzGav commented 1 month ago

So is it only BBC stations that have a problem? I’m actually surprised they work at all, most people can’t find a working steam.

awesomeruss commented 1 month ago

Yes - That is my experience so far. If I can't get Radio 2 working reliably then my plan to rip out my google hardware and replace entirely with HASS kit will fail. I love the way MA+HA can integrate virtually any other source of music and play it out to multiple different speakers and then play announcements over the top.

To be honest an ability to automatically try restarting the stream a few times would be enough - a momentary glitch would be tolerable, needing to manually restart is where the user pain is.

awesomeruss commented 1 month ago

I thought it was odd how the verbose logging showed repeated entries for: Opening 'http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d320000.norewind.m3u8' for reading But then somehow the stream url changes to Opening 'http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_6music/bbc_6music.isml/bbc_6music-audio=320000-269156755.ts' for reading

OzGav commented 1 month ago

I’m no expert but maybe it’s getting redirected. Google suggests that working BBC streams are somewhat elusive. I know Marcel has patched some issues in the past. https://github.com/music-assistant/hass-music-assistant/issues?q=is%3Aissue+bbc+is%3Aclosed

If it is only BBC streams then please edit the title to reflect that. This will get looked at when resources allow.

awesomeruss commented 1 month ago

Title updated. It seems there is an open source BBC Sounds client for LMS here. https://github.com/expectingtofly/LMS_BBC_Sounds_Plugin

I've been looking through that code, and it might not be too tricky to implement something similar in MA. It requires the user to have a BBC account and holds the username and password in local config. To sign in it scrapes the BBC login page to determine the signin url, then performs a second http request to sign in with the user's credentials to get a cookie.

After that it seems like a reasonable json api to get the list of stations and podcasts...

OzGav commented 1 month ago

That would be a feature request that you can raise separately or better still raise a PR for.

MelHarbour commented 1 month ago

It's on my list (UK based) to have a look at a BBC Sounds provider at some point, but a bit further down my priorities!

awesomeruss commented 1 month ago

Awesome! I think the only long term way BBC radio streaming could work is if the user has to provide their BBC account credentials. I spent a chunk of time staring at the LMS code that does this, and poking around BBC Sounds itself. Hopefully this is helpful, This is how I think it works:

Signin: Get https://account.bbc.com Rip the signinurl out of the content in the response Add 'https://account.bbc.com' to the front of signinurl add some headers POST using body1 - that contains the username Rip signinurl2 out of the content in the response Add 'https://account.bbc.com' to the front of signinurl2 add some headers POST using body1 - that contains the username and password save the cookie that comes back, use in future JWT requests

Station list: https://rms.api.bbc.co.uk/v2/experience/inline/stations This is freely available, includes station IDs

Playback: Get a JWT from https://rms.api.bbc.co.uk/v2/sign/token/, this request will need the cookie from signin. This needs to be periodically refreshed. Get latest segment from https://rms.api.bbc.co.uk/v2/services/STATION_ID_HERE/segments/latest?limit=1

From that sequence you should get a stream that will work for a while, refresh the JWT to keep it working.

let me know if I can do more - I know http/js pretty well but nothing useful on streaming, MA, or python. I'd be willing to hit codeacademy and learn some python if that would be enough to contribute usefully, but I suspect I'd still be stumbling around breaking things if I tried to touch the MA code.

MelHarbour commented 1 month ago

Yeah, the sequence should be fairly straightforward I think. I just need to have enough time to go work on implementing something. Happy to have others involved and happy to help someone learn the python necessary - it's not actually that complicated dealing with all the streaming etc - mostly one of the other providers can be cribbed.

Hit me up on the Discord channel if you like and we can discuss further. I suggest closing this bug in favour of a feature request to track implementation.

And we may even be able to pull up a couple of laptops over a beer sometime to do the implementation - I think from your website you live not a million miles from me (also just outside Cambridge).

awesomeruss commented 1 month ago

Mel - that sounds excellent. Coding and beer go always go together really well! I guess to make this work with MA we'd need to create a BBC Sounds Player Provider, that would take the user's BBC credentials as settings, then expose menus for the BBC radio stations and podcasts much like the LMS stuff. I think I'd need to find the time to spend a few days chugging through codeacademy so that I could at least read the existing MA code, then I might just take you up on the offer of a meetup.