fix: 视频源第一页视频为空不再视为错误 (#677)
This commit is contained in:
@@ -196,6 +196,9 @@ impl<'a> Collection<'a> {
|
||||
})?;
|
||||
let archives = &mut videos["data"]["archives"];
|
||||
if archives.as_array().is_none_or(|v| v.is_empty()) {
|
||||
if page == 1 {
|
||||
break;
|
||||
}
|
||||
Err(anyhow!(
|
||||
"no videos found in collection {:?} page {}",
|
||||
self.collection,
|
||||
|
||||
@@ -52,7 +52,15 @@ impl<'a> Dynamic<'a> {
|
||||
.get_dynamics(offset.take())
|
||||
.await
|
||||
.with_context(|| "failed to get dynamics")?;
|
||||
let items = res["data"]["items"].as_array_mut().context("items not exist")?;
|
||||
let items = match res["data"]["items"].as_array_mut() {
|
||||
Some(items) if !items.is_empty() => items,
|
||||
_ => {
|
||||
if offset.is_none() {
|
||||
break;
|
||||
}
|
||||
Err(anyhow!("no dynamics found in offset {:?}", offset))?
|
||||
}
|
||||
};
|
||||
for item in items.iter_mut() {
|
||||
if item["type"].as_str().is_none_or(|t| t != "DYNAMIC_TYPE_AV") {
|
||||
continue;
|
||||
|
||||
@@ -85,6 +85,9 @@ impl<'a> FavoriteList<'a> {
|
||||
.with_context(|| format!("failed to get videos of favorite {} page {}", self.fid, page))?;
|
||||
let medias = &mut videos["data"]["medias"];
|
||||
if medias.as_array().is_none_or(|v| v.is_empty()) {
|
||||
if page == 1 {
|
||||
break;
|
||||
}
|
||||
Err(anyhow!("no medias found in favorite {} page {}", self.fid, page))?;
|
||||
}
|
||||
let videos_info: Vec<VideoInfo> = serde_json::from_value(medias.take())
|
||||
|
||||
@@ -82,6 +82,9 @@ impl<'a> Submission<'a> {
|
||||
.with_context(|| format!("failed to get videos of upper {} page {}", self.upper_id, page))?;
|
||||
let vlist = &mut videos["data"]["list"]["vlist"];
|
||||
if vlist.as_array().is_none_or(|v| v.is_empty()) {
|
||||
if page == 1 {
|
||||
break;
|
||||
}
|
||||
Err(anyhow!("no medias found in upper {} page {}", self.upper_id, page))?;
|
||||
}
|
||||
let videos_info: Vec<VideoInfo> = serde_json::from_value(vlist.take())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use anyhow::{Context, Result};
|
||||
use async_stream::try_stream;
|
||||
use futures::Stream;
|
||||
use serde_json::Value;
|
||||
@@ -38,7 +38,7 @@ impl<'a> WatchLater<'a> {
|
||||
.with_context(|| "Failed to get watch later list")?;
|
||||
let list = &mut videos["data"]["list"];
|
||||
if list.as_array().is_none_or(|v| v.is_empty()) {
|
||||
Err(anyhow!("No videos found in watch later list"))?;
|
||||
return;
|
||||
}
|
||||
let videos_info: Vec<VideoInfo> =
|
||||
serde_json::from_value(list.take()).with_context(|| "Failed to parse watch later list")?;
|
||||
|
||||
Reference in New Issue
Block a user