s9e / TextFormatter

Text formatting library that supports BBCode, HTML and other markup via plugins. Handles emoticons, censors words, automatically embeds media and more.
MIT License
233 stars 36 forks source link

`spotify.link` seemingly not supported #223

Closed tarjeiba closed 1 year ago

tarjeiba commented 1 year ago

It doesn't seem like spotify.link urls are supported, and thus does not render an embedded player.

https://spotify.link/U1CqAwCm3Cb

If I'm mistaken, great.

It does seem, however, like there's a couple of levels of redirects to be done before getting the whole resource info, so fixing this might be outside TextFormatters scope. Is that correct?

Edit: It seems there is no reason to have to strong a hope of fixing this, https://community.spotify.com/t5/Spotify-for-Developers/Give-us-an-endpoint-to-decode-new-shortened-share-links/m-p/5523686 .

JoshyPHP commented 1 year ago

I can add support for those. Spotify used to use link.tospotify.com for their short links, I can just add spotify.link to the list.

tarjeiba commented 1 year ago

Nice, thanks! I didn't know that link.tospotify.com links were shortened as well.

JoshyPHP commented 1 year ago

They were, but it seems they have abandoned the domain, which is weird considering it breaks every instance a short link was shared in the past.

$ nslookup spotify.link - 8.8.8.8
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   spotify.link
Address: 13.56.23.3
Name:   spotify.link
Address: 13.52.129.235

$ nslookup link.tospotify.com - 8.8.8.8
Server:     8.8.8.8
Address:    8.8.8.8#53

** server can't find link.tospotify.com: NXDOMAIN
tarjeiba commented 1 year ago

Thanks again!

Just so I understand further ... how do we actually get what is needed from the shortened url? Given the Spotify community discussion, I assumed that to be infeasible.

JoshyPHP commented 1 year ago

What it does is it downloads the linked page and looks for anything that matches a Spotify URL anywhere in the headers or the page's source. If the short link is a redirect, the correct URL should be somewhere in a Location header. It doesn't use any API, just basic scraping.

$ wget https://spotify.link/U1CqAwCm3Cb
Resolving spotify.link... 13.52.129.235, 13.56.23.3
Connecting to spotify.link|13.52.129.235|:443... connected.
HTTP request sent, awaiting response... 307 Temporary Redirect
Location: https://open.spotify.com/track/1lb8H6M5htL5MeBpZpmZws?si=ToGzloD-QTy6tnlehRcmYQ&utm_source=copy-link&utm_medium=copy-link&nd=1&_branch_match_id=link-1230390365295791060 [following]
tarjeiba commented 1 year ago

That makes sense. Thanks again! And thanks for closing it quickly.