support new e621 API, GH Action changes

This commit is contained in:
TJ Horner 2020-04-23 18:37:01 -04:00
parent 9a8b55999b
commit 9016498640
4 changed files with 116 additions and 40 deletions

View File

@ -7,10 +7,10 @@ jobs:
name: Build and publish name: Build and publish
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Go 1.13 - name: Set up Go 1.14
uses: actions/setup-go@v1 uses: actions/setup-go@v1
with: with:
go-version: 1.13 go-version: 1.14
id: go id: go
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -21,6 +21,12 @@ jobs:
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o ./e6dl-windows-amd64.exe . GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o ./e6dl-windows-amd64.exe .
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o ./e6dl-darwin-amd64 . GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o ./e6dl-darwin-amd64 .
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ./e6dl-linux-amd64 . GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ./e6dl-linux-amd64 .
- name: Compress binaries with upx
run: |
sudo apt-get install upx
upx e6dl-windows-amd64.exe
upx e6dl-darwin-amd64
upx e6dl-linux-amd64
- name: Upload binaries - name: Upload binaries
uses: skx/github-action-publish-binaries@release-1.3 uses: skx/github-action-publish-binaries@release-1.3
env: env:

View File

@ -96,7 +96,7 @@ func work(wn int, state *workState, wc chan *e621.Post) {
progress, progress,
workerText, workerText,
post.ID, post.ID,
humanize.Bytes(uint64(post.FileSize)), humanize.Bytes(uint64(post.File.Size)),
getSavePath(post, &state.SaveDirectory), getSavePath(post, &state.SaveDirectory),
)) ))
@ -114,14 +114,14 @@ func work(wn int, state *workState, wc chan *e621.Post) {
} }
func getSavePath(post *e621.Post, directory *string) string { func getSavePath(post *e621.Post, directory *string) string {
savePath := path.Join(*directory, strconv.Itoa(post.ID)+"."+post.FileExt) savePath := path.Join(*directory, strconv.Itoa(post.ID)+"."+post.File.Ext)
return savePath return savePath
} }
func downloadPost(post *e621.Post, directory string) error { func downloadPost(post *e621.Post, directory string) error {
savePath := getSavePath(post, &directory) savePath := getSavePath(post, &directory)
resp, err := e621.HTTPGet(post.FileURL) resp, err := e621.HTTPGet(post.File.URL)
if err != nil { if err != nil {
return err return err
} }

View File

@ -8,37 +8,104 @@ import (
"time" "time"
) )
// Post represents an e621 post object returned by the e621 API. type PostFile struct {
Width int `json:"width"`
Height int `json:"height"`
Ext string `json:"ext"`
Size int `json:"size"`
Md5 string `json:"md5"`
URL string `json:"url"`
}
type PostPreview struct {
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url"`
}
type PostSample struct {
Has bool `json:"has"`
Height int `json:"height"`
Width int `json:"width"`
URL string `json:"url"`
}
type PostScore struct {
Up int `json:"up"`
Down int `json:"down"`
Total int `json:"total"`
}
type PostTags struct {
General []string `json:"general"`
Species []string `json:"species"`
Character []string `json:"character"`
Copyright []string `json:"copyright"`
Artist []string `json:"artist"`
Invalid []string `json:"invalid"`
Lore []string `json:"lore"`
Meta []string `json:"meta"`
}
func (t *PostTags) All() []string {
allTags := []string{}
groups := [][]string{
t.General,
t.Species,
t.Character,
t.Copyright,
t.Artist,
t.Invalid,
t.Lore,
t.Meta,
}
for _, g := range groups {
allTags = append(allTags, g...)
}
return allTags
}
type PostFlags struct {
Pending bool `json:"pending"`
Flagged bool `json:"flagged"`
NoteLocked bool `json:"note_locked"`
StatusLocked bool `json:"status_locked"`
RatingLocked bool `json:"rating_locked"`
Deleted bool `json:"deleted"`
}
type PostRelationships struct {
ParentID int `json:"parent_id"`
HasChildren bool `json:"has_children"`
HasActiveChildren bool `json:"has_active_children"`
Children []int `json:"children"`
}
type Post struct { type Post struct {
ID int `json:"id"` // The ID of the post ID int `json:"id"`
Tags string `json:"tags"` // Space-separated list of tags attached to this post CreatedAt string `json:"created_at"`
LockedTags bool `json:"locked_tags"` // (undocumented) UpdatedAt string `json:"updated_at"`
Description string `json:"description"` // The post's description File PostFile `json:"file"`
CreatedAt SerializedDate `json:"created_at"` // When the post was uploaded Preview PostPreview `json:"preview"`
CreatorID int `json:"creator_id"` // User ID of the user who uploaded the post Sample PostSample `json:"sample"`
Author string `json:"author"` // Username of the user who uploaded the post Score PostScore `json:"score"`
Change int `json:"change"` // (undocumented) Tags PostTags `json:"tags"`
Source string `json:"source"` // URL that the source for this post can be found at LockedTags []string `json:"locked_tags"`
Score int `json:"score"` // The post's score (upvotes - downvotes) ChangeSeq int `json:"change_seq"`
FavoritesCount int `json:"fav_count"` // Amount of users that favorited this post Flags PostFlags `json:"flags"`
MD5Hash string `json:"md5"` // MD5-sum of the post's file's content Rating string `json:"rating"`
FileSize int `json:"file_size"` // Size of the post's file FavCount int `json:"fav_count"`
FileURL string `json:"file_url"` // URL to the full-sized file Sources []string `json:"sources"`
FileExt string `json:"file_ext"` // File extension Pools []int `json:"pools"`
PreviewURL string `json:"preview_url"` // URL to preview-sized version of the file Relationships PostRelationships `json:"relationships"`
PreviewHeight int `json:"preview_height"` // Height of the preview ApproverID int `json:"approver_id"`
PreviewWidth int `json:"preview_width"` // Width of the preview UploaderID int `json:"uploader_id"`
Rating string `json:"rating"` // Rating of the file ("safe", "questionable", "explicit") Description string `json:"description"`
Status string `json:"status"` // Moderation status ("active" or "pending") CommentCount int `json:"comment_count"`
Width int `json:"width"` // Width of the original file IsFavorited bool `json:"is_favorited"`
Height int `json:"height"` // Height of the original file
HasComments bool `json:"has_comments"` // True if post has comments
HasNotes bool `json:"has_notes"` // True if post has notes
HasChildren bool `json:"has_children"` // True if post has children
Children string `json:"children"` // Comma-separated list of children post IDs
ParentID int `json:"parent_id"` // ID of the parent post
Artist []string `json:"artist"` // Slice of artist names
Sources []string `json:"sources"` // Slice of source URLs
} }
// SerializedDate represents a serialized date passed via JSON // SerializedDate represents a serialized date passed via JSON
@ -65,7 +132,7 @@ func GetPostsForTags(tags string, limit int, sfw bool, page int) ([]Post, error)
domain = "e621.net" domain = "e621.net"
} }
req, _ := http.NewRequest("GET", "https://"+domain+"/post/index.json", nil) req, _ := http.NewRequest("GET", "https://"+domain+"/posts.json", nil)
req.Header.Set("User-Agent", "e6dl: go edition (@tjhorner on Telegram)") req.Header.Set("User-Agent", "e6dl: go edition (@tjhorner on Telegram)")
qs := req.URL.Query() qs := req.URL.Query()
@ -87,8 +154,11 @@ func GetPostsForTags(tags string, limit int, sfw bool, page int) ([]Post, error)
return nil, err return nil, err
} }
var posts []Post var respBody struct {
json.Unmarshal(body, &posts) Posts []Post
}
return posts, nil json.Unmarshal(body, &respBody)
return respBody.Posts, nil
} }

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/tjhorner/e6dl module github.com/tjhorner/e6dl
go 1.12 go 1.14
require ( require (
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0