fix: handle music playlist/album not found
This commit is contained in:
parent
939a7aea61
commit
ea80717f69
3 changed files with 59 additions and 10 deletions
|
|
@ -151,7 +151,25 @@ impl MapResponse<MusicPlaylist> for response::MusicPlaylist {
|
|||
self,
|
||||
ctx: &MapRespCtx<'_>,
|
||||
) -> Result<MapResult<MusicPlaylist>, ExtractionError> {
|
||||
let (header, music_contents) = match self.contents {
|
||||
let contents = match self.contents {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
if self
|
||||
.microformat
|
||||
.map(|m| m.microformat_data_renderer.noindex)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
return Err(ExtractionError::NotFound {
|
||||
id: ctx.id.to_owned(),
|
||||
msg: "no contents".into(),
|
||||
});
|
||||
} else {
|
||||
return Err(ExtractionError::InvalidData("no contents".into()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let (header, music_contents) = match contents {
|
||||
response::music_playlist::Contents::SingleColumnBrowseResultsRenderer(c) => (
|
||||
self.header,
|
||||
c.contents
|
||||
|
|
@ -338,7 +356,25 @@ impl MapResponse<MusicPlaylist> for response::MusicPlaylist {
|
|||
|
||||
impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
||||
fn map_response(self, ctx: &MapRespCtx<'_>) -> Result<MapResult<MusicAlbum>, ExtractionError> {
|
||||
let (header, sections) = match self.contents {
|
||||
let contents = match self.contents {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
if self
|
||||
.microformat
|
||||
.map(|m| m.microformat_data_renderer.noindex)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
return Err(ExtractionError::NotFound {
|
||||
id: ctx.id.to_owned(),
|
||||
msg: "no contents".into(),
|
||||
});
|
||||
} else {
|
||||
return Err(ExtractionError::InvalidData("no contents".into()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let (header, sections) = match contents {
|
||||
response::music_playlist::Contents::SingleColumnBrowseResultsRenderer(c) => (
|
||||
self.header,
|
||||
c.contents
|
||||
|
|
@ -454,10 +490,11 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
|||
}
|
||||
}
|
||||
|
||||
let playlist_id = self.microformat.and_then(|mf| {
|
||||
mf.microformat_data_renderer
|
||||
.url_canonical
|
||||
.strip_prefix("https://music.youtube.com/playlist?list=")
|
||||
let playlist_id = self
|
||||
.microformat
|
||||
.and_then(|mf| mf.microformat_data_renderer.url_canonical)
|
||||
.and_then(|x| {
|
||||
x.strip_prefix("https://music.youtube.com/playlist?list=")
|
||||
.map(str::to_owned)
|
||||
});
|
||||
let (playlist_id, artist_id) = header
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use super::{
|
|||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct MusicPlaylist {
|
||||
pub contents: Contents,
|
||||
pub contents: Option<Contents>,
|
||||
pub header: Option<Header>,
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "DefaultOnError")]
|
||||
|
|
@ -172,5 +172,7 @@ pub(crate) struct Microformat {
|
|||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct MicroformatData {
|
||||
pub url_canonical: String,
|
||||
pub url_canonical: Option<String>,
|
||||
#[serde(default)]
|
||||
pub noindex: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -654,6 +654,16 @@ c[36](c[8],c[32]),c[20](c[25],c[10]),c[2](c[22],c[8]),c[32](c[20],c[16]),c[32](c
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_extract_js_fn_outside_vars4() {
|
||||
let base_js = "let a0=123456;let a1=function(a){return a};let Wka = function(d){var x=1+2+a1();return x;}";
|
||||
let res = extract_js_fn(base_js, "Wka").unwrap();
|
||||
assert_eq!(
|
||||
res,
|
||||
"var a1=function(a){return a}; var Wka = function(d){var x=1+2+a1();return x;};"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_get_nsig_fn() {
|
||||
let res = get_nsig_fn(&TEST_JS).unwrap();
|
||||
|
|
|
|||
Reference in a new issue