mirror of
https://github.com/lanyeeee/bilibili-video-downloader.git
synced 2026-09-09 01:27:27 +08:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa469b1348 | ||
|
|
2ab8a91ef4 | ||
|
|
28c81795b8 | ||
|
|
7d065797fb |
@@ -120,6 +120,15 @@ impl BiliClient {
|
||||
let http_resp = request.send().await?;
|
||||
// 检查http响应状态码
|
||||
let status = http_resp.status();
|
||||
// 尝试从headers中拿SESSDATA
|
||||
let sessdata = http_resp
|
||||
.headers()
|
||||
.get_all("set-cookie")
|
||||
.iter()
|
||||
.filter_map(|header| header.to_str().ok())
|
||||
.filter_map(|header| header.split(';').next())
|
||||
.filter_map(|cookie| cookie.split_once('='))
|
||||
.find_map(|(key, value)| (key.trim() == "SESSDATA").then(|| value.to_owned()));
|
||||
let body = http_resp.text().await?;
|
||||
if status != StatusCode::OK {
|
||||
return Err(eyre!("预料之外的状态码({status}): {body}"));
|
||||
@@ -137,11 +146,14 @@ impl BiliClient {
|
||||
};
|
||||
// 尝试将data解析为二维码状态
|
||||
let data_str = data.to_string();
|
||||
let qrcode_status: QrcodeStatus = serde_json::from_str(&data_str)
|
||||
let mut qrcode_status: QrcodeStatus = serde_json::from_str(&data_str)
|
||||
.wrap_err(format!("将data解析为QrcodeStatus失败: {data_str}"))?;
|
||||
if ![0, 86101, 86090, 86038].contains(&qrcode_status.code) {
|
||||
return Err(eyre!("预料之外的二维码code: {qrcode_status:?}"));
|
||||
}
|
||||
if qrcode_status.code == 0 {
|
||||
qrcode_status.sessdata = sessdata.ok_or_eyre("扫码成功,但没有解析到SESSDATA")?;
|
||||
}
|
||||
Ok(qrcode_status)
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ impl ChapterSegments {
|
||||
// 遍历完所有现有片段并处理完所有重叠后,将新的片段添加到结果列表中
|
||||
processed_segments.push(new_segment);
|
||||
|
||||
processed_segments.sort_by(|a, b| a.start.cmp(&b.start));
|
||||
processed_segments.sort_by_key(|a| a.start);
|
||||
|
||||
self.segments = processed_segments;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use specta::Type;
|
||||
#[serde(default)]
|
||||
pub struct QrcodeStatus {
|
||||
pub url: String,
|
||||
pub sessdata: String,
|
||||
pub refresh_token: String,
|
||||
pub timestamp: i64,
|
||||
pub code: i64,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "bilibili-video-downloader",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"identifier": "com.lanyeeee.bilibili-video-downloader",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
|
||||
+1
-1
@@ -424,7 +424,7 @@ export type PurchaseFormatNote = { content_list: ContentList[]; link: string; ti
|
||||
export type PurchaseNote = { content: string; link: string; title: string }
|
||||
export type PurchaseProtocol = { link: string; title: string }
|
||||
export type QrcodeData = { url: string; qrcode_key: string }
|
||||
export type QrcodeStatus = { url: string; refresh_token: string; timestamp: number; code: number; message: string }
|
||||
export type QrcodeStatus = { url: string; sessdata: string; refresh_token: string; timestamp: number; code: number; message: string }
|
||||
export type RatingInBangumi = { count: number; score: number }
|
||||
export type RatingInBangumiFollow = { score: number; count: number }
|
||||
export type RecommendSeason = { cover: string; ep_count: string; id: number; season_url: string; subtitle: string; title: string; view: number }
|
||||
|
||||
@@ -93,8 +93,7 @@ function handleQrcodeStatus() {
|
||||
}
|
||||
|
||||
if (qrcodeStatus.value.code === 0) {
|
||||
const sessdata = qrcodeStatus.value.url.split('SESSDATA=')[1].split('&')[0]
|
||||
store.config.sessdata = encodeURIComponent(sessdata)
|
||||
store.config.sessdata = qrcodeStatus.value.sessdata
|
||||
showing.value = false
|
||||
message.success('登录成功')
|
||||
}
|
||||
|
||||
+11
-19
@@ -27,36 +27,28 @@ export const useStore = defineStore('store', () => {
|
||||
})
|
||||
|
||||
function useProgresses() {
|
||||
// 内部的高频更新状态
|
||||
const _progresses = new Map<string, ProgressData>()
|
||||
// 对外暴露的响应式状态
|
||||
const progresses = ref<Map<string, ProgressData>>(new Map())
|
||||
|
||||
// 等待在同一渲染帧内执行的更新函数
|
||||
const pendingUpdateFns: Array<(progresses: Map<string, ProgressData>) => void> = []
|
||||
|
||||
// 用于确保在同一渲染帧内只安排一次UI更新
|
||||
let isUpdateScheduled = false
|
||||
|
||||
// 将 `_progresses` 的内容更新到 `progresses` 中,并触发重新渲染
|
||||
// 在同一渲染帧内集中执行等待中的更新函数
|
||||
const updateProgressesOnFrame = () => {
|
||||
const newProgressesMap = new Map<string, ProgressData>()
|
||||
|
||||
for (const [key, value] of _progresses.entries()) {
|
||||
const progressData = progresses.value.get(key)
|
||||
|
||||
if (progressData !== undefined) {
|
||||
Object.assign(progressData, value)
|
||||
newProgressesMap.set(key, progressData)
|
||||
} else {
|
||||
newProgressesMap.set(key, { ...value })
|
||||
}
|
||||
}
|
||||
progresses.value = newProgressesMap
|
||||
|
||||
isUpdateScheduled = false
|
||||
|
||||
const updateFns = pendingUpdateFns.splice(0)
|
||||
for (const updateFn of updateFns) {
|
||||
updateFn(progresses.value)
|
||||
}
|
||||
}
|
||||
|
||||
const updateProgresses = (updateFn: (progresses: Map<string, ProgressData>) => void) => {
|
||||
// 使用传入的更新函数来修改 `_progresses`
|
||||
updateFn(_progresses)
|
||||
// 将传入的更新函数添加到等待队列
|
||||
pendingUpdateFns.push(updateFn)
|
||||
|
||||
if (!isUpdateScheduled) {
|
||||
// 如果没有安排过UI更新,则安排一次
|
||||
|
||||
Reference in New Issue
Block a user