https://github.com/atye/redmed
Go client for posting media to Reddit
https://github.com/atye/redmed
go golang media reddit reddit-api reddit-client
Last synced: 5 months ago
JSON representation
Go client for posting media to Reddit
- Host: GitHub
- URL: https://github.com/atye/redmed
- Owner: atye
- License: mit
- Created: 2022-08-30T02:22:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-01T02:45:29.000Z (almost 4 years ago)
- Last Synced: 2024-06-20T08:17:42.967Z (almost 2 years ago)
- Topics: go, golang, media, reddit, reddit-api, reddit-client
- Language: Go
- Homepage:
- Size: 1.5 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# redmed
`redmed` is a **red**it API wrapper for posting **med**ia (image, video, videogif) submissions.
## Why?
Existing Reddit API clients, such as [go-reddit](https://github.com/vartanbeno/go-reddit), only support link and self posts.
`redmed` used alongside existing tools gives you a more complete Reddit API wrapper.
## Usage (see [examples)](https://github.com/atye/redmed/blob/main/examples/main.go)
### Create a client
```
reddit := redmed.New(userAgent, clientID, secret, username, password)
```
With HTTP Client
```
c := &http.Client{Timeout: time.Second * 30}
reddit := redmed.New(userAgent, clientID, secret, username, password, redmed.WithHTTPClient(c))
```
With [gorilla](https://github.com/gorilla/websocket) Websocket Dialer
```
d := websocket.DefaultDialer
d.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
reddit := redmed.New(userAgent, clientID, secret, username, password, redmed.WithWebsocketDialer(d))
```
### Post an image
Supported image types:
- .png
- .jpg
- .jpeg
- .gif
Post image from local machine
```go
req := redmed.PostImageRequest{
NSWF: false,
Path: "/path/to/image.jpeg",
Resubmit: true,
SendReplies: true,
Spoiler: false,
Subreddit: "subreddit",
Title: "image from local path",
}
name, err := reddit.PostImage(context.Background(), req)
if err != nil {
fmt.Println(err)
}
```
Post image from link
```go
req := redmed.PostImageRequest{
NSWF: false,
Path: "https://host.com/image.jpeg",
Resubmit: true,
SendReplies: true,
Spoiler: false,
Subreddit: "subreddit",
Title: "image from local path",
}
name, err := reddit.PostImage(context.Background(), req)
if err != nil {
fmt.Println(err)
}
```
Post image gallery
```go
req := redmed.PostGalleryRequest{
NSWF: false,
Paths: []string{"/path/to/image.jpeg", "https://host.com/image.jpeg"},
SendReplies: true,
Spoiler: false,
Subreddit: "subreddit",
Title: "gallery from local path and link",
}
name, err := reddit.PostGallery(context.Background(), req)
if err != nil {
fmt.Println(err)
}
```
### Post a video
Supported image types:
- .mp4
- .mov
Post video from local machine with thumbnail image from link
```go
req := redmed.PostVideoRequest{
Kind: "video", // or videogif for silent video
NSWF: false,
VideoPath: "/path/to/video.mp4",
Resubmit: true,
SendReplies: true,
Spoiler: false,
Subreddit: "subreddit",
Title: "video from local path",
ThumbnailPath: "https://host.com/image.jpeg",
}
name, err := reddit.PostVideo(context.Background(), req)
if err != nil {
fmt.Println(err)
}
```
Post video from link with thumbnail image from local path
```go
req := redmed.PostVideoRequest{
Kind: "video", // or videogif for silent video
NSWF: false,
VideoPath: "https://host.com/video.mp4",
Resubmit: true,
SendReplies: true,
Spoiler: false,
Subreddit: "subreddit",
Title: "video from link",
ThumbnailPath: "/path/to/image.jpeg",
}
name, err := reddit.PostVideo(context.Background(), req)
if err != nil {
fmt.Println(err)
}
```
The `name` returned from submitting posts is the *fullname* of the post, such as `t3_x2dx7f`.