mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✨ 增加 pixiv 多线程下载与图片缓存
This commit is contained in:
parent
f7c6d67428
commit
aa1f82d46f
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/FloatTech/ZeroBot-Plugin
|
|||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/FloatTech/AnimeAPI v1.2.4-beta19
|
github.com/FloatTech/AnimeAPI v1.2.4-beta21
|
||||||
github.com/FloatTech/zbputils v1.2.4-beta7
|
github.com/FloatTech/zbputils v1.2.4-beta7
|
||||||
github.com/antchfx/htmlquery v1.2.4
|
github.com/antchfx/htmlquery v1.2.4
|
||||||
github.com/corona10/goimagehash v1.0.3
|
github.com/corona10/goimagehash v1.0.3
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
|||||||
github.com/FloatTech/AnimeAPI v1.2.4-beta19 h1:Yz19ppAdx9cZZbrJBEPqon6RNHY1TuCQl7SALFIW1lQ=
|
github.com/FloatTech/AnimeAPI v1.2.4-beta21 h1:C0CoX6mrEAOEWl1sLUhGBTasvwnwMkEMEGcDI4fps1I=
|
||||||
github.com/FloatTech/AnimeAPI v1.2.4-beta19/go.mod h1:rhYvzqLH2YTKBOk7DfJsXsdZlnxhpBP3HvctwqlLykM=
|
github.com/FloatTech/AnimeAPI v1.2.4-beta21/go.mod h1:rhYvzqLH2YTKBOk7DfJsXsdZlnxhpBP3HvctwqlLykM=
|
||||||
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
||||||
github.com/FloatTech/zbputils v1.2.4-beta7 h1:DofQTSVEBU1BQnLb4GahNZqsqVqoj4Lu5GDJa2rJW9o=
|
github.com/FloatTech/zbputils v1.2.4-beta7 h1:DofQTSVEBU1BQnLb4GahNZqsqVqoj4Lu5GDJa2rJW9o=
|
||||||
github.com/FloatTech/zbputils v1.2.4-beta7/go.mod h1:mPVpKu2scTyBiitNmzCrxGc9aIKs9rwfb6iqz/+heck=
|
github.com/FloatTech/zbputils v1.2.4-beta7/go.mod h1:mPVpKu2scTyBiitNmzCrxGc9aIKs9rwfb6iqz/+heck=
|
||||||
|
|||||||
@ -54,8 +54,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
url := json.Get("data.0.urls.original").Str
|
url := json.Get("data.0.urls.original").Str
|
||||||
url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re")
|
url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re")
|
||||||
id := json.Get("data.0.pid").String()
|
m, err := imgpool.NewImage(ctx, url[:strings.LastIndex(url, "/")+1], url)
|
||||||
m, err := imgpool.NewImage(ctx, id, url)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
queue <- m.String()
|
queue <- m.String()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/ascii2d"
|
"github.com/FloatTech/AnimeAPI/ascii2d"
|
||||||
|
"github.com/FloatTech/AnimeAPI/imgpool"
|
||||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||||
"github.com/FloatTech/AnimeAPI/saucenao"
|
"github.com/FloatTech/AnimeAPI/saucenao"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -49,22 +50,32 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
if illust.Pid > 0 {
|
if illust.Pid > 0 {
|
||||||
name := strconv.FormatInt(illust.Pid, 10)
|
name := strconv.FormatInt(illust.Pid, 10)
|
||||||
filepath := datapath + name
|
var imgs message.Message
|
||||||
switch {
|
for i, u := range illust.ImageUrls {
|
||||||
case file.IsExist(filepath + ".jpg"):
|
n := name + "_p" + strconv.Itoa(i)
|
||||||
filepath = "file:///" + filepath + ".jpg"
|
filepath := datapath + n
|
||||||
case file.IsExist(filepath + ".png"):
|
f := ""
|
||||||
filepath = "file:///" + filepath + ".png"
|
switch {
|
||||||
case file.IsExist(filepath + ".gif"):
|
case file.IsExist(filepath + ".jpg"):
|
||||||
filepath = "file:///" + filepath + ".gif"
|
f = filepath + ".jpg"
|
||||||
default:
|
case file.IsExist(filepath + ".png"):
|
||||||
filepath = ""
|
f = filepath + ".png"
|
||||||
}
|
case file.IsExist(filepath + ".gif"):
|
||||||
if filepath == "" {
|
f = filepath + ".gif"
|
||||||
logrus.Debug("[sausenao]开始下载", name)
|
default:
|
||||||
filepath, err = pixiv.Download(illust.ImageUrls, datapath, name)
|
logrus.Debugln("[sausenao]开始下载", n)
|
||||||
if err == nil {
|
filepath, err = pixiv.Download(u, datapath, n)
|
||||||
filepath = "file:///" + filepath
|
if err == nil {
|
||||||
|
f = filepath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if f != "" {
|
||||||
|
m, err := imgpool.NewImage(ctx, n, f)
|
||||||
|
if err == nil {
|
||||||
|
imgs = append(imgs, message.Image(m.String()))
|
||||||
|
} else {
|
||||||
|
imgs = append(imgs, message.Image("file:///"+f))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
txt := message.Text(
|
txt := message.Text(
|
||||||
@ -74,9 +85,9 @@ func init() { // 插件主体
|
|||||||
"画师ID:", illust.UserId, "\n",
|
"画师ID:", illust.UserId, "\n",
|
||||||
"直链:", "https://pixivel.moe/detail?id=", illust.Pid,
|
"直链:", "https://pixivel.moe/detail?id=", illust.Pid,
|
||||||
)
|
)
|
||||||
if filepath != "" {
|
if imgs != nil {
|
||||||
// 发送搜索结果
|
// 发送搜索结果
|
||||||
ctx.SendChain(message.Image(filepath), message.Text("\n"), txt)
|
ctx.Send(append(imgs, message.Text("\n"), txt))
|
||||||
} else {
|
} else {
|
||||||
// 图片下载失败,仅发送文字结果
|
// 图片下载失败,仅发送文字结果
|
||||||
ctx.SendChain(txt)
|
ctx.SendChain(txt)
|
||||||
|
|||||||
@ -245,7 +245,7 @@ func download(i *pixiv.Illust, filedir string) /*(string, */ error /*)*/ {
|
|||||||
return /*filepath + ".gif",*/ nil
|
return /*filepath + ".gif",*/ nil
|
||||||
}
|
}
|
||||||
// 下载最大分辨率为 1200 的图片
|
// 下载最大分辨率为 1200 的图片
|
||||||
link := i.ImageUrls
|
link := i.ImageUrls[0]
|
||||||
link = strings.ReplaceAll(link, "img-original", "img-master")
|
link = strings.ReplaceAll(link, "img-original", "img-master")
|
||||||
link = strings.ReplaceAll(link, "_p0", "_p0_master1200")
|
link = strings.ReplaceAll(link, "_p0", "_p0_master1200")
|
||||||
link = strings.ReplaceAll(link, ".png", ".jpg")
|
link = strings.ReplaceAll(link, ".png", ".jpg")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user