diff --git a/src/client/music_playlist.rs b/src/client/music_playlist.rs index 92f9fcf..ccd5f21 100644 --- a/src/client/music_playlist.rs +++ b/src/client/music_playlist.rs @@ -151,7 +151,25 @@ impl MapResponse for response::MusicPlaylist { self, ctx: &MapRespCtx<'_>, ) -> Result, 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 for response::MusicPlaylist { impl MapResponse for response::MusicPlaylist { fn map_response(self, ctx: &MapRespCtx<'_>) -> Result, 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,12 +490,13 @@ impl MapResponse 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=") - .map(str::to_owned) - }); + 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 .menu .or_else(|| header.buttons.into_iter().next()) diff --git a/src/client/response/music_playlist.rs b/src/client/response/music_playlist.rs index 0cb1a17..05abfbb 100644 --- a/src/client/response/music_playlist.rs +++ b/src/client/response/music_playlist.rs @@ -16,7 +16,7 @@ use super::{ #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub(crate) struct MusicPlaylist { - pub contents: Contents, + pub contents: Option, pub header: Option
, #[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, + #[serde(default)] + pub noindex: bool, } diff --git a/src/deobfuscate.rs b/src/deobfuscate.rs index 24ed4a7..1ff1c32 100644 --- a/src/deobfuscate.rs +++ b/src/deobfuscate.rs @@ -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();