Fetching tags by filename
This commit is contained in:
parent
404840f3b9
commit
3e94eb51d2
32
main.go
32
main.go
@ -4,6 +4,8 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"path"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"./pixiv"
|
"./pixiv"
|
||||||
)
|
)
|
||||||
@ -64,6 +66,13 @@ func main() {
|
|||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(cmdline.setTagsFile) > 0 {
|
||||||
|
err := setTagsFile(cmdline.setTagsFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s\n", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchFollows(userID string) (err error) {
|
func fetchFollows(userID string) (err error) {
|
||||||
@ -111,6 +120,20 @@ func fetchBookmarks(userID string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setTagsFile(filename string) (err error) {
|
||||||
|
if ok, id := pix.TypicalFilenamesMatcher(path.Base(filename)); ok {
|
||||||
|
illust, err := pix.GetIllust(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = syscall.Setxattr(filename, "user.xdg.tags", []byte(illust.TagsString()), 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func fetchIllusts(userID string) (err error) {
|
func fetchIllusts(userID string) (err error) {
|
||||||
illusts, err := pix.GetUserIllustsID(userID)
|
illusts, err := pix.GetUserIllustsID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -140,6 +163,13 @@ func fetchIllusts(userID string) (err error) {
|
|||||||
pix.DownloadChannel <- illust
|
pix.DownloadChannel <- illust
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(cmdline.setTagsFile) > 0 {
|
||||||
|
err = setTagsFile(cmdline.setTagsFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Request error or ID not recognized: %s\n", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +187,7 @@ func flags() {
|
|||||||
flag.BoolVar(&cmdline.test, "test", false, "test")
|
flag.BoolVar(&cmdline.test, "test", false, "test")
|
||||||
flag.StringVar(&cmdline.logErrorsFile, "log-errors", "", "file to strore failed items")
|
flag.StringVar(&cmdline.logErrorsFile, "log-errors", "", "file to strore failed items")
|
||||||
flag.IntVar(&cmdline.threads, "threads", 1, "threads number")
|
flag.IntVar(&cmdline.threads, "threads", 1, "threads number")
|
||||||
flag.StringVar(&cmdline.setTagsFile, "set-xattr-file", "", "[WIP] fetch illustration's tags and write them to xattrs of the specified file. Filename SHOULD be in following formats: <illust_id>_p<page_number>.<file_ext>, illust_<illust_id>_*")
|
flag.StringVar(&cmdline.setTagsFile, "set-xattr-file", "", "fetch illustration's tags and write them to xattrs of the specified file.")
|
||||||
flag.BoolVar(&cmdline.setXAttrTags, "set-xattr", false, "also write tags to xattrs")
|
flag.BoolVar(&cmdline.setXAttrTags, "set-xattr", false, "also write tags to xattrs")
|
||||||
flag.StringVar(&cmdline.testString, "test-string", "", "used for testing purposes")
|
flag.StringVar(&cmdline.testString, "test-string", "", "used for testing purposes")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
Loading…
Reference in New Issue
Block a user