Skip to content

Commit 5ab8b1b

Browse files
Merge pull request #262 from alley-rs/dev
2 parents 74f53ce + 9f8b55e commit 5ab8b1b

File tree

11 files changed

+75
-27
lines changed

11 files changed

+75
-27
lines changed

src/commands/parser/bigo.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
3+
export const parseBigo = async (roomId: number) => {
4+
const result = await invoke<ParsedResult>("parse_bigo", {
5+
roomId,
6+
});
7+
return result;
8+
};

src/commands/parser/bili.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
3+
export const parseBilibili = async (
4+
roomID: number,
5+
cookie: string,
6+
url: string
7+
) => {
8+
const result = await invoke<ParsedResult>("parse_bilibili", {
9+
roomId: roomID,
10+
cookie: cookie,
11+
url: url || null,
12+
});
13+
return result;
14+
};

src/commands/parser/douyin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
3+
export const parseDouyin = async (roomID: number) => {
4+
const result = await invoke<ParsedResult>("parse_douyin", {
5+
roomId: roomID,
6+
});
7+
return result;
8+
};

src/commands/parser/douyu.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
3+
export const parseDouyu = async (roomID: number) => {
4+
const result = await invoke<ParsedResult>("parse_douyu", {
5+
roomId: roomID,
6+
});
7+
return result;
8+
};

src/commands/parser/huya.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
3+
export const parseHuya = async (roomID: number, url: string) => {
4+
const result = await invoke<ParsedResult>("parse_huya", {
5+
roomId: roomID || null,
6+
url: url,
7+
});
8+
return result;
9+
};

src/commands/parser/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { parseBigo } from "./bigo";
2+
export { parseBilibili } from "./bili";
3+
export { parseDouyin } from "./douyin";
4+
export { parseDouyu } from "./douyu";
5+
export { parseHuya } from "./huya";

src/parser/bigo/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { parseBigo } from "~/commands/parser";
2+
13
import LiveStreamParser from "../base";
4+
25
import { parseRoomID } from "../utils";
3-
import { invoke } from "@tauri-apps/api/core";
46

57
class BigoParser extends LiveStreamParser {
68
constructor(roomID: number) {
@@ -9,9 +11,7 @@ class BigoParser extends LiveStreamParser {
911

1012
async parse(): Promise<ParsedResult | Error> {
1113
try {
12-
const result = await invoke<ParsedResult>("parse_bigo", {
13-
roomId: this.roomID,
14-
});
14+
const result = await parseBigo(this.roomID);
1515
return result;
1616
} catch (e) {
1717
return Error(String(e));

src/parser/bilibili/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { parseBilibili } from "~/commands/parser";
2+
13
import LiveStreamParser from "../base";
2-
import { invoke } from "@tauri-apps/api/core";
34

45
class BilibiliParser extends LiveStreamParser {
56
cookie: string;
@@ -12,11 +13,7 @@ class BilibiliParser extends LiveStreamParser {
1213

1314
async parse(): Promise<ParsedResult | Error> {
1415
try {
15-
const result = await invoke<ParsedResult>("parse_bilibili", {
16-
roomId: this.roomID,
17-
cookie: this.cookie,
18-
url: this.url || null,
19-
});
16+
const result = await parseBilibili(this.roomID, this.cookie, this.url);
2017
return result;
2118
} catch (e) {
2219
return Error(String(e));
@@ -26,7 +23,7 @@ class BilibiliParser extends LiveStreamParser {
2623

2724
export default function createBilibiliParser(
2825
input: string | number,
29-
cookie: string,
26+
cookie: string
3027
) {
3128
let roomID: number | undefined;
3229
let url: string | undefined;

src/parser/douyin/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { parseDouyin } from "~/commands/parser";
2+
13
import LiveStreamParser from "../base";
4+
25
import { parseRoomID } from "../utils";
3-
import { invoke } from "@tauri-apps/api/core";
46

57
class DouyinParser extends LiveStreamParser {
68
constructor(roomID: number) {
@@ -9,9 +11,7 @@ class DouyinParser extends LiveStreamParser {
911

1012
async parse(): Promise<ParsedResult | Error> {
1113
try {
12-
const result = await invoke<ParsedResult>("parse_douyin", {
13-
roomId: this.roomID,
14-
});
14+
const result = await parseDouyin(this.roomID);
1515
return result;
1616
} catch (e) {
1717
return Error(String(e));

src/parser/douyu/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { listen } from "@tauri-apps/api/event";
2+
13
import { evalResult } from "~/command";
4+
import { parseDouyu } from "~/commands/parser";
5+
26
import LiveStreamParser from "../base";
3-
import { listen } from "@tauri-apps/api/event";
4-
import { invoke } from "@tauri-apps/api/core";
7+
58
import {
69
INVALID_INPUT,
710
parseRoomID,
@@ -20,9 +23,7 @@ class DouyuParser extends LiveStreamParser {
2023
});
2124

2225
try {
23-
const result = await invoke<ParsedResult>("parse_douyu", {
24-
roomId: this.roomID,
25-
});
26+
const result = await parseDouyu(this.roomID);
2627
return result;
2728
} catch (e) {
2829
return Error(String(e));
@@ -33,7 +34,7 @@ class DouyuParser extends LiveStreamParser {
3334
}
3435

3536
export default function createDouyuParser(
36-
input: string | number,
37+
input: string | number
3738
): DouyuParser | Error {
3839
let roomID = parseRoomID(input);
3940
// 斗鱼的房间号可能在查询参数 rid 中

0 commit comments

Comments
 (0)