this post was submitted on 19 Dec 2024
35 points (100.0% liked)

Fediverse

28691 readers
632 users here now

A community to talk about the Fediverse and all it's related services using ActivityPub (Mastodon, Lemmy, KBin, etc).

If you wanted to get help with moderating your own community then head over to [email protected]!

Rules

Learn more at these websites: Join The Fediverse Wiki, Fediverse.info, Wikipedia Page, The Federation Info (Stats), FediDB (Stats), Sub Rehab (Reddit Migration), Search Lemmy

founded 2 years ago
MODERATORS
 

If you go to [email protected] and scroll you'll see some of the posts have a youtube thumbnail image, but not all.

I wanna post YouTube videos, but no one seems to engage much without a thumbnail, which makes sense, but I'm not sure what would result in the post actually having a thumbnail

If anyone has advice or guidance I'd appreciate it :) Thanks!

EDIT: so far it seems like it's potentially a combination of what version of lemmy the posters account is running, and how that instance is configured...

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 4 hours ago* (last edited 4 hours ago) (7 children)

So I take a peek at the Lemmy's source code.

When you see a thumbnail and title of a URL (including YouTube video links) on Lemmy, what happens is that Lemmy server fetched the website HTML file and get the og:title and og:image (this convention is called OpenGraph protocol ^1) located inside <head> HTML tag.

For example, for this video https://www.youtube.com/watch?v=MbYuEEU5e50, the OpenGraph metadata inside the HTML looks like this:

<meta property="og:title" content="Flume - Lose It feat. Vic Mensa">
<meta property="og:image" content="https://i.ytimg.com/vi/MbYuEEU5e50/maxresdefault.jpg">

Try opening the "Create Post" page, then enter URL of a YouTube video. You might notice that a loading spinner will appear. During this, the frontend of Lemmy is actually creating a request to /api/v3/post/site_metadata?url=[insert your URL]. When the backend side of Lemmy receives the request from front end, it will run this code ^2 to fetch the HTML and parse it to find the OpenGraph metadata. If the metadata is found, the backend will return it to front end, and you willl see recommended title and the "Thumbnail URL" field should be filled.

In theory, this should work fine, regardless of any website. I personally tried to view the HTML code of a YouTube video and the HTML file indeed contains OpenGraph metadata.

But it doesn't for YouTube videos in Lemmy somehow. And I'm not sure.

I'm suspecting YouTube thought that Lemmy servers are bots and because of that instead of receiving the HTML file of a YouTube video, instead it received a HTML file of a captcha page. I think I'm gonna try contacting admins of my instance to see whether YouTube URL works or not.

[–] [email protected] 1 points 3 hours ago (2 children)

Thats a very helpful response, thank you!

It seems like the only people getting thumbnails on [email protected] are from shitjustworks (how fitting lol)

[–] [email protected] 2 points 3 hours ago* (last edited 3 hours ago) (1 children)

See the other reply: seems that it was caused by Lemmy backend only fetches the first 512kb of the HTML, meanwhile YouTube puts bunch of JavaScript in the beginning of the HTML

Here's the fix that was only merged couple days ago apparently, https://github.com/LemmyNet/lemmy/pull/5266

Crazy, right

[–] [email protected] 1 points 3 hours ago

Interesting...

load more comments (4 replies)