reddit

package
v0.1.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIdleTimeoutReached = errors.New("download idle timeout reached")

Functions

This section is empty.

Types

type AuthorFlairRichtext

type AuthorFlairRichtext struct {
	E string `json:"e"`
	T string `json:"t"`
}

type CheckSubredditParams

type CheckSubredditParams struct {
	Subreddit     string        `json:"subreddit"`
	SubredditType SubredditType `json:"subreddit_type"`
}

type Client

type Client interface {
	Do(*http.Request) (*http.Response, error)
}

func NewRedditHTTPClient

func NewRedditHTTPClient(cfg *config.Config) Client

type Data

type Data struct {
	After     string `json:"after"`
	Dist      int    `json:"dist"`
	Modhash   string `json:"modhash"`
	GeoFilter any    `json:"geo_filter"`
	Children  []Post `json:"children"`
	Before    any    `json:"before"`
}

type DownloadStatusBroadcaster

type DownloadStatusBroadcaster interface {
	Broadcast(bmessage.ImageDownloadMessage)
}

type GalleryData

type GalleryData struct {
	Items []Items `json:"items"`
}

type GetPostsParam

type GetPostsParam struct {
	Subreddit     string
	Limit         int
	After         string
	SubredditType SubredditType
}

type Gildings

type Gildings struct{}

type ImageDownloadReader

type ImageDownloadReader struct {
	OnProgress         func(downloaded int64, contentLength int64, err error)
	OnClose            func(downloaded int64, contentLength int64, closeErr error)
	IdleTimeout        time.Duration
	IdleSpeedThreshold units.MetricBytes
	// contains filtered or unexported fields
}

func (*ImageDownloadReader) Close

func (idr *ImageDownloadReader) Close() error

func (*ImageDownloadReader) Read

func (idr *ImageDownloadReader) Read(p []byte) (n int, err error)

func (*ImageDownloadReader) WrapHTTPResponse

func (idr *ImageDownloadReader) WrapHTTPResponse(resp *http.Response) *http.Response

type Images

type Images struct {
	Source      Source        `json:"source"`
	Resolutions []Resolutions `json:"resolutions"`
	Variants    Variants      `json:"variants"`
	ID          string        `json:"id"`
}

type Items

type Items struct {
	OutboundURL string `json:"outbound_url,omitempty"`
	MediaID     string `json:"media_id"`
	ID          int    `json:"id"`
}

type LinkFlairRichtext

type LinkFlairRichtext struct {
	E string `json:"e"`
	T string `json:"t"`
}

type Listing

type Listing struct {
	Kind string `json:"kind"`
	Data Data   `json:"data"`
}

func (*Listing) GetLastAfter

func (l *Listing) GetLastAfter() string

GetLastAfter returns the last post namee for pagination.

Returns empty string if there is no more posts to look up.

func (*Listing) GetPosts

func (l *Listing) GetPosts() []Post

func (*Listing) GetSubreddit

func (l *Listing) GetSubreddit() string

type MediaEmbed

type MediaEmbed struct{}

type MediaMetadata

type MediaMetadata struct {
	Status          string             `json:"status"`
	Kind            string             `json:"e"`
	Mimetype        string             `json:"m"`
	ExtraThumbnails []ThumbnailPreview `json:"p"`
	Thumbnail       ThumbnailPreview   `json:"s"`
	ID              string             `json:"id"`
}

type NullDownloadStatusBroadcaster

type NullDownloadStatusBroadcaster struct{}

func (NullDownloadStatusBroadcaster) Broadcast

type Post

type Post struct {
	Kind string   `json:"kind"`
	Data PostData `json:"data,omitempty"`
}

func (*Post) GetAuthor

func (post *Post) GetAuthor() string

func (*Post) GetAuthorURL

func (post *Post) GetAuthorURL() string

func (*Post) GetCreated

func (post *Post) GetCreated() time.Time

func (*Post) GetID

func (post *Post) GetID() string

func (*Post) GetImageAspectRatio

func (post *Post) GetImageAspectRatio() float64

func (*Post) GetImageFilename

func (post *Post) GetImageFilename() string

func (*Post) GetImageRelativePath

func (post *Post) GetImageRelativePath(device *models.Device) string

func (*Post) GetImageSize

func (post *Post) GetImageSize() (width, height int64)

func (*Post) GetImageTargetDir

func (post *Post) GetImageTargetDir(cfg *config.Config, device *models.Device) string

func (*Post) GetImageTargetPath

func (post *Post) GetImageTargetPath(cfg *config.Config, device *models.Device) string

func (*Post) GetImageURL

func (post *Post) GetImageURL() string

func (*Post) GetName

func (post *Post) GetName() string
func (post *Post) GetPermalink() string

func (*Post) GetPostCreated

func (post *Post) GetPostCreated() int64

func (*Post) GetPostName

func (post *Post) GetPostName() string

func (*Post) GetPostTitle

func (post *Post) GetPostTitle() string

func (*Post) GetPostURL

func (post *Post) GetPostURL() string

func (*Post) GetSubreddit

func (post *Post) GetSubreddit() string

func (*Post) GetThumbnailRelativePath

func (post *Post) GetThumbnailRelativePath() string

func (*Post) GetThumbnailSize

func (post *Post) GetThumbnailSize() (width, height int64)

func (*Post) GetThumbnailTargetDir

func (post *Post) GetThumbnailTargetDir(cfg *config.Config) string

func (*Post) GetThumbnailTargetPath

func (post *Post) GetThumbnailTargetPath(cfg *config.Config) string

func (*Post) GetThumbnailURL

func (post *Post) GetThumbnailURL() string

func (*Post) GetTitle

func (post *Post) GetTitle() string

func (*Post) GetWindowsWallpaperImageRelativePath

func (post *Post) GetWindowsWallpaperImageRelativePath(device *models.Device) string

func (*Post) GetWindowsWallpaperImageTargetDir

func (post *Post) GetWindowsWallpaperImageTargetDir(cfg *config.Config, device *models.Device) string

func (*Post) GetWindowsWallpaperImageTargetPath

func (post *Post) GetWindowsWallpaperImageTargetPath(cfg *config.Config, device *models.Device) string

func (*Post) IsImagePost

func (post *Post) IsImagePost() bool

func (*Post) IsNSFW

func (post *Post) IsNSFW() bool

func (*Post) IsNSFWInt

func (post *Post) IsNSFWInt() int

type PostData

type PostData struct {
	ApprovedAtUtc              any                      `json:"approved_at_utc"`
	Subreddit                  string                   `json:"subreddit"`
	Selftext                   string                   `json:"selftext"`
	AuthorFullname             string                   `json:"author_fullname"`
	Saved                      bool                     `json:"saved"`
	ModReasonTitle             any                      `json:"mod_reason_title"`
	Gilded                     int                      `json:"gilded"`
	Clicked                    bool                     `json:"clicked"`
	IsGallery                  bool                     `json:"is_gallery"`
	Title                      string                   `json:"title"`
	LinkFlairRichtext          []LinkFlairRichtext      `json:"link_flair_richtext"`
	SubredditNamePrefixed      string                   `json:"subreddit_name_prefixed"`
	Hidden                     bool                     `json:"hidden"`
	Pwls                       int                      `json:"pwls"`
	LinkFlairCSSClass          string                   `json:"link_flair_css_class"`
	Downs                      int                      `json:"downs"`
	ThumbnailHeight            int64                    `json:"thumbnail_height"`
	TopAwardedType             any                      `json:"top_awarded_type"`
	HideScore                  bool                     `json:"hide_score"`
	MediaMetadata              map[string]MediaMetadata `json:"media_metadata"`
	Name                       string                   `json:"name"`
	Quarantine                 bool                     `json:"quarantine"`
	LinkFlairTextColor         any                      `json:"link_flair_text_color"`
	UpvoteRatio                float64                  `json:"upvote_ratio"`
	AuthorFlairBackgroundColor any                      `json:"author_flair_background_color"`
	Ups                        int                      `json:"ups"`
	Domain                     string                   `json:"domain"`
	MediaEmbed                 MediaEmbed               `json:"media_embed"`
	ThumbnailWidth             int64                    `json:"thumbnail_width"`
	AuthorFlairTemplateID      string                   `json:"author_flair_template_id"`
	IsOriginalContent          bool                     `json:"is_original_content"`
	UserReports                []any                    `json:"user_reports"`
	SecureMedia                any                      `json:"secure_media"`
	IsRedditMediaDomain        bool                     `json:"is_reddit_media_domain"`
	IsMeta                     bool                     `json:"is_meta"`
	Category                   any                      `json:"category"`
	SecureMediaEmbed           SecureMediaEmbed         `json:"secure_media_embed"`
	GalleryData                GalleryData              `json:"gallery_data"`
	LinkFlairText              string                   `json:"link_flair_text"`
	CanModPost                 bool                     `json:"can_mod_post"`
	Score                      int                      `json:"score"`
	ApprovedBy                 any                      `json:"approved_by"`
	IsCreatedFromAdsUI         bool                     `json:"is_created_from_ads_ui"`
	AuthorPremium              bool                     `json:"author_premium"`
	Thumbnail                  string                   `json:"thumbnail"`
	Edited                     any                      `json:"edited"`
	AuthorFlairCSSClass        string                   `json:"author_flair_css_class"`
	AuthorFlairRichtext        []AuthorFlairRichtext    `json:"author_flair_richtext"`
	Gildings                   Gildings                 `json:"gildings"`
	ContentCategories          any                      `json:"content_categories"`
	IsSelf                     bool                     `json:"is_self"`
	SubredditType              string                   `json:"subreddit_type"`
	Created                    float64                  `json:"created"`
	LinkFlairType              string                   `json:"link_flair_type"`
	Wls                        int                      `json:"wls"`
	RemovedByCategory          any                      `json:"removed_by_category"`
	BannedBy                   any                      `json:"banned_by"`
	AuthorFlairType            string                   `json:"author_flair_type"`
	TotalAwardsReceived        int                      `json:"total_awards_received"`
	AllowLiveComments          bool                     `json:"allow_live_comments"`
	SelftextHTML               any                      `json:"selftext_html"`
	Likes                      any                      `json:"likes"`
	SuggestedSort              any                      `json:"suggested_sort"`
	BannedAtUtc                any                      `json:"banned_at_utc"`
	URLOverriddenByDest        string                   `json:"url_overridden_by_dest"`
	ViewCount                  any                      `json:"view_count"`
	Archived                   bool                     `json:"archived"`
	NoFollow                   bool                     `json:"no_follow"`
	IsCrosspostable            bool                     `json:"is_crosspostable"`
	Pinned                     bool                     `json:"pinned"`
	Over18                     bool                     `json:"over_18"`
	AllAwardings               []any                    `json:"all_awardings"`
	Awarders                   []any                    `json:"awarders"`
	MediaOnly                  bool                     `json:"media_only"`
	CanGild                    bool                     `json:"can_gild"`
	Spoiler                    bool                     `json:"spoiler"`
	Locked                     bool                     `json:"locked"`
	AuthorFlairText            string                   `json:"author_flair_text"`
	TreatmentTags              []any                    `json:"treatment_tags"`
	Visited                    bool                     `json:"visited"`
	RemovedBy                  any                      `json:"removed_by"`
	ModNote                    any                      `json:"mod_note"`
	Distinguished              any                      `json:"distinguished"`
	SubredditID                string                   `json:"subreddit_id"`
	AuthorIsBlocked            bool                     `json:"author_is_blocked"`
	ModReasonBy                any                      `json:"mod_reason_by"`
	NumReports                 any                      `json:"num_reports"`
	RemovalReason              any                      `json:"removal_reason"`
	LinkFlairBackgroundColor   any                      `json:"link_flair_background_color"`
	ID                         string                   `json:"id"`
	IsRobotIndexable           bool                     `json:"is_robot_indexable"`
	ReportReasons              any                      `json:"report_reasons"`
	Author                     string                   `json:"author"`
	DiscussionType             any                      `json:"discussion_type"`
	NumComments                int                      `json:"num_comments"`
	SendReplies                bool                     `json:"send_replies"`
	WhitelistStatus            string                   `json:"whitelist_status"`
	ContestMode                bool                     `json:"contest_mode"`
	ModReports                 []any                    `json:"mod_reports"`
	AuthorPatreonFlair         bool                     `json:"author_patreon_flair"`
	AuthorFlairTextColor       string                   `json:"author_flair_text_color"`
	Permalink                  string                   `json:"permalink"`
	ParentWhitelistStatus      string                   `json:"parent_whitelist_status"`
	Stickied                   bool                     `json:"stickied"`
	URL                        string                   `json:"url"`
	SubredditSubscribers       int                      `json:"subreddit_subscribers"`
	CreatedUtc                 float64                  `json:"created_utc"`
	NumCrossposts              int                      `json:"num_crossposts"`
	Media                      any                      `json:"media"`
	IsVideo                    bool                     `json:"is_video"`
	PostHint                   string                   `json:"post_hint"`
	Preview                    Preview                  `json:"preview"`
}

type PostImage

type PostImage struct {
	URL  string
	File io.ReadCloser
}

func (*PostImage) Close

func (po *PostImage) Close() error

func (*PostImage) Read

func (po *PostImage) Read(p []byte) (n int, err error)

type Preview

type Preview struct {
	Images  []Images `json:"images"`
	Enabled bool     `json:"enabled"`
}

type Reddit

type Reddit struct {
	Client Client
	Config *config.Config
}

func (*Reddit) CheckSubreddit

func (reddit *Reddit) CheckSubreddit(ctx context.Context, params CheckSubredditParams) (actual string, err error)

CheckSubreddit checks a subreddit existence and will return error if subreddit not found.

The actual is the subreddit with proper capitalization if no error is returned.

func (*Reddit) DownloadImage

func (reddit *Reddit) DownloadImage(ctx context.Context, post Post, broadcaster *broadcast.Relay[events.Event]) (image PostImage, err error)

DownloadImage downloades the image.

If downloading image or thumbnail fails

func (*Reddit) DownloadThumbnail

func (reddit *Reddit) DownloadThumbnail(ctx context.Context, post Post, broadcaster *broadcast.Relay[events.Event]) (image PostImage, err error)

func (*Reddit) GetPosts

func (reddit *Reddit) GetPosts(ctx context.Context, params GetPostsParam) (posts Listing, err error)

type Resolutions

type Resolutions struct {
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type SecureMediaEmbed

type SecureMediaEmbed struct{}

type Source

type Source struct {
	URL    string `json:"url"`
	Width  int64  `json:"width"`
	Height int64  `json:"height"`
}

type SubredditType

type SubredditType int
const (
	SubredditTypeSub SubredditType = iota
	SubredditTypeUser
)

func (SubredditType) Code

func (s SubredditType) Code() string

func (*SubredditType) Parse

func (su *SubredditType) Parse(s string) error

func (SubredditType) String

func (s SubredditType) String() string

func (*SubredditType) UnmarshalJSON

func (su *SubredditType) UnmarshalJSON(b []byte) error

type ThumbnailPreview

type ThumbnailPreview struct {
	Y int    `json:"y"`
	X int    `json:"x"`
	U string `json:"u"`
}

type Variants

type Variants struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL