Documentation
¶
Overview ¶
Package reddit adapts the standalone github.com/go-reddit/reddit client to the aggregator's source.Provider contract. Anonymous fetches go through the shared browserhttp uTLS client so Reddit's TLS-fingerprint anti-bot 403 does not fire; a session-cookie-authenticated client can be supplied instead (the user's own logged-in reddit_session), since Reddit's self-serve OAuth app registration is effectively closed to new personal projects.
Index ¶
- type Provider
- func (p *Provider) Comments(ctx context.Context, postID, subreddit string) ([]source.Comment, error)
- func (p *Provider) Feed(ctx context.Context, q source.Query) (source.Result, error)
- func (p *Provider) Kind() source.Kind
- func (p *Provider) MyFollows(ctx context.Context) ([]source.Subscription, error)
- func (p *Provider) MySubscriptions(ctx context.Context) ([]string, error)
- func (p *Provider) SearchChannels(ctx context.Context, query string) ([]source.ChannelResult, error)
- func (p *Provider) SearchPosts(ctx context.Context, query, subreddit string) ([]source.Item, error)
- func (p *Provider) SearchSubreddits(ctx context.Context, query string) ([]source.SubredditResult, error)
- func (p *Provider) WithRedgifs(r RedgifsResolver) *Provider
- type RedgifsResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider fetches Reddit posts as normalized source items.
func New ¶
func New() *Provider
New returns an anonymous Reddit provider backed by the portable browser fingerprint HTTP client (pure Go, CGO=0, no host web view).
func NewWithClient ¶
func NewWithClient(c fetcher) *Provider
NewWithClient wraps an already-configured reddit client — e.g. a session-cookie (logged-in) client, or a fake in tests. It has no RedGIFs resolver; attach one with Provider.WithRedgifs.
func NewWithCookie ¶
NewWithCookie returns a Reddit provider that authenticates reads with the user's own logged-in browser reddit_session cookie, driving hc (the shared, request-logging client the aggregator builds). Reddit's self-serve OAuth registration is effectively closed to new personal projects, so supplying the cookie from an already-signed-in browser is the practical path for individual, read-only use — the same session-cookie pattern the reader already offers for Instagram and TikTok. The cookie keeps the anonymous www ".json" endpoints (no OAuth). A nil hc falls back to the portable browser-fingerprint client so the constructor is safe on its own.
func NewWithHTTPClient ¶
NewWithHTTPClient returns an anonymous Reddit provider driving hc (e.g. the shared, request-logging client the aggregator builds so the Network log can show Reddit's traffic). The browser User-Agent is kept so the fingerprint still matches.
func (*Provider) Comments ¶
func (p *Provider) Comments(ctx context.Context, postID, subreddit string) ([]source.Comment, error)
Comments fetches a post's comment thread and flattens it into display order with a per-comment Depth (0 = top-level reply). It goes through the same (anonymous or session-cookie) client as the feed, so the user's auth applies. The tree is walked depth-first, preserving the reddit ordering; "load more" frontier markers are already dropped by the client (only "t1" things survive), and deleted/empty-body nodes are skipped here while their replies are kept, so a live subtree under a removed parent is not lost.
func (*Provider) Feed ¶
Feed returns a page of posts. An empty Query.Channel fetches the front page; otherwise it fetches r/<Channel>. Query.Cursor is the reddit "after" token.
func (*Provider) MyFollows ¶
MyFollows returns the connected Reddit account's follows as ready subscriptions: every subreddit it is subscribed to (r/<name>) plus every redditor it follows (u/<name>). It satisfies source.FollowImporter, so the aggregator's generic "import my subscriptions" action pulls both in one call. A session-cookie (logged-in) client is required; an anonymous client yields a typed auth error.
func (*Provider) MySubscriptions ¶
MySubscriptions returns the r/<name> channels of every subreddit the authenticated account follows, ready to add as subscriptions. It requires a session-cookie (logged-in) client; an anonymous client yields an error.
func (*Provider) SearchChannels ¶
func (p *Provider) SearchChannels(ctx context.Context, query string) ([]source.ChannelResult, error)
SearchChannels implements source.Searcher: it discovers subreddits matching query (via SearchSubreddits) and maps each onto the platform-agnostic source.ChannelResult the generic search UI renders — a Reddit result subscribes as r/<name>.
func (*Provider) SearchPosts ¶
SearchPosts searches Reddit for posts matching query and maps them onto the normalized feed items (through the same mapPost the feed uses). When subreddit is non-empty the search is restricted to it; otherwise it is site-wide. The default relevance order applies. A blank query is rejected by the underlying client.
func (*Provider) SearchSubreddits ¶
func (p *Provider) SearchSubreddits(ctx context.Context, query string) ([]source.SubredditResult, error)
SearchSubreddits discovers subreddits whose name, title or description matches query, mapping Reddit's search results onto the aggregator's source.SubredditResult discovery type. A blank query is rejected. The caller may narrow the returned names/descriptions further with a local regexp filter (Reddit itself cannot enumerate subreddits, so this search is the only discovery path).
func (*Provider) WithRedgifs ¶
func (p *Provider) WithRedgifs(r RedgifsResolver) *Provider
WithRedgifs sets the resolver that turns RedGIFs links inside posts into direct media and returns the provider for chaining. The network constructors wire a real *redgifs.Client automatically; this is for NewWithClient and for injecting a fake in tests.
type RedgifsResolver ¶
RedgifsResolver resolves a RedGIFs gif id to its media variant URLs. The reddit provider uses it to turn a redgifs.com/watch/<id> or /ifr/<id> link pasted into a post into the actual playable mp4 + poster, instead of the static poster Reddit embeds. *redgifs.Client satisfies it; tests inject a fake so no live network is touched.