-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmovie.js
More file actions
51 lines (51 loc) · 1.58 KB
/
Copy pathmovie.js
File metadata and controls
51 lines (51 loc) · 1.58 KB
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
const params = getParams($argument);
const url = "https://movie.douban.com/cinema/nowplaying/suzhou/";
$httpClient.get(url, function (error, response, data) {
if (error) {
console.log("请求失败:", error);
$done();
return;
}
const movieData = extractMovieData(data);
const movieTitles = movieData.titles.slice(0, 9);
const movieScores = movieData.scores.slice(0, 9);
const movieActors = movieData.actors.slice(0, 9);
let panelContent = "";
for (let i = 0; i < movieTitles.length; i++) {
const score = movieScores[i] === "0" ? "暂无" : movieScores[i];
const actors = movieActors[i] || "暂无";
panelContent += "🎞️"+movieTitles[i] + "-" + actors+ "🍿" + score + "\n";
}
const body = {
title: "热映电影&评分",
content: panelContent,
icon: params.icon,
"icon-color": params.color
};
$done(body);
});
function extractMovieData(html) {
const pattern = /data-title="(.*?)"\s+data-score="(.*?)"[^>]+data-actors="(.*?)"/g;
let matches;
const titles = [];
const scores = [];
const actors = [];
while ((matches = pattern.exec(html)) !== null) {
const title = matches[1].trim();
const score = matches[2].trim();
const actorData = matches[3].trim();
const actorList = actorData.split(" / ");
titles.push(title);
scores.push(score);
actors.push(actorList);
}
return { titles: titles, scores: scores, actors: actors };
}
function getParams(param) {
return Object.fromEntries(
param
.split("&")
.map((item) => item.split("="))
.map(([k, v]) => [k, decodeURIComponent(v)])
);
}