Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
ac9cbad6d8 |
@@ -1 +0,0 @@
|
|||||||
package downloader
|
|
@@ -1,81 +0,0 @@
|
|||||||
package gelbooru
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type API struct {
|
|
||||||
apiKey string
|
|
||||||
userID string
|
|
||||||
httpClient http.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
apiEndpoint = "https://gelbooru.com/index.php"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newRequest(params map[string]string) (r *http.Request, err error) {
|
|
||||||
if _, ok := params["page"]; !ok {
|
|
||||||
params["page"] = "dapi"
|
|
||||||
}
|
|
||||||
if _, ok := params["s"]; !ok {
|
|
||||||
params["s"] = "post"
|
|
||||||
}
|
|
||||||
if _, ok := params["q"]; !ok {
|
|
||||||
params["s"] = "index"
|
|
||||||
}
|
|
||||||
if _, ok := params["json"]; !ok {
|
|
||||||
params["json"] = "1"
|
|
||||||
}
|
|
||||||
var addr string
|
|
||||||
for name, value := range params {
|
|
||||||
if len(addr) == 0 {
|
|
||||||
addr = fmt.Sprintf("%s?%s=%s", addr, name, value)
|
|
||||||
} else {
|
|
||||||
addr = fmt.Sprintf("%s&%s=%s", addr, name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addr = fmt.Sprintf("%s%s", apiEndpoint, addr)
|
|
||||||
|
|
||||||
r, err = http.NewRequest(http.MethodGet, addr, nil)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("newRequest: %s", err.Error())
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(userID string, APIKey string) (a API) {
|
|
||||||
a.userID = userID
|
|
||||||
a.apiKey = APIKey
|
|
||||||
a.httpClient = http.Client{
|
|
||||||
Transport: nil,
|
|
||||||
CheckRedirect: nil,
|
|
||||||
Jar: nil,
|
|
||||||
Timeout: time.Second * 30,
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *API) Search(querry string) (p []Post, err error) {
|
|
||||||
req, err := newRequest(map[string]string{"tags": querry})
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("Search: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp, err := a.httpClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("Search: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
err = json.Unmarshal(body, &p)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("Search: %s", err.Error())
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
@@ -1,47 +0,0 @@
|
|||||||
package gelbooru
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
type Post struct {
|
|
||||||
Change int `json:"change"`
|
|
||||||
CreatedAt string `json:"created_at"`
|
|
||||||
Directory string `json:"directory"`
|
|
||||||
FileURL string `json:"file_url"`
|
|
||||||
Hash string `json:"hash"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
Width int `json:"width"`
|
|
||||||
ID int `json:"id"`
|
|
||||||
Image string `json:"image"`
|
|
||||||
Owner string `json:"owner"`
|
|
||||||
ParentID string `json:"parent_id"`
|
|
||||||
PreviewHeight int `json:"preview_height"`
|
|
||||||
PreviewWidth int `json:"preview_width"`
|
|
||||||
Rating string `json:"raiting"`
|
|
||||||
Sample int `json:"sample"`
|
|
||||||
SampleHeight int `json:"sample_height"`
|
|
||||||
SampleWidth int `json:"sample_width"`
|
|
||||||
Score int `json:"score"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
TagsOriginal string `json:"tags"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Post) Name() string {
|
|
||||||
return p.Title
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Post) Author() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Post) Comment() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Post) Tags() []string {
|
|
||||||
return strings.Split(p.TagsOriginal, " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Post) Files() []string {
|
|
||||||
return []string{p.FileURL}
|
|
||||||
}
|
|
10
go.mod
Normal file
10
go.mod
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
module git.magicalmirro.red/voice/pixiv-scrapper
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
h12.io/socks v1.0.2
|
||||||
|
git.magicalmirro.red/voice/pixiv-scrapper/pixiv v0.0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
replace git.magicalmirro.red/voice/pixiv-scrapper/pixiv => ./pixiv
|
6
go.sum
Normal file
6
go.sum
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
github.com/h12w/go-socks5 v0.0.0-20200522160539-76189e178364 h1:5XxdakFhqd9dnXoAZy1Mb2R/DZ6D1e+0bGC/JhucGYI=
|
||||||
|
github.com/h12w/go-socks5 v0.0.0-20200522160539-76189e178364/go.mod h1:eDJQioIyy4Yn3MVivT7rv/39gAJTrA7lgmYr8EW950c=
|
||||||
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
||||||
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
|
||||||
|
h12.io/socks v1.0.2 h1:cZhhbV8+DE0Y1kotwhr1a3RC3kFO7AtuZ4GLr3qKSc8=
|
||||||
|
h12.io/socks v1.0.2/go.mod h1:AIhxy1jOId/XCz9BO+EIgNL2rQiPTBNnOfnVnQ+3Eck=
|
14
main.go
14
main.go
@@ -7,8 +7,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"./gelbooru"
|
"git.magicalmirro.red/voice/pixiv-scrapper/pixiv"
|
||||||
"./pixiv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdlineT struct {
|
type cmdlineT struct {
|
||||||
@@ -74,17 +73,6 @@ func main() {
|
|||||||
fmt.Printf("%s\n", err.Error())
|
fmt.Printf("%s\n", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cmdline.testString) > 0 {
|
|
||||||
gAPI := gelbooru.New("", "")
|
|
||||||
posts, err := gAPI.Search(cmdline.testString)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
for _, post := range posts {
|
|
||||||
fmt.Println(post)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchFollows(userID string) (err error) {
|
func fetchFollows(userID string) (err error) {
|
||||||
|
5
pixiv/go.mod
Normal file
5
pixiv/go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module git.magicalmirro.red/voice/pixiv-scrapper/pixiv
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require h12.io/socks v1.0.2
|
6
pixiv/go.sum
Normal file
6
pixiv/go.sum
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
github.com/h12w/go-socks5 v0.0.0-20200522160539-76189e178364 h1:5XxdakFhqd9dnXoAZy1Mb2R/DZ6D1e+0bGC/JhucGYI=
|
||||||
|
github.com/h12w/go-socks5 v0.0.0-20200522160539-76189e178364/go.mod h1:eDJQioIyy4Yn3MVivT7rv/39gAJTrA7lgmYr8EW950c=
|
||||||
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
||||||
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
|
||||||
|
h12.io/socks v1.0.2 h1:cZhhbV8+DE0Y1kotwhr1a3RC3kFO7AtuZ4GLr3qKSc8=
|
||||||
|
h12.io/socks v1.0.2/go.mod h1:AIhxy1jOId/XCz9BO+EIgNL2rQiPTBNnOfnVnQ+3Eck=
|
@@ -102,7 +102,7 @@ func (p *Pixiv) GetIllust(illustID string) (r Illust, err error) {
|
|||||||
page.Height = r.Height
|
page.Height = r.Height
|
||||||
r.Pages = append(r.Pages, page)
|
r.Pages = append(r.Pages, page)
|
||||||
}
|
}
|
||||||
for _, tag := range r.TagsOriginal.Tags {
|
for _, tag := range r.Tags.Tags {
|
||||||
if len(tag.Translation.En) > 0 {
|
if len(tag.Translation.En) > 0 {
|
||||||
r.stringTags = append(r.stringTags, tag.Translation.En)
|
r.stringTags = append(r.stringTags, tag.Translation.En)
|
||||||
} else if len(tag.Romaji) > 0 {
|
} else if len(tag.Romaji) > 0 {
|
||||||
|
@@ -13,7 +13,7 @@ type Illust struct {
|
|||||||
IllustType int `json:"illustType"`
|
IllustType int `json:"illustType"`
|
||||||
XRestrict int `json:"xRestrict"`
|
XRestrict int `json:"xRestrict"`
|
||||||
Sl int `json:"sl"`
|
Sl int `json:"sl"`
|
||||||
URLoriginal string `json:"url"`
|
URL string `json:"url"`
|
||||||
Pages []IllustPage
|
Pages []IllustPage
|
||||||
URLs struct {
|
URLs struct {
|
||||||
Mini string `json:"mini"`
|
Mini string `json:"mini"`
|
||||||
@@ -23,7 +23,7 @@ type Illust struct {
|
|||||||
Original string `json:"original"`
|
Original string `json:"original"`
|
||||||
} `json:"urls"`
|
} `json:"urls"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
TagsOriginal struct {
|
Tags struct {
|
||||||
AuthorID string `json:"authorId"`
|
AuthorID string `json:"authorId"`
|
||||||
IsLocked bool `json:"isLocked"`
|
IsLocked bool `json:"isLocked"`
|
||||||
Tags []IllustTag `json:"tags"`
|
Tags []IllustTag `json:"tags"`
|
||||||
@@ -57,41 +57,6 @@ func (i *Illust) TagsString() (r string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Illust) Name() string {
|
|
||||||
return i.IllustTitle
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Illust) Author() string {
|
|
||||||
return i.UserName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Illust) Comment() string {
|
|
||||||
return i.IllustComment
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Illust) Tags() []string {
|
|
||||||
return i.stringTags
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Illust) Files() (urls []string) {
|
|
||||||
if len(i.Pages) > 0 {
|
|
||||||
for _, page := range i.Pages {
|
|
||||||
urls = append(urls, page.URLs.Original)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
urls = append(urls, i.URLs.Original)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Illust) URL() string {
|
|
||||||
return i.URLoriginal
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Illust) Type() string {
|
|
||||||
return "pixiv"
|
|
||||||
}
|
|
||||||
|
|
||||||
//IllustTag .
|
//IllustTag .
|
||||||
type IllustTag struct {
|
type IllustTag struct {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
|
37
post/main.go
37
post/main.go
@@ -1,37 +0,0 @@
|
|||||||
package post
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UnifiedPost interface {
|
|
||||||
ID() string
|
|
||||||
Name() string
|
|
||||||
Author() string
|
|
||||||
Comment() string
|
|
||||||
Tags() []string
|
|
||||||
Files() []string
|
|
||||||
URL() string
|
|
||||||
Stringer() string
|
|
||||||
Type() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteAttributes writes info from post to file's metadata
|
|
||||||
func WriteAttributes(filename string, post UnifiedPost) (err error) {
|
|
||||||
var tags string
|
|
||||||
for _, tag := range post.Tags() {
|
|
||||||
tags = fmt.Sprintf("%s,%s", tags, tag)
|
|
||||||
}
|
|
||||||
err = syscall.Setxattr(filename, "user.xdg.tags", []byte(tags), 0)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("WriteAttributes: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = syscall.Setxattr(filename, "user.xdg.comment", []byte(post.Comment()), 0)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("WriteAttributes: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
Reference in New Issue
Block a user