Skip to content

Commit

Permalink
Providing cookie to Bilibili (#102)
Browse files Browse the repository at this point in the history
Fix #102
  • Loading branch information
maoqxxmm authored Nov 14, 2022
1 parent 416f151 commit 7528135
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 7 additions & 1 deletion server/models/mv/bilibili/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ class Entry {
upic;
page;
part;
cookie;

constructor(author, bvid, title, pic, upic, page, part) {
// Too many props. Should be put into one config prop.
constructor(author, bvid, title, pic, upic, page, part, cookie) {
this.author = author;
this.bvid = bvid;
this.title_ = title;
this.pic = pic;
this.upic = upic;
this.page = page;
this.part = part;
this.cookie = cookie;
}

id = () => {
Expand Down Expand Up @@ -52,6 +55,9 @@ class Entry {
};

downloadOptions = () => {
if (this.cookie) {
return ["--add-header", `cookie:${this.cookie}`];
}
return [];
};

Expand Down
10 changes: 7 additions & 3 deletions server/models/mv/bilibili/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Provider {
return NAME;
};

configure = (_config) => {};
configure = (config) => {
this.cookie = config.cookie;
};

search = async (title) => {
if (!this.cookie) {
Expand Down Expand Up @@ -59,7 +61,8 @@ class Provider {
"http:" + ele["pic"],
ele["upic"],
page["page"],
part
part,
this.cookie
)
);
}
Expand Down Expand Up @@ -90,7 +93,8 @@ class Provider {
data["pic"],
owner["face"],
page,
part
part,
this.cookie
);
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/SettingsWindow.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
.settings-window-form > .ant-form-item {
margin: 0 0 8px;
}

.settings-window-form .ant-form-item-label .icon-info {
margin-left: 4px;
}
15 changes: 15 additions & 0 deletions src/components/SettingsWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
Space,
Switch,
Tabs,
Tooltip,
} from "antd";
import React, { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import InfoCircleOutlined from "@ant-design/icons/InfoCircleOutlined";
import "./SettingsWindow.css";
import "./Window.css";

Expand Down Expand Up @@ -41,6 +43,13 @@ const SettingsWindow = (props) => {
form.submit();
}, [form]);

const BilibiliCookiesConfigLabel = (
<Tooltip title={t("bilibili_cookies_tooltip")}>
<span>{t("cookie")}</span>
<InfoCircleOutlined className="icon-info" />
</Tooltip>
);

return (
<Space
className={`settings-window-space ${className}`}
Expand Down Expand Up @@ -132,6 +141,12 @@ const SettingsWindow = (props) => {
>
<Switch />
</Form.Item>
<Form.Item
label={BilibiliCookiesConfigLabel}
name={["providers", "mv", "bilibili", "cookie"]}
>
<Input />
</Form.Item>
<Divider plain orientation="left" style={{ marginTop: 0 }}>
{t("ncm_mv")}
</Divider>
Expand Down
3 changes: 3 additions & 0 deletions src/locales/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const zh = {
ncm_lyrics: "网易云音乐 (歌词)",
petit_lyrics: "プチリリ",
save: "保存",
cookie: "Cookie",
bilibili_cookies_tooltip:
"哔哩哔哩需要提供 Cookie 才能获取 480P 以上的画质",
},
};

Expand Down

0 comments on commit 7528135

Please sign in to comment.