Files
QuantumultX/Scripts/nf_ytb_ui-check.js
2021-09-30 19:05:30 +08:00

173 lines
7.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/***
Thanks to & modified from https://gist.githubusercontent.com/Hyseen/b06e911a41036ebc36acf04ddebe7b9a/raw/nf_check.js
For Quantumult-X 598+
[task_local]
event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/nf_ytb_ui-check.js, tag=YouTube/Netflix 解锁查询, img-url=checkmark.seal.system, enabled=true
@XIAO_KOP
**/
const BASE_URL = 'https://www.netflix.com/title/'
const BASE_URL_YTB = "https://www.youtube.com/premium"
const FILM_ID = 81215567
const link = { "media-url": "https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/img/southpark/7.png" }
const policy_name = "Netflix" //填入你的 netflix 策略组名
const arrow = "➟"
var output = ""
var opts = {
policy: $environment.params
};
var flags = new Map([[ "AC" , "🇦🇨" ] , [ "AF" , "🇦🇫" ] , [ "AI" , "🇦🇮" ] , [ "AL" , "🇦🇱" ] , [ "AM" , "🇦🇲" ] , [ "AQ" , "🇦🇶" ] , [ "AR" , "🇦🇷" ] , [ "AS" , "🇦🇸" ] , [ "AT" , "🇦🇹" ] , [ "AU" , "🇦🇺" ] , [ "AW" , "🇦🇼" ] , [ "AX" , "🇦🇽" ] , [ "AZ" , "🇦🇿" ] , [ "BB" , "🇧🇧" ] , [ "BD" , "🇧🇩" ] , [ "BE" , "🇧🇪" ] , [ "BF" , "🇧🇫" ] , [ "BG" , "🇧🇬" ] , [ "BH" , "🇧🇭" ] , [ "BI" , "🇧🇮" ] , [ "BJ" , "🇧🇯" ] , [ "BM" , "🇧🇲" ] , [ "BN" , "🇧🇳" ] , [ "BO" , "🇧🇴" ] , [ "BR" , "🇧🇷" ] , [ "BS" , "🇧🇸" ] , [ "BT" , "🇧🇹" ] , [ "BV" , "🇧🇻" ] , [ "BW" , "🇧🇼" ] , [ "BY" , "🇧🇾" ] , [ "BZ" , "🇧🇿" ] , [ "CA" , "🇨🇦" ] , [ "CF" , "🇨🇫" ] , [ "CH" , "🇨🇭" ] , [ "CK" , "🇨🇰" ] , [ "CL" , "🇨🇱" ] , [ "CM" , "🇨🇲" ] , [ "CN" , "🇨🇳" ] , [ "CO" , "🇨🇴" ] , [ "CP" , "🇨🇵" ] , [ "CR" , "🇨🇷" ] , [ "CU" , "🇨🇺" ] , [ "CV" , "🇨🇻" ] , [ "CW" , "🇨🇼" ] , [ "CX" , "🇨🇽" ] , [ "CY" , "🇨🇾" ] , [ "CZ" , "🇨🇿" ] , [ "DE" , "🇩🇪" ] , [ "DG" , "🇩🇬" ] , [ "DJ" , "🇩🇯" ] , [ "DK" , "🇩🇰" ] , [ "DM" , "🇩🇲" ] , [ "DO" , "🇩🇴" ] , [ "DZ" , "🇩🇿" ] , [ "EA" , "🇪🇦" ] , [ "EC" , "🇪🇨" ] , [ "EE" , "🇪🇪" ] , [ "EG" , "🇪🇬" ] , [ "EH" , "🇪🇭" ] , [ "ER" , "🇪🇷" ] , [ "ES" , "🇪🇸" ] , [ "ET" , "🇪🇹" ] , [ "EU" , "🇪🇺" ] , [ "FI" , "🇫🇮" ] , [ "FJ" , "🇫🇯" ] , [ "FK" , "🇫🇰" ] , [ "FM" , "🇫🇲" ] , [ "FO" , "🇫🇴" ] , [ "FR" , "🇫🇷" ] , [ "GA" , "🇬🇦" ] , [ "GB" , "🇬🇧" ] , [ "HK" , "🇭🇰" ] ,["HU","🇭🇺"], [ "ID" , "🇮🇩" ] , [ "IE" , "🇮🇪" ] , [ "IL" , "🇮🇱" ] , [ "IM" , "🇮🇲" ] , [ "IN" , "🇮🇳" ] , [ "IS" , "🇮🇸" ] , [ "IT" , "🇮🇹" ] , [ "JP" , "🇯🇵" ] , [ "KR" , "🇰🇷" ] , [ "LU" , "🇱🇺" ] , [ "MO" , "🇲🇴" ] , [ "MX" , "🇲🇽" ] , [ "MY" , "🇲🇾" ] , [ "NL" , "🇳🇱" ] , [ "PH" , "🇵🇭" ] , [ "RO" , "🇷🇴" ] , [ "RS" , "🇷🇸" ] , [ "RU" , "🇷🇺" ] , [ "RW" , "🇷🇼" ] , [ "SA" , "🇸🇦" ] , [ "SB" , "🇸🇧" ] , [ "SC" , "🇸🇨" ] , [ "SD" , "🇸🇩" ] , [ "SE" , "🇸🇪" ] , [ "SG" , "🇸🇬" ] , [ "TH" , "🇹🇭" ] , [ "TN" , "🇹🇳" ] , [ "TO" , "🇹🇴" ] , [ "TR" , "🇹🇷" ] , [ "TV" , "🇹🇻" ] , [ "TW" , "🇨🇳" ] , [ "UK" , "🇬🇧" ] , [ "UM" , "🇺🇲" ] , [ "US" , "🇺🇸" ] , [ "UY" , "🇺🇾" ] , [ "UZ" , "🇺🇿" ] , [ "VA" , "🇻🇦" ] , [ "VE" , "🇻🇪" ] , [ "VG" , "🇻🇬" ] , [ "VI" , "🇻🇮" ] , [ "VN" , "🇻🇳" ] , [ "ZA" , "🇿🇦"]])
!(async () => {
let result = {
title: '📺 Netflix/YouTube 解锁查询',
content: '----------------------\n\n检测失败请重试',
content1: '检测失败,请重试'
}
await Promise.race([test(FILM_ID),timeOut(5000)])
.then((code) => {
console.log(code)
if (code === 'Not Available') {
result['content'] = '----------------------\n\n🛑 未支持 Netflix'
//return
//console.log(result)
} else if (code === 'Not Found') {
result['content'] = '----------------------\n\n⚠ 仅支持 Netflix 自制剧'
//return
} else if (code === "timeout") {
result['content'] = "----------------------\n\n🛑 测试超时"
} else {
result['content'] = '----------------------\n\n✅ 完整支持 Netflix ➟ ⟦'+flags.get(code.toUpperCase())+code.toUpperCase()+"⟧"
}
return testYTB()
// $notify(result["title"], output, result["content"]+"\n"+result["content1"], link)
// $done({"title":result["title"],"message":result["content"]+"\n"+result["content1"]})
})
.then((code) => {
console.log(code)
if (code === 'Not Available') {
result['content1'] = '⚠️ 未支持 YouTube Premium'
//return
} else if (code === "timeout") {
result['content1'] = "🛑 测试超时"
} else {
result['content1'] = "✅ 支持 YouTube Premium ➟ ⟦"+flags.get(code.toUpperCase())+code.toUpperCase()+"⟧"
}
$done({"title":result["title"],"message":result["content"]+"\n\n"+result["content1"]})
})
// )
})()
.finally(() => $done());
function timeOut(delay) {
return new Promise((resolve, reject) => {
setTimeout(() => {
//reject(new Error('timeout'))
resolve("timeout")
}, delay)
})
}
function test(filmId) {
return new Promise((resolve, reject) => {
let option = {
url: BASE_URL + filmId,
opts: opts,
timeout: 4000,
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',
},
}
$task.fetch(option).then (response => {
console.log(response.statusCode)
if (response.statusCode === 404) {
resolve('Not Found')
return
}
if (response.statusCode === 403) {
resolve('Not Available')
return
}
if (response.statusCode === 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')
}, reason => {
resolve("timeout")
return
}
)
})
}
function testYTB() {
return new Promise((resolve, reject) => {
let option = {
url: BASE_URL_YTB,
opts: opts,
timeout: 4000,
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'
},
}
$task.fetch(option).then(response=> {
let data = response.body
console.log(response.statusCode)
if (response.statusCode !== 200) {
reject('Error')
return
}
if (data.indexOf('Premium is not available in your country') !== -1) {
resolve('Not Available')
return
}
//console.log(data.split("countryCode")[1])
let region = ''
let re = new RegExp('"GL":"(.*?)"', '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)
}, reason => {
resolve("timeout")
})
})
}