fix!: remove music playlist search without filter
This commit is contained in:
parent
031b730c47
commit
8ea69d5453
4 changed files with 22 additions and 62 deletions
|
|
@ -173,7 +173,6 @@ enum MusicSearchCategory {
|
||||||
Videos,
|
Videos,
|
||||||
Artists,
|
Artists,
|
||||||
Albums,
|
Albums,
|
||||||
Playlists,
|
|
||||||
PlaylistsYtm,
|
PlaylistsYtm,
|
||||||
PlaylistsCommunity,
|
PlaylistsCommunity,
|
||||||
}
|
}
|
||||||
|
|
@ -676,15 +675,10 @@ async fn main() {
|
||||||
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
||||||
print_data(&res, format, pretty);
|
print_data(&res, format, pretty);
|
||||||
}
|
}
|
||||||
Some(MusicSearchCategory::Playlists) => {
|
|
||||||
let mut res = rp.query().music_search_playlists(&query).await.unwrap();
|
|
||||||
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
|
||||||
print_data(&res, format, pretty);
|
|
||||||
}
|
|
||||||
Some(MusicSearchCategory::PlaylistsYtm) => {
|
Some(MusicSearchCategory::PlaylistsYtm) => {
|
||||||
let mut res = rp
|
let mut res = rp
|
||||||
.query()
|
.query()
|
||||||
.music_search_playlists_filter(&query, false)
|
.music_search_playlists(&query, false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
||||||
|
|
@ -693,7 +687,7 @@ async fn main() {
|
||||||
Some(MusicSearchCategory::PlaylistsCommunity) => {
|
Some(MusicSearchCategory::PlaylistsCommunity) => {
|
||||||
let mut res = rp
|
let mut res = rp
|
||||||
.query()
|
.query()
|
||||||
.music_search_playlists_filter(&query, true)
|
.music_search_playlists(&query, true)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -619,7 +619,7 @@ async fn music_search_playlists() {
|
||||||
|
|
||||||
let rp = rp_testfile(&json_path);
|
let rp = rp_testfile(&json_path);
|
||||||
rp.query()
|
rp.query()
|
||||||
.music_search_playlists_filter("pop", community)
|
.music_search_playlists("pop", community)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ enum Params {
|
||||||
Albums,
|
Albums,
|
||||||
#[serde(rename = "EgWKAQIgAWoMEAMQBBAJEA4QChAF")]
|
#[serde(rename = "EgWKAQIgAWoMEAMQBBAJEA4QChAF")]
|
||||||
Artists,
|
Artists,
|
||||||
#[serde(rename = "EgWKAQIoAWoMEAMQBBAJEA4QChAF")]
|
|
||||||
Playlists,
|
|
||||||
#[serde(rename = "EgeKAQQoADgBagwQAxAEEAkQDhAKEAU%3D")]
|
#[serde(rename = "EgeKAQQoADgBagwQAxAEEAkQDhAKEAU%3D")]
|
||||||
YtmPlaylists,
|
YtmPlaylists,
|
||||||
#[serde(rename = "EgeKAQQoAEABagwQAxAEEAkQDhAKEAU%3D")]
|
#[serde(rename = "EgeKAQQoAEABagwQAxAEEAkQDhAKEAU%3D")]
|
||||||
|
|
@ -152,44 +150,25 @@ impl RustyPipeQuery {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search YouTube Music playlists
|
/// Search YouTube Music playlists
|
||||||
|
///
|
||||||
|
/// Playlists are filtered whether they are created by users
|
||||||
|
/// (`community=true`) or by YouTube Music (`community=false`)
|
||||||
pub async fn music_search_playlists<S: AsRef<str>>(
|
pub async fn music_search_playlists<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: S,
|
query: S,
|
||||||
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
|
||||||
self._music_search_playlists(query, Params::Playlists).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Search YouTube Music playlists that were created by users
|
|
||||||
/// (`community=true`) or by YouTube Music (`community=false`)
|
|
||||||
pub async fn music_search_playlists_filter<S: AsRef<str>>(
|
|
||||||
&self,
|
|
||||||
query: S,
|
|
||||||
community: bool,
|
community: bool,
|
||||||
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
|
||||||
self._music_search_playlists(
|
|
||||||
query,
|
|
||||||
if community {
|
|
||||||
Params::CommunityPlaylists
|
|
||||||
} else {
|
|
||||||
Params::YtmPlaylists
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn _music_search_playlists<S: AsRef<str>>(
|
|
||||||
&self,
|
|
||||||
query: S,
|
|
||||||
params: Params,
|
|
||||||
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
||||||
let query = query.as_ref();
|
let query = query.as_ref();
|
||||||
let context = self.get_context(ClientType::DesktopMusic, true, None).await;
|
let context = self.get_context(ClientType::DesktopMusic, true, None).await;
|
||||||
let request_body = QSearch {
|
let request_body = QSearch {
|
||||||
context,
|
context,
|
||||||
query,
|
query,
|
||||||
params: Some(params),
|
params: Some(if community {
|
||||||
|
Params::CommunityPlaylists
|
||||||
|
} else {
|
||||||
|
Params::YtmPlaylists
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.execute_request::<response::MusicSearch, _, _>(
|
self.execute_request::<response::MusicSearch, _, _>(
|
||||||
|
|
|
||||||
|
|
@ -1808,18 +1808,12 @@ fn music_search_artists_cont(rp: RustyPipe) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case::ytm(false)]
|
fn music_search_playlists(rp: RustyPipe, unlocalized: bool) {
|
||||||
#[case::default(true)]
|
let res = tokio_test::block_on(
|
||||||
fn music_search_playlists(#[case] with_community: bool, rp: RustyPipe, unlocalized: bool) {
|
rp.query()
|
||||||
let res = if with_community {
|
.music_search_playlists("today's rock hits", false),
|
||||||
tokio_test::block_on(rp.query().music_search_playlists("today's rock hits")).unwrap()
|
)
|
||||||
} else {
|
.unwrap();
|
||||||
tokio_test::block_on(
|
|
||||||
rp.query()
|
|
||||||
.music_search_playlists_filter("today's rock hits", false),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(res.corrected_query, None);
|
assert_eq!(res.corrected_query, None);
|
||||||
let playlist = res
|
let playlist = res
|
||||||
|
|
@ -1837,24 +1831,17 @@ fn music_search_playlists(#[case] with_community: bool, rp: RustyPipe, unlocaliz
|
||||||
assert_eq!(playlist.channel, None);
|
assert_eq!(playlist.channel, None);
|
||||||
assert!(playlist.from_ytm);
|
assert!(playlist.from_ytm);
|
||||||
|
|
||||||
if with_community {
|
assert!(
|
||||||
assert!(
|
res.items.items.iter().all(|p| p.from_ytm),
|
||||||
res.items.items.iter().any(|p| !p.from_ytm),
|
"community items found"
|
||||||
"no community items found"
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
assert!(
|
|
||||||
res.items.items.iter().all(|p| p.from_ytm),
|
|
||||||
"community items found"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn music_search_playlists_community(rp: RustyPipe) {
|
fn music_search_playlists_community(rp: RustyPipe) {
|
||||||
let res = tokio_test::block_on(
|
let res = tokio_test::block_on(
|
||||||
rp.query()
|
rp.query()
|
||||||
.music_search_playlists_filter("Best Pop Music Videos - Top Pop Hits Playlist", true),
|
.music_search_playlists("Best Pop Music Videos - Top Pop Hits Playlist", true),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue