From 5960a4f95824ee7c977711b5ec02d925cde14020 Mon Sep 17 00:00:00 2001 From: Shawn <45581750+KOP-XIAO@users.noreply.github.com> Date: Tue, 12 Oct 2021 18:55:48 +0800 Subject: [PATCH] update --- .DS_Store | Bin 12292 -> 12292 bytes Scripts/UI-Action.json | 3 +- Scripts/disney-ui-check.js | 203 +++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 Scripts/disney-ui-check.js diff --git a/.DS_Store b/.DS_Store index 32cb939d4ab6e26637a6213ad4a995941e3585cb..ee402068ea99a53e68bc079a1550e8a9ddb93c63 100644 GIT binary patch delta 28 jcmZokXi3|p delta 28 jcmZokXi3 { + let { region, status } = await testDisneyPlus() + console.log(`testDisneyPlus: region=${region}, status=${status}`) + if (status==STATUS_COMING) { + //console.log(1) + result["status"] = "🚦 即将登陆 ➟ "+'⟦'+flags.get(region.toUpperCase())+"⟧" + } else if (status==STATUS_AVAILABLE){ + //console.log(2) + result["status"] = "✅ 已支持 ➟ "+'⟦'+flags.get(region.toUpperCase())+"⟧" + console.log(result["status"]) + } else if (status==STATUS_NOT_AVAILABLE) { + //console.log(3) + result["status"] = "🛑 不支持 " + } + cnt = `

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

'+result["status"]+'

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

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

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

'+result["status"]+'

----------------------
'+$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) + }) +} + +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" , "🇿🇦"]]) + +