Skip to content

Commit

Permalink
refactor: detectPlatform()
Browse files Browse the repository at this point in the history
Update detectPlatform.mjs
Update CHANGELOG.md
  • Loading branch information
VirgilClyne committed Nov 10, 2024
1 parent 434aa3f commit 73fb814
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
* 升级了 `@nsnanocat/util`
* `$platform` 改为 `$app`
* 使用了全新的 `URL``URLSearchParams` polyfill

### 🔄 Other Changes
* 重构了 `detectPlatform`
80 changes: 60 additions & 20 deletions src/function/detectPlatform.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,66 @@ import { log } from "@nsnanocat/util";
export default function detectPlatform(url) {
log("☑️ Detect Platform", "");
/***************** Platform *****************/
const Platform = /\.(netflix\.com|nflxvideo\.net)/i.test(url) ? "Netflix"
: /(\.youtube|youtubei\.googleapis)\.com/i.test(url) ? "YouTube"
: /\.spotify(cdn)?\.com/i.test(url) ? "Spotify"
: /\.apple\.com/i.test(url) ? "Apple"
: /\.(dssott|starott|dssedge)\.com/i.test(url) ? "Disney+"
: /primevideo\.com|(\.(pv-cdn|aiv-cdn|akamaihd|cloudfront)\.net)|s3\.amazonaws\.com\/aiv-prod-timedtext\//i.test(url) ? "PrimeVideo"
: /prd\.media\.h264\.io/i.test(url) ? "Max"
: /\.(api\.hbo|hbomaxcdn)\.com/i.test(url) ? "HBOMax"
: /\.hulu(stream|im)?\.com/i.test(url) ? "Hulu"
: /\.(pplus\.paramount\.tech|cbs(aavideo|cbsivideo)?\.com)/i.test(url) ? "Paramount+"
: /\.uplynk\.com/i.test(url) ? "Discovery+"
: /dplus-ph-/i.test(url) ? "Discovery+Ph"
: /\.peacocktv\.com/i.test(url) ? "PeacockTV"
: /\.fubo\.tv/i.test(url) ? "FuboTV"
: /\.viki\.io/i.test(url) ? "Viki"
: /epix(hls\.akamaized\.net|\.services\.io)/i.test(url) ? "MGM+"
: /\.nebula\.app/i.test(url) ? "Nebula"
: /\.pluto(\.tv|tv\.net)/i.test(url) ? "PlutoTV"
: /\.mubicdn\.net/i.test(url) ? "MUBI"
: "Universal";
let Platform = "Universal";
switch (true) {
case /\.(netflix\.com|nflxvideo\.net)/i.test(url):
Platform = "Netflix";
break;
case /(\.youtube|youtubei\.googleapis)\.com/i.test(url):
Platform = "YouTube";
break;
case /\.spotify(cdn)?\.com/i.test(url):
Platform = "Spotify";
break;
case /\.apple\.com/i.test(url):
Platform = "Apple";
break;
case /\.(dssott|starott|dssedge)\.com/i.test(url):
Platform = "Disney+";
break;
case /primevideo\.com|(\.(pv-cdn|aiv-cdn|akamaihd|cloudfront)\.net)|s3\.amazonaws\.com\/aiv-prod-timedtext\//i.test(url):
Platform = "PrimeVideo";
break;
case /prd\.media\.h264\.io/i.test(url):
Platform = "Max";
break;
case /\.(api\.hbo|hbomaxcdn)\.com/i.test(url):
Platform = "HBOMax";
break;
case /\.hulu(stream|im)?\.com/i.test(url):
Platform = "Hulu";
break;
case /\.(pplus\.paramount\.tech|cbs(aavideo|cbsivideo)?\.com)/i.test(url):
Platform = "Paramount+";
break;
case /\.uplynk\.com/i.test(url):
Platform = "Discovery+";
break;
case /dplus-ph-/i.test(url):
Platform = "Discovery+Ph";
break;
case /\.peacocktv\.com/i.test(url):
Platform = "PeacockTV";
break;
case /\.fubo\.tv/i.test(url):
Platform = "FuboTV";
break;
case /\.viki\.io/i.test(url):
Platform = "Viki";
break;
case /epix(hls\.akamaized\.net|\.services\.io)/i.test(url):
Platform = "MGM+";
break;
case /\.nebula\.app/i.test(url):
Platform = "Nebula";
break;
case /\.pluto(\.tv|tv\.net)/i.test(url):
Platform = "PlutoTV";
break;
case /\.mubicdn\.net/i.test(url):
Platform = "MUBI";
break;
}
log(`✅ Detect Platform, Platform: ${Platform}`, "");
return Platform;
};

0 comments on commit 73fb814

Please sign in to comment.