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,
|
||||
Artists,
|
||||
Albums,
|
||||
Playlists,
|
||||
PlaylistsYtm,
|
||||
PlaylistsCommunity,
|
||||
}
|
||||
|
|
@ -676,15 +675,10 @@ async fn main() {
|
|||
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
||||
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) => {
|
||||
let mut res = rp
|
||||
.query()
|
||||
.music_search_playlists_filter(&query, false)
|
||||
.music_search_playlists(&query, false)
|
||||
.await
|
||||
.unwrap();
|
||||
res.items.extend_limit(rp.query(), limit).await.unwrap();
|
||||
|
|
@ -693,7 +687,7 @@ async fn main() {
|
|||
Some(MusicSearchCategory::PlaylistsCommunity) => {
|
||||
let mut res = rp
|
||||
.query()
|
||||
.music_search_playlists_filter(&query, true)
|
||||
.music_search_playlists(&query, true)
|
||||
.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);
|
||||
rp.query()
|
||||
.music_search_playlists_filter("pop", community)
|
||||
.music_search_playlists("pop", community)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ enum Params {
|
|||
Albums,
|
||||
#[serde(rename = "EgWKAQIgAWoMEAMQBBAJEA4QChAF")]
|
||||
Artists,
|
||||
#[serde(rename = "EgWKAQIoAWoMEAMQBBAJEA4QChAF")]
|
||||
Playlists,
|
||||
#[serde(rename = "EgeKAQQoADgBagwQAxAEEAkQDhAKEAU%3D")]
|
||||
YtmPlaylists,
|
||||
#[serde(rename = "EgeKAQQoAEABagwQAxAEEAkQDhAKEAU%3D")]
|
||||
|
|
@ -152,44 +150,25 @@ impl RustyPipeQuery {
|
|||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// 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>>(
|
||||
&self,
|
||||
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,
|
||||
) -> 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> {
|
||||
let query = query.as_ref();
|
||||
let context = self.get_context(ClientType::DesktopMusic, true, None).await;
|
||||
let request_body = QSearch {
|
||||
context,
|
||||
query,
|
||||
params: Some(params),
|
||||
params: Some(if community {
|
||||
Params::CommunityPlaylists
|
||||
} else {
|
||||
Params::YtmPlaylists
|
||||
}),
|
||||
};
|
||||
|
||||
self.execute_request::<response::MusicSearch, _, _>(
|
||||
|
|
|
|||
|
|
@ -1808,18 +1808,12 @@ fn music_search_artists_cont(rp: RustyPipe) {
|
|||
}
|
||||
|
||||
#[rstest]
|
||||
#[case::ytm(false)]
|
||||
#[case::default(true)]
|
||||
fn music_search_playlists(#[case] with_community: bool, rp: RustyPipe, unlocalized: bool) {
|
||||
let res = if with_community {
|
||||
tokio_test::block_on(rp.query().music_search_playlists("today's rock hits")).unwrap()
|
||||
} else {
|
||||
tokio_test::block_on(
|
||||
rp.query()
|
||||
.music_search_playlists_filter("today's rock hits", false),
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
fn music_search_playlists(rp: RustyPipe, unlocalized: bool) {
|
||||
let res = tokio_test::block_on(
|
||||
rp.query()
|
||||
.music_search_playlists("today's rock hits", false),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(res.corrected_query, None);
|
||||
let playlist = res
|
||||
|
|
@ -1837,24 +1831,17 @@ fn music_search_playlists(#[case] with_community: bool, rp: RustyPipe, unlocaliz
|
|||
assert_eq!(playlist.channel, None);
|
||||
assert!(playlist.from_ytm);
|
||||
|
||||
if with_community {
|
||||
assert!(
|
||||
res.items.items.iter().any(|p| !p.from_ytm),
|
||||
"no community items found"
|
||||
)
|
||||
} else {
|
||||
assert!(
|
||||
res.items.items.iter().all(|p| p.from_ytm),
|
||||
"community items found"
|
||||
)
|
||||
}
|
||||
assert!(
|
||||
res.items.items.iter().all(|p| p.from_ytm),
|
||||
"community items found"
|
||||
)
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn music_search_playlists_community(rp: RustyPipe) {
|
||||
let res = tokio_test::block_on(
|
||||
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();
|
||||
|
||||
|
|
|
|||
Reference in a new issue