Skip to content

feat(processor): fetch the media of embedded tweets - #4612

Open
dave-atx wants to merge 1 commit into
miniflux:mainfrom
dave-atx:feat/expand-tweet-embeds
Open

dave-atx wants to merge 1 commit into
miniflux:mainfrom
dave-atx:feat/expand-tweet-embeds

Conversation

@dave-atx

@dave-atx dave-atx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Have you followed these guidelines?

Embedded tweets show up in Miniflux as a bare blockquote. The sanitizer (correctly) drops X's widget script, so photos and videos are lost and links stay as opaque t.co URLs. News sites like MacRumors, 9to5Mac and Ars Technica embed tweets often, and the media is usually the point of the embed.

This adds an opt-in FETCH_TWEET_EMBEDS option. For each blockquote whose last link points to a tweet, the processor fetches the tweet from the syndication endpoint X's own embed widget uses (cdn.syndication.twimg.com/tweet-result), then:

  • appends photos as <img>, and videos and GIFs as <video> (highest bitrate MP4, thumbnail as poster)
  • replaces t.co links with the URLs they point to, and drops the media placeholder link

Like the crawler and the watch time fetches, it only runs for new entries or on a forced refresh. Non-crawler feeds update existing entries on every refresh, which would replace the expanded content with the feed's copy, so existing entries with a tweet embed are left out of the update unless the refresh is forced. Other entries update normally.

Each tweet is fetched at most once per refresh. After a failed request (timeout, etc) the rest of the refresh skips the endpoint, so a slow endpoint delays it by one timeout at most; deleted / protected tweets don't count as failures. If a fetch fails, the content is left as it was. Requests go through the fetcher with the configured timeout and proxy rotator, the same way the Bilibili watch time fetch does.

A couple of things reviewers should know:

  • The endpoint is undocumented, but it's widely used: X's own embed widget loads tweets from it, as do libraries like Vercel's react-tweet. It needs a non-empty token parameter but doesn't validate it, so Miniflux sends a constant. If X changes or removes the endpoint, entries just stop getting media and nothing else changes.
  • Videos are hotlinked from video.twimg.com, which returns 403 when the request has a Referer from another site. The web UI sends no referrer, so it plays fine there. API clients that send one need the media proxy with video in MEDIA_PROXY_RESOURCE_TYPES. I left the <video> element without width / height since the reader stylesheet doesn't give videos height: auto, and the attributes leave a tall empty box when the video is scaled down.

Testing: unit tests cover photos, videos, non-tweet and nested blockquotes, fetch failures (including skipping the endpoint after a failed request), tweets without media, unsafe URLs, fetching each tweet once, and the t.co expansion (including escaping and rejecting non-http(s) destinations). make test passes with -race. I'd been running the earlier rewrite rule version on my own instance against MacRumors, 9to5Mac and Ars Technica; this version hasn't been deployed there yet.

Docs: miniflux/website#139 adds the option to the configuration page.

No breaking changes; nothing runs unless FETCH_TWEET_EMBEDS=1.

@fguillot fguillot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few blockers:

  1. Fetches block the refresh worker. Each uncached tweet is fetched one at a time with the full HTTP timeout, so a slow syndication endpoint can hold up refreshes for every other feed.
  2. Nested blockquotes duplicate media. An outer blockquote that wraps a tweet embed matches the same status link, so the media gets appended twice.

Most of this comes from doing network I/O inside a rewrite rule, which runs on every entry at every refresh. Could you move the fetch into the processor and only run it for new entries (entryIsNew || forceRefresh), the way Bilibili/YouTube watch time works? That also removes the need for the in-memory cache.

@dave-atx
dave-atx force-pushed the feat/expand-tweet-embeds branch from ac53cf8 to d4e22c6 Compare November 4, 2026 04:25
@dave-atx

dave-atx commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both fair. I reworked it:

  • The fetch moved into the processor (internal/reader/processor/tweet_embeds.go) and only runs for entryIsNew || forceRefresh. It's behind a new FETCH_TWEET_EMBEDS option, like the watch time ones. The rewrite rule and the in-memory cache are gone.
  • Non-crawler feeds update existing entries on every refresh, so the next refresh would have replaced the expanded content with the feed's copy. When the option is on, existing entries with a tweet embed are left out of the update unless the refresh is forced, the same way crawler feeds skip updates. Other entries update normally.
  • Each tweet is fetched at most once per refresh. After a failed request (timeout, etc) the rest of the refresh skips the endpoint, so a slow endpoint costs one timeout at most. Deleted / protected tweets don't count as failures.
  • A blockquote's last link now has to be its own, outside any nested blockquote, so a quote wrapping an embed no longer gets the media twice. There's a test for it.

If you'd rather have this as a per-feed setting than an instance-wide option, I'm happy to switch it.

dave-atx added a commit to dave-atx/miniflux-website that referenced this pull request Nov 4, 2026
Documents the FETCH_TWEET_EMBEDS option added in miniflux/v2#4612.
@dave-atx dave-atx changed the title feat(rewrite): add expand_tweet_embeds rule feat(processor): fetch the media of embedded tweets Nov 4, 2026
Embedded tweets reach the reader as a bare blockquote: the sanitizer drops
X's widget script, so photos and videos are lost and links stay as opaque
t.co URLs.

When FETCH_TWEET_EMBEDS is enabled, the processor finds blockquotes whose
last link points to a tweet, fetches the tweet from the syndication
endpoint used by X's embed widget, and:

- appends the tweet's photos as <img> and its videos and GIFs as <video>,
  using the highest bitrate MP4 and the thumbnail as poster
- replaces t.co links with the URLs they point to, and drops the media
  placeholder link

As with the crawler and watch times, tweets are only fetched for new
entries or on a forced refresh. Existing entries containing an embedded
tweet are left out of the update, so they keep the stored media instead of
being replaced by the feed's copy without it.

Each tweet is fetched at most once per refresh. After a request fails, the
rest of the refresh skips the endpoint, so a slow endpoint delays it by one
timeout at most. Deleted or protected tweets don't count as failures. If a
fetch fails, the content is left unchanged.

A link inside a nested blockquote belongs to that blockquote, so a quote
wrapping a tweet embed doesn't get the tweet's media a second time.
@dave-atx
dave-atx force-pushed the feat/expand-tweet-embeds branch from d4e22c6 to e41a884 Compare December 1, 2026 19:19
@dave-atx

dave-atx commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (a5ff7e7). After 3070c7f, forbidigo flagged the three *Html calls in tweet_embeds.go, so I switched them to build html.Node values and insert them with the *Nodes methods:

  • Media figures are built with newElementNode / newTextNode, copied from the rewrite package since they're unexported there.
  • t.co URLs in text are replaced by splitting the text node into text and link nodes, instead of string-replacing escaped HTML and parsing it back.

The rendered output is unchanged (the existing tests compare full HTML). I added a test for a paragraph that holds only the media's t.co link, since that's the case the node version could get wrong. golangci-lint is clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants