-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathStream-All.js
More file actions
359 lines (314 loc) · 9.47 KB
/
Copy pathStream-All.js
File metadata and controls
359 lines (314 loc) · 9.47 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
脚本参考 @Helge_0x00
修改日期:2022.12.16
Surge配置参考注释
----------------------------------------
[Panel]
策略面板 = script-name=解锁检测,update-interval=7200
[Script]
解锁检测 = type=generic,timeout=30,script-path=https://raw.githubusercontent.com/githubdulong/Script/master/Stream-All.js,script-update-interval=0,argument=title=解锁检测&icon=headphones.circle&color=#FF2121
----------------------------------------
支持使用脚本使用 argument 参数自定义配置,如:argument=title=解锁检测&icon=headphones.circle&color=#FF2121,具体参数如下所示,
* title: 面板标题
* icon: SFSymbols 图标
* color:图标颜色
*/
let args = getArgs();
const REQUEST_HEADERS = {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',
'Accept-Language': 'en',
}
// 即将登陆
const STATUS_COMING = 2
// 支持解锁
const STATUS_AVAILABLE = 1
// 不支持解锁
const STATUS_NOT_AVAILABLE = 0
// 检测超时
const STATUS_TIMEOUT = -1
// 检测异常
const STATUS_ERROR = -2
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36';
(async () => {
let now = new Date();
let hour = now.getHours();
let minutes = now.getMinutes();
hour = hour > 9 ? hour : "0" + hour;
minutes = minutes > 9 ? minutes : "0" + minutes;
let panel_result = {
title: `${args.title} | ${hour}:${minutes}` || `流媒体解锁查询 | ${hour}:${minutes}`,
content: '',
icon: args.icon || "play.circle",
"icon-color": args.color || "#007aff",
}
let [{ region, status }] = await Promise.all([testDisneyPlus()])
await Promise.all([check_youtube_premium(), check_netflix()])
.then((result) => {
console.log(result)
let disney_result = ""
if (status == STATUS_COMING) {
//console.log(1)
disney_result = "D+: 即将登陆~" + region.toUpperCase()
} else if (status == STATUS_AVAILABLE) {
//console.log(2)
console.log(region)
disney_result = "D+: \u2611" + region.toUpperCase()
// console.log(result["Disney"])
} else if (status == STATUS_NOT_AVAILABLE) {
//console.log(3)
disney_result = "D+: \u2612"
} else if (status == STATUS_TIMEOUT) {
disney_result = "D+: N/A"
}
result.push(disney_result)
console.log(result)
let content = result.join(' ')
console.log(content)
panel_result['content'] = content
})
.finally(() => {
$done(panel_result)
})
})()
function getArgs() {
return Object.fromEntries(
$argument
.split("&")
.map((item) => item.split("="))
.map(([k, v]) => [k, decodeURIComponent(v)])
);
}
async function check_youtube_premium() {
let inner_check = () => {
return new Promise((resolve, reject) => {
let option = {
url: 'https://www.youtube.com/premium',
headers: REQUEST_HEADERS,
}
$httpClient.get(option, function (error, response, data) {
if (error != null || response.status !== 200) {
reject('Error')
return
}
if (data.indexOf('Premium is not available in your country') !== -1) {
resolve('Not Available')
return
}
let region = ''
let re = new RegExp('"countryCode":"(.*?)"', 'gm')
let result = re.exec(data)
if (result != null && result.length === 2) {
region = result[1]
} else if (data.indexOf('www.google.cn') !== -1) {
region = 'CN'
} else {
region = 'US'
}
resolve(region)
})
})
}
let youtube_check_result = 'YT: '
await inner_check()
.then((code) => {
if (code === 'Not Available') {
youtube_check_result += '\u2612 |'
} else {
youtube_check_result += "\u2611" + code.toUpperCase() + ' |'
}
})
.catch((error) => {
youtube_check_result += 'N/A |'
})
return youtube_check_result
}
async function check_netflix() {
let inner_check = (filmId) => {
return new Promise((resolve, reject) => {
let option = {
url: 'https://www.netflix.com/title/' + filmId,
headers: REQUEST_HEADERS,
}
$httpClient.get(option, function (error, response, data) {
if (error != null) {
reject('Error')
return
}
if (response.status === 403) {
reject('Not Available')
return
}
if (response.status === 404) {
resolve('Not Found')
return
}
if (response.status === 200) {
let url = response.headers['x-originating-url']
let region = url.split('/')[3]
region = region.split('-')[0]
if (region == 'title') {
region = 'US'
}
resolve(region)
return
}
reject('Error')
})
})
}
let netflix_check_result = 'NF: '
await inner_check(80062035)
.then((code) => {
if (code === 'Not Found') {
return inner_check(80018499)
}
netflix_check_result += '\u2611' + code.toUpperCase() + ' |'
return Promise.reject('BreakSignal')
})
.then((code) => {
if (code === 'Not Found') {
return Promise.reject('Not Available')
}
netflix_check_result += '⚠' + code.toUpperCase() + ' |'
return Promise.reject('BreakSignal')
})
.catch((error) => {
if (error === 'BreakSignal') {
return
}
if (error === 'Not Available') {
netflix_check_result += '\u2612 |'
return
}
netflix_check_result += 'N/A |'
})
return netflix_check_result
}
async function testDisneyPlus() {
try {
let { region, cnbl } = await Promise.race([testHomePage(), timeout(7000)])
console.log(`homepage: region=${region}, cnbl=${cnbl}`)
// 即将登陆
// if (cnbl == 2) {
// return { region, status: STATUS_COMING }
// }
let { countryCode, inSupportedLocation } = await Promise.race([getLocationInfo(), timeout(7000)])
console.log(`getLocationInfo: countryCode=${countryCode}, inSupportedLocation=${inSupportedLocation}`)
region = countryCode ?? region
console.log("region:" + region)
// 即将登陆
if (inSupportedLocation === false || inSupportedLocation === 'false') {
return { region, status: STATUS_COMING }
} else {
// 支持解锁
return { region, status: STATUS_AVAILABLE }
}
} catch (error) {
console.log("error:" + error)
// 不支持解锁
if (error === 'Not Available') {
console.log("不支持")
return { status: STATUS_NOT_AVAILABLE }
}
// 检测超时
if (error === 'Timeout') {
return { status: STATUS_TIMEOUT }
}
return { status: STATUS_ERROR }
}
}
function getLocationInfo() {
return new Promise((resolve, reject) => {
let opts = {
url: 'https://disney.api.edge.bamgrid.com/graph/v1/device/graphql',
headers: {
'Accept-Language': 'en',
Authorization: 'ZGlzbmV5JmJyb3dzZXImMS4wLjA.Cu56AgSfBTDag5NiRA81oLHkDZfu5L3CKadnefEAY84',
'Content-Type': 'application/json',
'User-Agent': UA,
},
body: JSON.stringify({
query: 'mutation registerDevice($input: RegisterDeviceInput!) { registerDevice(registerDevice: $input) { grant { grantType assertion } } }',
variables: {
input: {
applicationRuntime: 'chrome',
attributes: {
browserName: 'chrome',
browserVersion: '94.0.4606',
manufacturer: 'apple',
model: null,
operatingSystem: 'macintosh',
operatingSystemVersion: '10.15.7',
osDeviceIds: [],
},
deviceFamily: 'browser',
deviceLanguage: 'en',
deviceProfile: 'macosx',
},
},
}),
}
$httpClient.post(opts, function (error, response, data) {
if (error) {
reject('Error')
return
}
if (response.status !== 200) {
console.log('getLocationInfo: ' + data)
reject('Not Available')
return
}
data = JSON.parse(data)
if (data?.errors) {
console.log('getLocationInfo: ' + data)
reject('Not Available')
return
}
let {
token: { accessToken },
session: {
inSupportedLocation,
location: { countryCode },
},
} = data?.extensions?.sdk
resolve({ inSupportedLocation, countryCode, accessToken })
})
})
}
function testHomePage() {
return new Promise((resolve, reject) => {
let opts = {
url: 'https://www.disneyplus.com/',
headers: {
'Accept-Language': 'en',
'User-Agent': UA,
},
}
$httpClient.get(opts, function (error, response, data) {
if (error) {
reject('Error')
return
}
if (response.status !== 200 || data.indexOf('Sorry, Disney+ is not available in your region.') !== -1) {
reject('Not Available')
return
}
let match = data.match(/Region: ([A-Za-z]{2})[\s\S]*?CNBL: ([12])/)
if (!match) {
resolve({ region: '', cnbl: '' })
return
}
let region = match[1]
let cnbl = match[2]
resolve({ region, cnbl })
})
})
}
function timeout(delay = 5000) {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject('Timeout')
}, delay)
})
}