LeonardoCardoso / SwiftLinkPreview

It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
https://leocardz.com/swift-link-preview-5a9860c7756f
MIT License
1.37k stars 196 forks source link

Does not follow redirects on Apple News links #130

Open chrysb opened 3 years ago

chrysb commented 3 years ago

Thanks for making this. Certainly saved me a lot of time!

Unfortunately, it doesn't seem to follow redirects.

Example: https://apple.news/Ak2IoOEp8Qdi6JVs8p-Jj_A

It should return the og:image from here: https://abcnews.go.com/Politics/capitol-breached-protesters/story?id=75081629

The impact is that it does not return the image from the news article, but rather a big Apple News logo.

LeonardoCardoso commented 3 years ago

Thanks for the report. I will add it to investigation needed.

chrysb commented 3 years ago

Just tried the library again and found it also doesn't work for Spotify urls:

Example: https://open.spotify.com/artist/39ywlwtGw8RTGobakgb11L?si=As8Ynf-RS12yFu8jckzhYQ

chrysb commented 3 years ago

Just tried the library again and found it also doesn't work for Spotify urls:

Example: https://open.spotify.com/artist/39ywlwtGw8RTGobakgb11L?si=As8Ynf-RS12yFu8jckzhYQ

I spoke too soon. I updated from 3.2.0 to 3.3.0 and that Spotify URL worked. Hurrah!

isharing0726 commented 3 years ago

The reason is that Apple news' OG:image doesn't have a file extension.

<meta property="og:image" content="https://c.apple.news/AgEXQWsySW9PRXA4UWRpNkpWczhwLUpqX0EAMA" /><meta name="twitter:card" content="summary_large_image" />

The supported imagePattern is

static let imagePattern = "(.+?)\\.(gif|jpg|jpeg|png|bmp)$"

chrysb commented 3 years ago

Would it make sense to pass along the image URL regardless of extension? That would allow clients to try to parse the image and we can rely on iOS to examine the content headers and try to create UIImages from the URLs.

JD10NN3 commented 3 years ago

Any news on this one? Any way to ignore the imagePattern ?