Skip to content

Repository files navigation

reddit-embed

A small self-hosted service that generates Discord link previews (OpenGraph embeds) for Reddit posts, using the official Reddit Data API.

When a Reddit link is shared on Discord with the service's host in place of www.reddit.com, Discord's link-preview crawler receives the post's title, text and media as OpenGraph tags. Browsers are redirected to the original post on reddit.com.

Inspired by fxreddit.

Reddit Data API usage

This project follows Reddit's Responsible Builder Policy and Data API Terms. It requires approved API access.

Authentication App-only OAuth (client_credentials). No user login, no password stored.
Access Read-only. The service never posts, comments, votes, messages or moderates.
Endpoints GET /comments/{id} for the single post being shared (plus comment= for a linked comment), and resolving /r/{sub}/s/{code} share links. Nothing else.
Volume One request per shared link, on demand. No listings, search, crawling or bulk collection.
Rate limits X-Ratelimit-* headers are tracked; no request is sent while the quota is exhausted.
User-Agent linux:reddit-embed:<version> (by /u/<username>), as required by Reddit.
Caching Post data is kept in memory for 10 minutes. Merged video files are deleted after VIDEO_CACHE_DAYS (3 by default).
Removed content Removed or deleted posts and comments are never displayed.
NSFW / spoilers Only the title is shown, without text or media.
Data use No storage beyond the caches above, no resale or sharing, no AI/ML training, no user profiling.

Every preview links back to the original post, with its subreddit and author.

Supported links

Replace www.reddit.com with the service's public URL:

https://www.reddit.com/r/<sub>/comments/<id>/<slug>/
https://<host>/rdt/r/<sub>/comments/<id>/<slug>/
  • Posts and links to a specific comment
  • /comments/<id>, /gallery/<id>, short ids (/<id>, like redd.it)
  • Share links (/r/<sub>/s/<code>)

Preview content by post type: text, image, gallery (up to 4 images), Reddit-hosted video with audio, YouTube, and polls.

Reddit-hosted videos are published as separate DASH video and audio tracks. The service merges them with ffmpeg (stream copy, no re-encoding, 720p max) so Discord can play the video with sound. Videos longer than VIDEO_MAX_DURATION show a thumbnail only.

Setup

Requirements: Python 3.10+, ffmpeg, and Reddit Data API credentials.

python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
cp .env.example .env && chmod 600 .env   # then fill in the values
.venv/bin/python app.py

Test with a crawler User-Agent:

curl -A Discordbot http://127.0.0.1:8080/r/<sub>/comments/<id>/

To run it permanently, use the systemd user unit reddit-embed.service (it expects the project in ~/reddit-embed) and put the service behind an HTTPS reverse proxy. nginx-rdt.conf is an example location block.

Configuration

Variable Default Description
REDDIT_CLIENT_ID / REDDIT_CLIENT_SECRET API credentials
REDDIT_USERNAME Used in the User-Agent
PUBLIC_BASE_URL Public URL of the service, no trailing slash
PORT 8080 Local port (the service binds to 127.0.0.1 only)
VIDEO_MAX_HEIGHT 720 Maximum video height
VIDEO_MAX_DURATION 600 Longer videos only show a thumbnail (seconds)
VIDEO_CACHE_DAYS 3 Retention of merged video files
LOG_LEVEL INFO

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages