From 2f1fa81be89faa952368c537e0c6af0563d034a9 Mon Sep 17 00:00:00 2001 From: Shawn <45581750+KOP-XIAO@users.noreply.github.com> Date: Tue, 12 Oct 2021 21:19:43 +0800 Subject: [PATCH] Update streaming-ui-check.js --- Scripts/streaming-ui-check.js | 294 ++++++++++++++++++++++++---------- 1 file changed, 209 insertions(+), 85 deletions(-) diff --git a/Scripts/streaming-ui-check.js b/Scripts/streaming-ui-check.js index 224cd92..572ea59 100644 --- a/Scripts/streaming-ui-check.js +++ b/Scripts/streaming-ui-check.js @@ -22,14 +22,6 @@ const BASE_URL = 'https://www.netflix.com/title/'; const BASE_URL_YTB = "https://www.youtube.com/premium"; const BASE_URL_DISNEY = 'https://www.disneyplus.com'; const BASE_URL_Dazn = "https://startup.core.indazn.com/misl/v5/Startup"; -//var BASE_URL_BLBL = "https://api.bilibili.com/pgc/player/web/playurl?avid=18281381&cid=29892777&qn=0&type=&otype=json&ep_id=183799&fourk=1&fnver=0&fnval=16&session=" + randomString(20) + "&module=bangumi"; -//const BASE_URL_BahamutAnime = 'https://ani.gamer.com.tw/ajax/token.php?adID=89422&sn=14667'; -//const BASE_URL_HULUJP = 'https://id.hulu.jp'; -//const BASE_URL_HBOMAX = 'https://www.hbomax.com'; -//const BASE_URL_NICONICO = 'https://www.nicovideo.jp/watch/so23017073'; -//const BASE_URL_KKTV = "https://api.kktv.me/v3/ipcheck"; -//const BASE_URL_TVBANYWHERE = "https://uapisfm.tvbanywhere.com.sg/geoip/check/platform/android"; -var D_region; const FILM_ID = 81215567 const link = { "media-url": "https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/img/southpark/7.png" } @@ -38,6 +30,23 @@ const policy_name = "Netflix" //填入你的 netflix 策略组名 const arrow = " ➟ " var output = "" +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' + +// 即将登陆 +const STATUS_COMING = 2 +// 支持解锁 +const STATUS_AVAILABLE = 1 +// 不支持解锁 +const STATUS_NOT_AVAILABLE = 0 +// 检测超时 +const STATUS_TIMEOUT = -1 +// 检测异常 +const STATUS_ERROR = -2 + +var opts = { + policy: $environment.params +}; + var opts = { policy: $environment.params }; @@ -47,45 +56,205 @@ var opts1 = { redirection: false }; -function randomString(e) -{ - e = e || 32; - var t = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890", - a = t.length, - n = ""; - for (i=0;iYouTube: 检测失败,请重试', + "Netflix": 'Netflix: 检测失败,请重试', + "Dazn": "Dazn: 检测失败,请重试", + "Disney": "Disney⁺: 检测失败,请重试", //"Google": "Google 定位: 检测失败,请重试" } -StreamingCheck() +//StreamingCheck() +// +//function StreamingCheck(){ +// testYTB() +// test(FILM_ID) +// //testDisney() +// testDazn() +// setTimeout(function(){ +// let content = "------------------------------"+"
"+([result["YouTube"],result["Netflix"],result["Dazn"]]).join("

") +// content = content + "
------------------------------
"+""+"节点 ➟ " + $environment.params+ "" +// content =`

` + content + `

` +// $done({"title": result["title"], "htmlMessage": content}) +// },3000) +//} -function StreamingCheck(){ +;(async () => { testYTB() test(FILM_ID) - //testDisney() testDazn() - setTimeout(function(){ - $done({"title": result["title"],"message": "\n "+([result["YouTube"],result["Netflix"],result["Dazn"]]).join("\n\n ") +'\n\n -----------------------------\n\n'+ " 节点" + arrow + $environment.params}) - },3000) + let { region, status } = await testDisneyPlus() + console.log(`testDisneyPlus: region=${region}, status=${status}`) + if (status==STATUS_COMING) { + //console.log(1) + result["Disney"] = "Disney⁺: 即将登陆 ➟ "+'⟦'+flags.get(region.toUpperCase())+"⟧" + } else if (status==STATUS_AVAILABLE){ + //console.log(2) + result["Disney"] = "Disney⁺: 已支持 ➟ "+'⟦'+flags.get(region.toUpperCase())+"⟧" + console.log(result["Disney"]) + } else if (status==STATUS_NOT_AVAILABLE) { + //console.log(3) + result["Disney"] = "Disney⁺: 未支持 " + } else if (status==STATUS_TIMEOUT) { + result["Disney"] = "Disney⁺: 测试超时 " + } + let content = "------------------------------"+"
"+([result["YouTube"],result["Netflix"],result["Disney"],result["Dazn"]]).join("

") + content = content + "
------------------------------
"+""+"节点 ➟ " + $environment.params+ "" + content =`

` + content + `

` +// cnt = `

` +'----------------------

'+result["Disney"]+'

----------------------
'+$environment.params + `

` + $done({"title":result["title"],"htmlMessage":content}) +})() +.finally(() => $done({"title":result["title"],"htmlMessage":`

`+'----------------------

'+"🚥 检测异常"+'

----------------------
'+$environment.params + `

`})); + + +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 opts0 = { + url: 'https://disney.api.edge.bamgrid.com/graph/v1/device/graphql', + method: "POST", + opts: opts, + 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: 'microsoft', + model: null, + operatingSystem: 'windows', + operatingSystemVersion: '10.0', + osDeviceIds: [], + }, + deviceFamily: 'browser', + deviceLanguage: 'en', + deviceProfile: 'windows', + }, + }, + }), + } + + $task.fetch(opts0).then(response => { + let data = response.body + console.log("locationinfo:"+response.statusCode) + if (response.statusCode !== 200) { + console.log('getLocationInfo: ' + data) + reject('Not Available') + return + } else {let { + inSupportedLocation, + location: { countryCode }, + } = JSON.parse(data)?.extensions?.sdk?.session + resolve({ inSupportedLocation, countryCode }) + } + }, reason => { + reject('Error') + return + }) + }) +} + +function testHomePage() { + return new Promise((resolve, reject) => { + let opts0 = { + url: 'https://www.disneyplus.com/', + opts: opts, + headers: { + 'Accept-Language': 'en', + 'User-Agent': UA, + }, + } + $task.fetch(opts0).then(response => { + let data = response.body + //console.log("homepage"+response.statusCode) + if (response.statusCode !== 200 || data.indexOf('unavailable') !== -1) { + reject('Not Available') + return + } else { + let match = data.match(/Region: ([A-Za-z]{2})[\s\S]*?CNBL: ([12])/) + if (!match) { + resolve({ region: '', cnbl: '' }) + return + } else { + let region = match[1] + let cnbl = match[2] + //console.log("homepage"+region+cnbl) + resolve({ region, cnbl }) + } + } + }, reason => { + reject('Error') + return + }) + }) +} + +function timeout(delay = 5000) { + return new Promise((resolve, reject) => { + setTimeout(() => { + reject('Timeout') + }, delay) + }) } function test(filmId) { let option = { url: BASE_URL + filmId, opts: opts, - timeout: 2800, + timeout: 3200, 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', @@ -95,11 +264,11 @@ function test(filmId) { console.log("nf:"+response.statusCode) if (response.statusCode === 404) { //resolve('Not Found') - result["Netflix"] = "Netflix: 支持自制剧集" + result["Netflix"] = "Netflix: 支持自制剧集" } else if (response.statusCode === 403) { //resolve('Not Available') //console.log("nfnf") - result["Netflix"] = "Netflix: 未支持" + result["Netflix"] = "Netflix: 未支持" } else if (response.statusCode === 200) { let url = response.headers['X-Originating-URL'] let region = url.split('/')[3] @@ -109,12 +278,12 @@ function test(filmId) { } console.log("nf:"+region) //resolve(region) - result["Netflix"] = "Netflix: 完整支持"+ "⟦"+flags.get(region.toUpperCase())+"⟧" + result["Netflix"] = "Netflix: 完整支持"+ "⟦"+flags.get(region.toUpperCase())+"⟧" } //reject('Error') }, reason => { //resolve("timeout") - result["Netflix"] = "Netflix: 检测超时" + result["Netflix"] = "Netflix: 检测超时" } ) } @@ -134,10 +303,10 @@ function testYTB() { console.log("ytb:"+response.statusCode) if (response.statusCode !== 200) { //reject('Error') - result["YouTube"] = "YouTube Premium: 检测失败" + result["YouTube"] = "YouTube Premium: 检测失败" } else if (data.indexOf('Premium is not available in your country') !== -1) { //resolve('Not Available') - result["YouTube"] = "YouTube Premium: 未支持" + result["YouTube"] = "YouTube Premium: 未支持" } else if (data.indexOf('Premium is not available in your country') == -1) {//console.log(data.split("countryCode")[1]) let region = '' let re = new RegExp('"GL":"(.*?)"', 'gm') @@ -150,60 +319,15 @@ function testYTB() { region = 'US' } //resolve(region) - result["YouTube"] = "YouTube Premium: 支持"+ "⟦"+flags.get(region.toUpperCase())+"⟧" + result["YouTube"] = "YouTube Premium: 支持"+ "⟦"+flags.get(region.toUpperCase())+"⟧" console.log("ytb:"+region+ result["YouTube"]) } }, reason => { - result["YouTube"] = "YouTube Premium: 检测超时" + result["YouTube"] = "YouTube Premium: 检测超时" //resolve("timeout") }) } - -function testDisney(){ - let option = { - url: BASE_URL_DISNEY, - opts: opts, - timeout: 2800, - headers: { - 'User-Agent': - 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' - }, - } - $task.fetch(option).then(response => { - console.log("Disney+ :" + response.statusCode); - //console.log(response.body) - let DisneyURL = response.headers['Location']; - if(response.statusCode === 200) - { - if(response.body.indexOf("Sorry, Star+ is not available in your region") !== -1) // 无服务 - { - result["Disney"]= "Disney+: 未支持" - } else if(response.body.indexOf("【公式】Disney+ (ディズニープラス)") !== -1) // 日本版 - { - D_region = "JP" - result["Disney"]= "Disney+: 已支持"+ "⟦"+flags.get(D_region.toUpperCase())+"⟧" - } else if(response.body.indexOf(' { - result["Disney"]= "Disney+: 检测超时" - }) -} - function testDazn() { const extra =`{ @@ -236,7 +360,7 @@ function testDazn() { //$done(data) if (response.statusCode !== 200) { //reject('Error') - result["Dazn"] = "Dazn: 检测失败" + result["Dazn"] = "Dazn: 检测失败" } else if (response.statusCode == 200) {//console.log(data.split("countryCode")[1]) console.log(data) let region = '' @@ -244,16 +368,16 @@ function testDazn() { let ret = re.exec(data) if (ret != null && ret.length === 2) { region = ret[1] - result["Dazn"] = "Dazn: 支持"+ "⟦"+flags.get(region.toUpperCase())+"⟧" + result["Dazn"] = "Dazn: 支持"+ "⟦"+flags.get(region.toUpperCase())+"⟧" } else { - result["Dazn"] = "Dazn: 未支持" + result["Dazn"] = "Dazn: 未支持" } //resolve(region) console.log("Dazn:"+region+ result["Dazn"]) } }, reason => { - result["Dazn"] = "Dazn: 检测超时" + result["Dazn"] = "Dazn: 检测超时" //resolve("timeout") }) }