Ability to write artwork's tags into file xattrs.
This commit is contained in:
@@ -7,8 +7,32 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type artworkFile struct {
|
||||
directory string
|
||||
filename string
|
||||
url string
|
||||
}
|
||||
type artwork struct {
|
||||
tags []string
|
||||
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]
|
||||
return
|
||||
}
|
||||
|
||||
//DownloadIllust .
|
||||
func (p *Pixiv) downloadIllust(i Illust) (err error) {
|
||||
if !i.Complited() {
|
||||
@@ -17,20 +41,7 @@ func (p *Pixiv) downloadIllust(i Illust) (err error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
getExtension := func(fullpath string) (ext string) {
|
||||
parts := strings.Split(fullpath, ".")
|
||||
ext = parts[len(parts)-1]
|
||||
return
|
||||
}
|
||||
type artworkFile struct {
|
||||
directory string
|
||||
filename string
|
||||
url string
|
||||
}
|
||||
type artwork struct {
|
||||
tags []string
|
||||
files []artworkFile
|
||||
}
|
||||
|
||||
var art artwork
|
||||
for _, tag := range i.Tags.Tags {
|
||||
if len(tag.Translation.En) > 0 {
|
||||
@@ -66,7 +77,12 @@ func (p *Pixiv) downloadIllust(i Illust) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.setxattr {
|
||||
err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(art.tagsToString()), 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -19,16 +19,18 @@ type Pixiv struct {
|
||||
WorkDirectory string
|
||||
logChannel chan string
|
||||
DownloadChannel chan Illust
|
||||
setxattr bool
|
||||
}
|
||||
|
||||
//New returns object with methods to access API functions
|
||||
func New(cookies string, logFilePath string, threads int) (p Pixiv) {
|
||||
func New(cookies string, logFilePath string, threads int, xattrs bool) (p Pixiv) {
|
||||
p.phpsessid = http.Cookie{Name: "PHPSESSID", Value: cookies}
|
||||
p.Ua = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"
|
||||
p.client = &http.Client{}
|
||||
p.RetryCount = 5
|
||||
p.ItemsPerRequest = 100
|
||||
p.WorkDirectory = fmt.Sprintf("%s/Pictures/pixiv", os.Getenv("HOME"))
|
||||
p.setxattr = xattrs
|
||||
if len(logFilePath) > 0 {
|
||||
logfile, err := os.OpenFile(logFilePath, os.O_APPEND, 664)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user