Skip to content

Commit

Permalink
Correct author for some providers (#14)
Browse files Browse the repository at this point in the history
* feat(api): correct author for some providers
* fix(typo): fixed typo in imported packages
* chore(deps): bump mergo version
* feat(provider): updated sankaku channel provider to use api v2
* fix(provider): updated base url for sankaku api v2
  • Loading branch information
leonidboykov authored Feb 7, 2019
1 parent 195a899 commit aa72a3a
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/getmoe/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func saveImage(posts []getmoe.Post, saveDir string, quiet bool) error {
}

if !quiet {
fName, _ := utils.FileURLUnescape(p.FileURL)
fName, _ := helper.FileURLUnescape(p.FileURL)
fmt.Println("Getting", fName[:32], "...")
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/leonidboykov/getmoe

require (
github.com/imdario/mergo v0.3.6
github.com/imdario/mergo v0.3.7
github.com/kr/pretty v0.1.0 // indirect
github.com/urfave/cli v1.20.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
2 changes: 1 addition & 1 deletion internal/helper/unescape.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package helper

import (
"net/url"
Expand Down
2 changes: 1 addition & 1 deletion internal/helper/unescape_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package helper

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion post.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *Post) HasTag(tag string) bool {
func (p *Post) Save(saveDir string) error {
// Getting the actual URL
// TODO: support JPG sources forcing
fileName, err := utils.FileURLUnescape(p.FileURL)
fileName, err := helper.FileURLUnescape(p.FileURL)
if err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions provider/boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ var AvailableBoards = map[string]*getmoe.Board{
URL: getmoe.URLString{URL: url.URL{Host: "danbooru.donmai.us"}},
})),
"chan.sankakucomplex.com": getmoe.NewBoard(sankaku.New(getmoe.ProviderConfiguration{
URL: getmoe.URLString{URL: url.URL{Host: "capi-beta.sankakucomplex.com"}},
URL: getmoe.URLString{URL: url.URL{Host: "capi-v2.sankakucomplex.com"}},
})),
"idol.sankakucomplex.com": getmoe.NewBoard(sankaku.New(getmoe.ProviderConfiguration{
URL: getmoe.URLString{URL: url.URL{Host: "iapi.sankakucomplex.com"}},
URL: getmoe.URLString{URL: url.URL{
Host: "iapi.sankakucomplex.com",
Path: "post/index.json",
}},
})),
}
2 changes: 1 addition & 1 deletion provider/danbooru/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ type Post struct {
}

func (p *Post) parseTags() []string {
return strings.Split(p.TagStringGeneral, " ")
return strings.Split(p.TagString, " ")
}
22 changes: 18 additions & 4 deletions provider/sankaku/post.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package sankaku

import (
"time"
import "time"

const (
artistTag = 1
companyTag = 2
brandTag = 3
characterTag = 4
)

// Post contains native Sankaku data
Expand All @@ -20,8 +25,8 @@ type Post struct {
Change int `json:"change"`
HasNotes bool `json:"has_notes"`
Source string `json:"source"`
Author string `json:"author"`
CreatedAt struct {
// Author string `json:"author"`
CreatedAt struct {
N int `json:"n"`
JSONClass string `json:"json_class"`
S int `json:"s"`
Expand Down Expand Up @@ -54,6 +59,15 @@ func (p *Post) parseTags() []string {
return result
}

func (p *Post) findArtist() string {
for i := range p.Tags {
if p.Tags[i].Type == artistTag {
return p.Tags[i].Name
}
}
return ""
}

func (p *Post) parseTime() time.Time {
return time.Unix(int64(p.CreatedAt.S), 0)
}
10 changes: 3 additions & 7 deletions provider/sankaku/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import (
"github.com/leonidboykov/getmoe/internal/query"
)

const (
defaultPasswordSalt = "choujin-steiner--%s--"
defaultPostsLimit = 100
)

const (
loginKey = "login"
passwordHashKey = "password_hash"
Expand All @@ -34,7 +29,8 @@ const (
var defaultProvider = &Provider{
URL: &url.URL{
Scheme: "https",
Path: "post/index.json",
// Path: "post/index.json",
Path: "posts",
},
Headers: map[string]string{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
Expand Down Expand Up @@ -132,7 +128,7 @@ func (p *Provider) Parse(data []byte) ([]getmoe.Post, error) {
Width: page[i].Width,
Height: page[i].Height,
CreatedAt: page[i].parseTime(),
Author: page[i].Author,
Author: page[i].findArtist(),
Source: page[i].Source,
Rating: page[i].Rating,
Hash: page[i].Md5,
Expand Down

0 comments on commit aa72a3a

Please sign in to comment.