NickM-27 / LinkPreview

An easy to use library for showing a link preview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to show title on top of URL?

TheMithuRoy opened this issue · comments

Is it possible to display the og:title on top of the URL? Instead of showing YouTube Video, the video title may show up. And instead of displaying the full link, just the hostname would be really nice.

Yes it is possible. you i have to import library and make changes in LinkPreview.kt file.

If you make this change and do a pr I'd be happy to accept it

Okay, I will try if I got the time to do but in the meantime if someone is not able to fetch the youtube title you just need to remove the below code and the else condition code will be outside the else branch. so that means jsoup will fetch the title and image from the youtube URL as well as the normal URL. That is work for me.

LinkPreview.Kt
if (url.let { it.contains("youtube") && it.contains("v=") }) { val id = url.split("v=")[1].split(" ")[0] val imageUrl = "https://img.youtube.com/vi/$id/hqdefault.jpg" imageType = ImageType.YOUTUBE context.addLink(url, imageUrl) setPreviewData(PreviewData("Youtube Video",imageUrl,url)) }