Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(huya): 修复小概率网页解码错误导致页面不更新的问题 #11

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@

--alley-color-mask: rgba(0, 0, 0, 0.5);

--alley-color-info-bg: rgb(41 44 104 / 30%);
--alley-color-info-border: #4045a3;

--alley-color-success-bg: #092b00;
--alley-color-success-border: #237804;

--alley-color-error-bg: #5c0011;
--alley-color-error-border: #820014;

.alley-input {
--alley-input-addon-bg: rgba(255, 255, 255, 0.04);
// --alley-input-active-border-color: #1668dc;
Expand Down
15 changes: 12 additions & 3 deletions src/parser/huya/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ class Huya {
});

const ptn = /stream: (\{.+"iFrameRate":\d+\})/;
const streamStr = ptn.exec(html)![1];

const streamStr = ptn.exec(html)?.[1];
if (!streamStr) {
return Error(
`获取 streamStr 失败, 可能因为网页解码错误, 房间号: ${this.roomID}`,
);
}

const stream = JSON.parse(streamStr);
const roomID = stream.data[0].gameLiveInfo.profileRoom as string;
info(log_prefix, `真实房间 id:${roomID}`);
Expand Down Expand Up @@ -227,9 +234,11 @@ class Huya {

async parse() {
const roomID = await this.getFinalRoomID();
const result = await this.getRoomProfile(roomID);
if (roomID instanceof Error) {
return roomID;
}

console.log(result);
const result = await this.getRoomProfile(roomID);

return result;
}
Expand Down