Skip to content

Commit aa1f82d

Browse files
committed
✨ 增加 pixiv 多线程下载与图片缓存
1 parent f7c6d67 commit aa1f82d

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/FloatTech/ZeroBot-Plugin
33
go 1.17
44

55
require (
6-
github.com/FloatTech/AnimeAPI v1.2.4-beta19
6+
github.com/FloatTech/AnimeAPI v1.2.4-beta21
77
github.com/FloatTech/zbputils v1.2.4-beta7
88
github.com/antchfx/htmlquery v1.2.4
99
github.com/corona10/goimagehash v1.0.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/FloatTech/AnimeAPI v1.2.4-beta19 h1:Yz19ppAdx9cZZbrJBEPqon6RNHY1TuCQl7SALFIW1lQ=
2-
github.com/FloatTech/AnimeAPI v1.2.4-beta19/go.mod h1:rhYvzqLH2YTKBOk7DfJsXsdZlnxhpBP3HvctwqlLykM=
1+
github.com/FloatTech/AnimeAPI v1.2.4-beta21 h1:C0CoX6mrEAOEWl1sLUhGBTasvwnwMkEMEGcDI4fps1I=
2+
github.com/FloatTech/AnimeAPI v1.2.4-beta21/go.mod h1:rhYvzqLH2YTKBOk7DfJsXsdZlnxhpBP3HvctwqlLykM=
33
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
44
github.com/FloatTech/zbputils v1.2.4-beta7 h1:DofQTSVEBU1BQnLb4GahNZqsqVqoj4Lu5GDJa2rJW9o=
55
github.com/FloatTech/zbputils v1.2.4-beta7/go.mod h1:mPVpKu2scTyBiitNmzCrxGc9aIKs9rwfb6iqz/+heck=

plugin_lolicon/lolicon.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ func init() {
5454
}
5555
url := json.Get("data.0.urls.original").Str
5656
url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re")
57-
id := json.Get("data.0.pid").String()
58-
m, err := imgpool.NewImage(ctx, id, url)
57+
m, err := imgpool.NewImage(ctx, url[:strings.LastIndex(url, "/")+1], url)
5958
if err == nil {
6059
queue <- m.String()
6160
} else {

plugin_saucenao/searcher.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"github.com/FloatTech/AnimeAPI/ascii2d"
10+
"github.com/FloatTech/AnimeAPI/imgpool"
1011
"github.com/FloatTech/AnimeAPI/pixiv"
1112
"github.com/FloatTech/AnimeAPI/saucenao"
1213
"github.com/sirupsen/logrus"
@@ -49,22 +50,32 @@ func init() { // 插件主体
4950
}
5051
if illust.Pid > 0 {
5152
name := strconv.FormatInt(illust.Pid, 10)
52-
filepath := datapath + name
53-
switch {
54-
case file.IsExist(filepath + ".jpg"):
55-
filepath = "file:///" + filepath + ".jpg"
56-
case file.IsExist(filepath + ".png"):
57-
filepath = "file:///" + filepath + ".png"
58-
case file.IsExist(filepath + ".gif"):
59-
filepath = "file:///" + filepath + ".gif"
60-
default:
61-
filepath = ""
62-
}
63-
if filepath == "" {
64-
logrus.Debug("[sausenao]开始下载", name)
65-
filepath, err = pixiv.Download(illust.ImageUrls, datapath, name)
66-
if err == nil {
67-
filepath = "file:///" + filepath
53+
var imgs message.Message
54+
for i, u := range illust.ImageUrls {
55+
n := name + "_p" + strconv.Itoa(i)
56+
filepath := datapath + n
57+
f := ""
58+
switch {
59+
case file.IsExist(filepath + ".jpg"):
60+
f = filepath + ".jpg"
61+
case file.IsExist(filepath + ".png"):
62+
f = filepath + ".png"
63+
case file.IsExist(filepath + ".gif"):
64+
f = filepath + ".gif"
65+
default:
66+
logrus.Debugln("[sausenao]开始下载", n)
67+
filepath, err = pixiv.Download(u, datapath, n)
68+
if err == nil {
69+
f = filepath
70+
}
71+
}
72+
if f != "" {
73+
m, err := imgpool.NewImage(ctx, n, f)
74+
if err == nil {
75+
imgs = append(imgs, message.Image(m.String()))
76+
} else {
77+
imgs = append(imgs, message.Image("file:///"+f))
78+
}
6879
}
6980
}
7081
txt := message.Text(
@@ -74,9 +85,9 @@ func init() { // 插件主体
7485
"画师ID:", illust.UserId, "\n",
7586
"直链:", "https://pixivel.moe/detail?id=", illust.Pid,
7687
)
77-
if filepath != "" {
88+
if imgs != nil {
7889
// 发送搜索结果
79-
ctx.SendChain(message.Image(filepath), message.Text("\n"), txt)
90+
ctx.Send(append(imgs, message.Text("\n"), txt))
8091
} else {
8192
// 图片下载失败,仅发送文字结果
8293
ctx.SendChain(txt)

plugin_setutime/setu_geter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func download(i *pixiv.Illust, filedir string) /*(string, */ error /*)*/ {
245245
return /*filepath + ".gif",*/ nil
246246
}
247247
// 下载最大分辨率为 1200 的图片
248-
link := i.ImageUrls
248+
link := i.ImageUrls[0]
249249
link = strings.ReplaceAll(link, "img-original", "img-master")
250250
link = strings.ReplaceAll(link, "_p0", "_p0_master1200")
251251
link = strings.ReplaceAll(link, ".png", ".jpg")

0 commit comments

Comments
 (0)