fix: handle video details not found
This commit is contained in:
parent
c618c83ff3
commit
0d1e569248
4 changed files with 1044 additions and 3 deletions
|
|
@ -27,7 +27,7 @@ pub struct VideoDetails {
|
|||
/// Video metadata + recommended videos
|
||||
pub contents: Contents,
|
||||
/// Video ID
|
||||
pub current_video_endpoint: CurrentVideoEndpoint,
|
||||
pub current_video_endpoint: Option<CurrentVideoEndpoint>,
|
||||
/// Video chapters + comment section
|
||||
#[serde_as(as = "VecLogError<_>")]
|
||||
pub engagement_panels: MapResult<Vec<EngagementPanel>>,
|
||||
|
|
|
|||
|
|
@ -92,7 +92,11 @@ impl MapResponse<VideoDetails> for response::VideoDetails {
|
|||
) -> Result<MapResult<VideoDetails>, ExtractionError> {
|
||||
let mut warnings = Vec::new();
|
||||
|
||||
let video_id = self.current_video_endpoint.watch_endpoint.video_id;
|
||||
let current_video_endpoint = self
|
||||
.current_video_endpoint
|
||||
.ok_or_else(|| ExtractionError::ContentUnavailable("Video not found".into()))?;
|
||||
|
||||
let video_id = current_video_endpoint.watch_endpoint.video_id;
|
||||
if id != video_id {
|
||||
return Err(ExtractionError::WrongResult(format!(
|
||||
"got wrong playlist id {}, expected {}",
|
||||
|
|
@ -571,7 +575,6 @@ mod tests {
|
|||
|
||||
let details: response::VideoDetails =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
dbg!(&details);
|
||||
let map_res = details.map_response(id, Language::En, None).unwrap();
|
||||
|
||||
assert!(
|
||||
|
|
@ -585,6 +588,21 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_video_details_not_found() {
|
||||
let filename = "testfiles/video_details/video_details_not_found.json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let details: response::VideoDetails =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
let err = details.map_response("", Language::En, None).unwrap_err();
|
||||
assert!(matches!(
|
||||
err,
|
||||
crate::error::ExtractionError::ContentUnavailable(_)
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_map_recommendations() {
|
||||
let json_path = Path::new("testfiles/video_details/recommendations.json");
|
||||
|
|
|
|||
1012
testfiles/video_details/video_details_not_found.json
Normal file
1012
testfiles/video_details/video_details_not_found.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -632,6 +632,17 @@ async fn get_video_details_agegate() {
|
|||
assert!(details.recommended.items.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_details_not_found() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
let err = rp.query().video_details("abcdefgLi5X").await.unwrap_err();
|
||||
|
||||
assert!(matches!(
|
||||
err,
|
||||
Error::Extraction(ExtractionError::ContentUnavailable(_))
|
||||
))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_video_recommendations() {
|
||||
let rp = RustyPipe::builder().strict().build();
|
||||
|
|
|
|||
Reference in a new issue