-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update youku version retrieval method
- Loading branch information
Showing
2 changed files
with
9 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,4 @@ recursiveUnzipList = [] | |
[extra] | ||
# require_windows = false | ||
# missing_version = "" | ||
weekly = true | ||
# weekly = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
import { Ok, Err, Result } from "ts-results"; | ||
import { Ok, Result } from "ts-results"; | ||
import { ScraperReturned } from "../../src/class"; | ||
import { robustGet } from "../../src/network"; | ||
|
||
export default async function (): Promise<Result<ScraperReturned, string>> { | ||
const page = ( | ||
await robustGet("https://youku.com/product/index") | ||
).unwrap() as string; | ||
|
||
// 匹配初始化数据 | ||
const jsonTextMatch = page.match(/window\.__INITIAL_DATA__\s*=\s*([^;]+);/g); | ||
if (jsonTextMatch == null) return new Err("Error:Can't match initial data"); | ||
const json = JSON.parse( | ||
jsonTextMatch[0].split(/window.__INITIAL_DATA__\s*=\s*/)[1].slice(0, -1), | ||
); | ||
// console.log(JSON.stringify(json,null,2)) | ||
|
||
// 选中pc版 | ||
const node = json[0].subNav[0]; | ||
// console.log(JSON.stringify(node,null,2)) | ||
|
||
const prefix = "https://pcclient.download.youku.com/iku-win-release/"; | ||
const versionUrl = `${prefix}latest.yml?noCache=${Math.random()}`; | ||
const versionInfo: any = (await robustGet(versionUrl)).unwrap() as string; | ||
const version = versionInfo.match(/version: (.+)/)[1]; | ||
const downloadLink = prefix + versionInfo.match(/url: (.+)/)[1]; | ||
return new Ok({ | ||
version: node.ver, | ||
downloadLink: node.downloadUrl, | ||
version, | ||
downloadLink, | ||
}); | ||
} |