-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSouFanDrama.js
178 lines (156 loc) · 6.22 KB
/
SouFanDrama.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import plugin from '../../lib/plugins/plugin.js'
import fetch from 'node-fetch'
import fs from 'node:fs'
import {
segment
} from 'oicq'
const _path = `./soufanvideo/`
//项目路径
const _cwdpath = process.cwd();
if (!fs.existsSync(_path)) {
fs.mkdirSync(_path);
}
let minsim = 0.90; //#匹配度,0.90以下的可能会不太准
export class fjSearch extends plugin {
constructor() {
super({
/** 功能名称 */
name: '搜番剧',
/** 功能描述 */
dsc: '通过番剧截图搜索番名及信息',
/** https://oicqjs.github.io/oicq/#events */
event: 'message',
/** 优先级,数字越小等级越高 */
priority: 1001,
rule: [{
/** 命令正则匹配 */
reg: '#*搜番$',
/** 执行方法 */
fnc: 'fjsearch'
}]
})
}
/**
*
* @param e oicq传递的事件参数e
*/
async fjsearch(e) {
if (this.e.source) {
let reply;
if (this.e.isGroup) {
reply = (await this.e.group.getChatHistory(this.e.source.seq, 1)).pop()?.message;
} else {
reply = (await this.e.friend.getChatHistory(this.e.source.time, 1)).pop()?.message;
}
if (reply) {
for (let val of reply) {
if (val.type == "image") {
this.e.img = [val.url];
break;
}
}
}
}
if (!this.e.img) {
this.setContext('dealImg');
await this.reply(" 请发送动漫番剧截图", false, {
at: true
});
} else {
this.dealImg();
}
}
async dealImg() {
if (!this.e.img) {
return true;
}
let responseImage = await fetch(this.e.img[0]);
if (!responseImage.ok) {
await this.reply("获取番剧图片失败", false, {
at: true
});
}
let buffer = await responseImage.arrayBuffer();
let headers = {
"Content-Type": "image/jpeg"
};
let file = Buffer.from(buffer, 'binary');
let urlapi = "https://api.trace.moe/search?anilistInfo=&cutBorders=";
let response = await fetch(urlapi, {
method: "POST",
body: file,
headers
});
let res = await response.json();
if (res.result.length == 0) {
await this.reply('未找到相关番剧,此搜索引擎对截图尺寸和质量要求比较高,不支持以下类型截图识别:\n1、有额外添加的黑边\n2、裁切过的不完整截图\n3、左右翻转的\n4、经过滤镜处理的\n5、加了文字的表情包\n6、1990年之前的动画\n7、非正式发行的动画,即同人插图等\n8、非日本动画\n9、画面过暗的\n10、分辨率过低的(须大于 320x180)');
this.finish('dealImg');
return true;
}
let resultall = res.result[0];
let formtime = resultall.from;
if (resultall.similarity.toFixed(4) < minsim) {
await this.reply('未找到相关番剧,此搜索引擎对截图尺寸和质量要求比较高,不支持以下类型截图识别:\n1、有额外添加的黑边\n2、裁切过的不完整截图\n3、左右翻转的\n4、经过滤镜处理的\n5、加了文字的表情包\n6、1990年之前的动画\n7、非正式发行的动画,即同人插图等\n8、非日本动画\n9、画面过暗的\n10、分辨率过低的(须大于 320x180)');
this.finish('dealImg');
return true;
}
let synonyms = "";
for (const key in resultall.anilist.synonyms) {
synonyms += resultall.anilist.synonyms[key] + "、";
}
let details = await this.getDetails(resultall.anilist.id);
let end = "";
if (details.status != "FINISHED") {
end = "未完结";
} else {
end = details.endDate.year + "年" + details.endDate.month + "月" + details.endDate.day + "日";
}
let fengmian;
if (!resultall.anilist.isAdult) {
fengmian = details.coverImage.large;
}
let msg = [
fengmian ? segment.image(fengmian) : "",
"\n番名:" + resultall.anilist.title.native + "\n",
resultall.anilist.title.romaji + "\n",
"别名:" + synonyms + "\n",
`类型:${details.type} - ${details.format}` + ` 共${details.episodes}集\n`,
"开播时间:" + details.startDate.year + "年" + details.startDate.month + "月" + details.startDate.day + "日 - " + end + "\n",
"相似度:" + resultall.similarity.toFixed(4) * 100 + "%\n",
"该截图出自第" + resultall.episode + "集" + Math.floor(formtime % 3600 / 60) + "分" + Math.floor(formtime % 60) + "秒"
];
await this.e.reply(msg);
if (!resultall.video) {
return true;
}
console.log(_cwdpath);
let url = resultall.video;
response = await fetch(url);
let buff = await response.arrayBuffer();
var me = this;
fs.writeFile(`${_path}temp.mp4`, Buffer.from(buff), "binary", async function(err) {
console.log(err || "下载视频成功");
if (!err) {
if (!resultall.anilist.isAdult) {
await me.e.reply(segment.video(`file:///${_cwdpath}/plugins/suiyue/resources/soufanvideo/temp.mp4`));
}
}
});
this.finish('dealImg');
}
async getDetails(id) {
let query = `{Media (id:${id}) {coverImage {large}startDate {year,month,day}endDate {year,month,day}season,seasonYear,type,format,status,episodes}}`;
let url = 'https://graphql.anilist.co';
let response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: query
}),
});
let res = await response.json();
return res.data.Media;
}
}