overcast-sonos icon indicating copy to clipboard operation
overcast-sonos copied to clipboard

Unable to browse music

Open felciano opened this issue 5 years ago • 16 comments

I'm having trouble getting this configured and running. The service and music source configuration seems to be working -- when going into that music source on the Sonos app, I can see a stream of activity in the console indicating that it is connecting and retrieving data. However the app then says Unable to browse music - there was a problem connecting to OvercastTest (where OvercastTest is what I named the Sonos music source).

Any suggestions?

felciano avatar Oct 13 '20 19:10 felciano

@felciano Overcast changed their API and now this is broken :( I'm going to spend some time fixing it this weekend! I've been airplaying to get around the issue but I far prefer a native Sonos service...

antonino-u avatar Nov 11 '20 15:11 antonino-u

Agreed -- would be great to see this working again. Thank you for your efforts here

felciano avatar Nov 11 '20 16:11 felciano

Hi @antonino-u any update on getting this working again?

felciano avatar Jan 01 '21 21:01 felciano

Ah sorry guys, I've been busy working on other projects :( I'm really hoping to get to it after I'm done with my current priority, which is winding down. It's annoying for me too, I assure you.

antonino-u avatar Jan 05 '21 16:01 antonino-u

Just to add a note that I'm waiting on this too :)

Interestingly though, for quite a few of the podcasts I'm subscribed to the script seems to work fine (although I have modified it to work in Python 3 by updating the import statements to the new module names like urllib.parse and http.server). Some episodes though still just give the generic 'Unable to connect to Overcast' error in the Sonos app, and I can't see anything in the console to explain this - the URIs reported in the debug statements look ok and I can open them in a browser with no issue so I suspect it's something else.

Here's a working one: +GXAiadKy4 And a non-working one: +gUC1iFZso

qbiecom avatar Apr 23 '21 23:04 qbiecom

Done a bit more testing and narrowed this down - Libsyn hosted podcasts seem to be the main ones giving the error. I haven't yet encountered any others that aren't working correctly (although that's not to say they aren't).

The URI returned by the overcast-sonos though does appear to be correct - I can copy and paste it into a web browser and play it fine.

qbiecom avatar Apr 24 '21 21:04 qbiecom

Ok, this is quite hacky but it works... for now.

As well as libsyn I was also having issues playing podcasts hosted on blubrry and audioboom. For the latter two, it was a simple case of telling final_redirect_url to ignore the redirects on these and just return the original URL again.

libsyn proved more more troublesome, but I eventually narrowed it down to two issues, the URL passed back (for whatever reason the player was having trouble connecting to it) and the certificate used by libsyn (it's not signed by one of the CAs listed at https://developer.sonos.com/build/content-service-get-started/security/). So, the function now switches the connection to HTTP rather than HTTPS, and removes everything after &cs_id in the URL which allows the device to play back the audio.

So, here's my new, hacked together, final_redirect_url function from utilities.py. It's not perfect, but it's a good start.

'def final_redirect_url(url): if "blubrry" in url or "audioboom" in url: log.debug('Ignoring redirects for this URL''') return url if "libsyn" in url: redirected_url = requests.head(url, allow_redirects=True).url http_url = redirected_url.replace('https://','http://') http_url = http_url.split('&cs_id',1) return http_url[0] else: redirected_url = requests.head(url, allow_redirects=True).url if url != redirected_url: log.debug('''Redirected url '%s' to '%s'.''', url, redirected_url) return redirected_url'

qbiecom avatar Apr 28 '21 11:04 qbiecom

If you make a PR I'm happy to approve it!

antonino-u avatar Apr 28 '21 14:04 antonino-u

I'll have a go once I've cleaned it all up :)

It's been a fun learning experience, I've never dabbled in Python before!

qbiecom avatar Apr 28 '21 15:04 qbiecom

I kind of hate it 😂 my goal for this would eventually to create a node package but I Airplay a lot more than I use this service these days, so my incentive to fix it is quite low. Very happy to pass the baton over to others :)

antonino-u avatar Apr 28 '21 16:04 antonino-u

Haha well I would use airplay but for some reason whenever I lock the screen on my phone Overcast will randomly stop playing :(

I've done a bit more work and was able to remove my 'hack' by updating some of the modules to newer versions (lxml to 4.1..1, PySimpleSoap to 1.16.2), the specified versions might not have been playing nicely with Python 3. I'm just checking newer versions to see if the latest ones work ok, then I'll include the updated requirements file in my PR.

qbiecom avatar Apr 30 '21 19:04 qbiecom

Ok, I've been productive as you can see from my PR!

  • Updated to work in Python 3
  • Made some tweaks to how a single podcasts episodes display to include the episode summaries
  • Fixed the Libsyn issue! It was caused by newer versions of requests, as there was a change to how it handles URL redirects in 2.19 and higher, so I've added a workaround for these (The sonos can't handle the #t= part at the end of the redirected URL for some reason!)
  • Made some tweaks to the readme and setup instructions
  • Updated the requirements to newer versions that work better with Python 3 (Some of them look like they were using deprecated functions so best not to rely on them)
  • Updated the function which 'deletes' a completed episode to delete if less than 60 seconds are left, because we don't have completely accurate episode lengths so episodes could end up left in your queue and you'd need to delete them on the website or in the app
  • Added a few comments here and there

I still want to do some work on how episodes are displayed and the presentation map, but for now the core functionality is all there and working!

This is actually been quite a fun learning experience. I'm now thinking about what other fun things I can do in python to try to expand my knowledge ;)

qbiecom avatar May 05 '21 22:05 qbiecom

@qbiecom thanks for making these edits. I tried downloading your fork and am able to get it configured as a new Sonos music source and connected. However I'm still getting an "unable to browse music" error when I select the "overcast" source from the Browse menu. In the terminal I can see get_active_episodes being called and it seem to be returning results, but the field values look weird:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): overcast.fm:443
DEBUG:urllib3.connectionpool:https://overcast.fm:443 "POST /login HTTP/1.1" 302 None
DEBUG:urllib3.connectionpool:https://overcast.fm:443 "GET /podcasts HTTP/1.1" 200 None
INFO:overcast-sonos:at=start
DEBUG:pysimplesoap.server:dispatch method: getLastUpdate
DEBUG:pysimplesoap.server:returns_types {'getLastUpdateResult': {'autoRefreshEnabled': <class 'bool'>, 'catalog': <class 'str'>, 'favorites': <class 'str'>, 'pollInterval': <class 'int'>}}
DEBUG:overcast-sonos:at=getLastUpdate
DEBUG:pysimplesoap.server:dispathed method returns: {'getLastUpdateResult': {'catalog': '5d98525f-61bc-41bd-bae9-2c6408563585', 'favorites': '0', 'pollInterval': 60}}
192.168.1.79 - - [21/Aug/2021 17:48:57] "POST /overcast-sonos HTTP/1.1" 200 -
DEBUG:pysimplesoap.server:dispatch method: getMetadata
DEBUG:pysimplesoap.server:returns_types {'getMetadataResult': {'index': <class 'int'>, 'count': <class 'int'>, 'total': <class 'int'>, 'mediaCollection': {'id': <class 'str'>, 'title': <class 'str'>, 'itemType': <class 'str'>, 'artistId': <class 'str'>, 'artist': <class 'str'>, 'albumArtURI': <class 'str'>, 'canPlay': <class 'bool'>, 'canEnumerate': <class 'bool'>, 'canAddToFavorites': <class 'bool'>, 'canScroll': <class 'bool'>, 'canSkip': <class 'bool'>}}}
DEBUG:overcast-sonos:at=getMetadata id=root index=0 count=100 recursive=False
DEBUG:urllib3.connectionpool:https://overcast.fm:443 "GET /podcasts HTTP/1.1" 200 None
...
'https://overcast.fm/art/thumb/2395170?110', 'genreId': 'podcast', 'canResume': True}}}, {'mediaMetadata': {'id': 'episodes/https://overcast.fm/+Nf6ATUZwc', 'title': '\n                    Dec 28, 2020 • 60 min                 - REPLAY: Frans von der Dunk – Space Law, Piracy, Profit and Militarization in Age of Star Wars', 'mimeType': 'audio/mpeg', 'itemType': 'track', 'semanticType': 'episode.podcast', 'trackMetadata': {'artist': '\n                    Dec 28, 2020 • 60 min                ', 'album': '\n                    Dec 28, 2020 • 60 min                ', 'albumArtist': '\n                    Dec 28, 2020 • 60 min                ', 'albumArtURI': 'https://overcast.fm/art/thumb/884640', 'genreId': 'podcast', 'canResume': True}}}]}
192.168.1.79 - - [21/Aug/2021 17:48:57] "POST /overcast-sonos HTTP/1.1" 200 -

After poking around the HTML on overcast.fm and the css parsing in get_episode_details, I'm wondering whether the page format has changed and thus ? For example, it looks like the title is being extracted from 'div.centertext h3 a', however I don't see any h3 tags in the HTML source. Is this still working for you?

felciano avatar Aug 22 '21 01:08 felciano

@felciano I've been using this consistently for a few weeks now with no issues, so not sure why it's not working for you.

I'll check when I get home tonight!

qbiecom avatar Aug 24 '21 09:08 qbiecom

@felciano yup, just tested and it's still working:

https://youtube.com/shorts/wqzBIT_bcr8?feature=share

I'll have a poke at the source of a page on overcasts site and see if we can get to the bottom of it.

qbiecom avatar Aug 24 '21 18:08 qbiecom

Thanks @qbiecom I'm happy to share what my OC page looks like in source if it would help

felciano avatar Aug 25 '21 05:08 felciano