-
Notifications
You must be signed in to change notification settings - Fork 0
/
Douban_qx.js
175 lines (143 loc) · 7.07 KB
/
Douban_qx.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
/*
Douban Movie Add-ons for Quantumult X by Neurogram
- 豆瓣电影移动版网页增强
- 快捷跳转 茶杯狐 搜索
- 展示在映流媒体平台
- 快捷收藏电影至 Airtable
使用说明
【Surge】
[Script]
// 茶杯狐、解析网、555电影
豆瓣电影 = type=http-response,pattern=^https://m.douban.com/movie/subject/.+,requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/githubdulong/Script/master/Douban.js
【quan_x】
[rewrite_local]
// 茶杯狐、解析网、555电影
^https://m.douban.com/movie/subject/.+ url script-response-body https://raw.githubusercontent.com/githubdulong/Script/master/Douban_qx.js
// Airtable 收藏
^https://m.douban.com/movie/subject/.+\?seen=\d url script-request-header Douban.js
[mitm]
hostname = m.douban.com
收藏功能,需自行修改代码,点击 想看 / 看过 触发收藏
Author:
Telegram: Neurogram
GitHub: Neurogram-R
*/
let url = $request.url
let movieId = url.match(/subject\/(\d+)/)
let seen = url.match(/\?seen=(\d)$/)
let collect = false //收藏功能,默认关闭,需自行配置
let region = "US" //流媒体区域
let tmdb_api_key = "" // TMDB API KEY
if (!seen) douban_addons()
if (seen) collect_movie()
async function douban_addons() {
let body = $response.body
let title = body.match(/"sub-title">([^<]+)/)
if (!title) $done({})
if (collect) body = body.replace(/<a.+pbtn.+wish.+>/, `<a href="${url}?seen=0">`)
if (collect) body = body.replace(/<a.+pbtn.+collect.+>/, `<a href="${url}?seen=1">`)
let mweb = [`<a href="https://www.cupfox.com/search?key=${title[1]}">\t<img src="https://raw.githubusercontent.com/githubdulong/Script/master/Images/Chb.png" height="26" width="26" style="vertical-align: text-top;" /></a>`]
mweb.push(`<a href="https://z1.m1907.cn/?jx=wd=${title[1]}&submit="><img src="https://raw.githubusercontent.com/githubdulong/Script/master/Images/Jxw.png" height="26" width="26" style="vertical-align: text-top;" /></a>`)
mweb.push(`<a href="https://www.o8tv.com/vodsearch/-------------.html?wd=${title[1]}&submit="><img src="https://raw.githubusercontent.com/githubdulong/Script/master/Images/555.png" height="26" width="26" style="vertical-align: text-top;" /></a>`)
let douban_options = {
url: `https://frodo.douban.com/api/v2/movie/${movieId[1]}?apiKey=0ac44ae016490db2204ce0a042db2916`,
method: "GET",
headers: {
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.3(0x18000323) NetType/WIFI Language/en",
"Referer": "https://servicewechat.com/wx2f9b06c1de1ccfca/82/page-frame.html"
}
}
let douban_result = await send_request(douban_options)
if ((douban_result.type == "movie" || douban_result.type == "tv") && douban_result.original_title && tmdb_api_key) {
let tbdb_query_options = {
url: `https://api.themoviedb.org/3/search/${douban_result.type}?api_key=${tmdb_api_key}&query=${encodeURIComponent(douban_result.original_title.replace(/Season \d+$/, ""))}&page=1`,
method: "GET"
}
let tmdb_query = await send_request(tbdb_query_options)
if (tmdb_query.results[0]) {
let providers_query_options = {
url: `https://api.themoviedb.org/3/${douban_result.type}/${tmdb_query.results[0].id}/watch/providers?api_key=${tmdb_api_key}`,
method: "GET"
}
let tmdb_providers = await send_request(providers_query_options)
if (tmdb_providers.results[region]) {
if (tmdb_providers.results[region].flatrate) {
for (var i in tmdb_providers.results[region].flatrate) {
mweb.push(`<a href=""><img src="https://image.tmdb.org/t/p/original${tmdb_providers.results[region].flatrate[i].logo_path}" height="25" width="25" style="vertical-align: text-top;" /></a>`)
}
}
}
}
}
body = body.replace(/("sub-title">.+?)(<\/div>)/, `$1${mweb.join("\n")}$2`)
$done({ body })
}
async function collect_movie() {
if ($response) $done({})
let options = {
url: `https://frodo.douban.com/api/v2/movie/${movieId[1]}?apiKey=0ac44ae016490db2204ce0a042db2916`,
method: "GET",
headers: {
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.3(0x18000323) NetType/WIFI Language/en",
"Referer": "https://servicewechat.com/wx2f9b06c1de1ccfca/82/page-frame.html"
}
}
let douban_result = await send_request(options)
if (douban_result.msg == "movie_not_found") {
$notify('豆瓣电影', data.msg, "");
$done({ path: url.replace(/https:\/\/m.douban.com|\/\?seen=\d/g, "") })
}
let casts = ""
for (var i = 0; i < douban_result.actors.length; i++) {
casts = casts + douban_result.actors[i].name + " / "
}
let directors = ""
for (var k = 0; k < douban_result.directors.length; k++) {
directors = directors + douban_result.directors[k].name + " / "
}
let title = douban_result.title + " " + douban_result.original_title
let table = {
url: "https://api.airtable.com/v0/BASE_ID/Douban",
method: "POST",
headers: {
Authorization: "Bearer API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
records: [
{
"fields": {
"Title": title,
"Description": douban_result.intro,
"Poster": [
{
"url": douban_result.pic.large
}
],
"Seen": seen[1] == 1 ? true : false,
"Actors": casts.replace(/\s\/\s$/, ""),
"Director": directors.replace(/\s\/\s$/, ""),
"Genre": douban_result.genres.toString(),
"Douban": "https://movie.douban.com/subject/" + movieId[1],
"Rating": douban_result.rating.value,
"Year": douban_result.year
}
}
]
})
}
let airtable_collect = await send_request(table)
if (!airtable_collect.records) {
$notify('收藏失败', airtable_collect.error.type, airtable_collect.error.message);
$done({ path: url.replace(/https:\/\/m.douban.com|\/\?seen=\d/g, "") })
}
$notify('豆瓣电影', title + " 收藏成功", "");
$done({ path: url.replace(/https:\/\/m.douban.com|\/\?seen=\d/g, "") })
}
function send_request(options) {
return new Promise((resolve, reject) => {
$task.fetch(options).then(response => {
resolve(JSON.parse(response.body))
})
})
}