Update downloader.go, pixiv.go, and types.go
This commit is contained in:
parent
acf352d459
commit
b3ca71d477
@ -20,13 +20,6 @@ type artwork struct {
|
||||
files []artworkFile
|
||||
}
|
||||
|
||||
func (a *artwork) tagsToString() (r string) {
|
||||
for _, tag := range a.tags {
|
||||
r = fmt.Sprintf("%s,%s", r, tag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getExtension(fullpath string) (ext string) {
|
||||
parts := strings.Split(fullpath, ".")
|
||||
ext = parts[len(parts)-1]
|
||||
@ -43,17 +36,6 @@ func (p *Pixiv) downloadIllust(i Illust) (err error) {
|
||||
}
|
||||
|
||||
var art artwork
|
||||
for _, tag := range i.Tags.Tags {
|
||||
if len(tag.Translation.En) > 0 {
|
||||
art.tags = append(art.tags, tag.Translation.En)
|
||||
} else if len(tag.Romaji) > 0 {
|
||||
art.tags = append(art.tags, tag.Romaji)
|
||||
} else {
|
||||
art.tags = append(art.tags, tag.Tag)
|
||||
}
|
||||
}
|
||||
art.tags = append(art.tags, i.UserName)
|
||||
art.tags = append(art.tags, fmt.Sprintf("pixiv_id_%s", i.UserID))
|
||||
|
||||
for pageNumber, page := range i.Pages {
|
||||
directory := fmt.Sprintf("%s/%s_%s/", p.WorkDirectory, i.UserID, i.UserAccount)
|
||||
@ -80,7 +62,7 @@ func (p *Pixiv) downloadIllust(i Illust) (err error) {
|
||||
return err
|
||||
}
|
||||
if p.setxattr {
|
||||
err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(art.tagsToString()), 0)
|
||||
err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(i.TagsString()), 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -102,6 +102,17 @@ func (p *Pixiv) GetIllust(illustID string) (r Illust, err error) {
|
||||
page.Height = r.Height
|
||||
r.Pages = append(r.Pages, page)
|
||||
}
|
||||
for _, tag := range r.Tags.Tags {
|
||||
if len(tag.Translation.En) > 0 {
|
||||
r.stringTags = append(r.stringTags, tag.Translation.En)
|
||||
} else if len(tag.Romaji) > 0 {
|
||||
r.stringTags = append(r.stringTags, tag.Romaji)
|
||||
} else {
|
||||
r.stringTags = append(r.stringTags, tag.Tag)
|
||||
}
|
||||
}
|
||||
r.stringTags = append(r.stringTags, r.UserName)
|
||||
r.stringTags = append(r.stringTags, fmt.Sprintf("pixiv_id_%s", r.UserID))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package pixiv
|
||||
|
||||
import "fmt"
|
||||
|
||||
//Illust .
|
||||
type Illust struct {
|
||||
complited bool
|
||||
@ -27,6 +29,7 @@ type Illust struct {
|
||||
Tags []IllustTag `json:"tags"`
|
||||
Writable bool `json:"writable"`
|
||||
} `json:"tags,omitempty"`
|
||||
stringTags []string
|
||||
UserID string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
UserAccount string `json:"userAccount"`
|
||||
@ -46,6 +49,14 @@ type Illust struct {
|
||||
ProfileImageURL string `json:"profileImageUrl"`
|
||||
}
|
||||
|
||||
// TagsString returns tags in one string separated by "," character
|
||||
func (i *Illust) TagsString() (r string) {
|
||||
for _, tag := range i.stringTags {
|
||||
r = fmt.Sprintf("%s,%s", r, tag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//IllustTag .
|
||||
type IllustTag struct {
|
||||
Tag string `json:"tag"`
|
||||
|
Loading…
Reference in New Issue
Block a user