refactor: generic search API
This commit is contained in:
parent
48ccfc5c06
commit
8458d878e7
21 changed files with 2185 additions and 2262 deletions
|
|
@ -7,7 +7,7 @@ use num_enum::TryFromPrimitive;
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use rustypipe::client::{ClientType, RustyPipe, RustyPipeQuery, YTContext};
|
||||
use rustypipe::model::YouTubeItem;
|
||||
use rustypipe::model::{MusicItem, YouTubeItem};
|
||||
use rustypipe::param::search_filter::{ItemType, SearchFilter};
|
||||
use serde::de::IgnoredAny;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -274,14 +274,25 @@ pub async fn playlists_for_shorts(rp: &RustyPipeQuery) -> Result<bool> {
|
|||
}
|
||||
|
||||
pub async fn track_viewcount(rp: &RustyPipeQuery) -> Result<bool> {
|
||||
let res = rp.music_search("lieblingsmensch namika").await?;
|
||||
let res = rp.music_search_main("lieblingsmensch namika").await?;
|
||||
|
||||
let track = &res
|
||||
.tracks
|
||||
.items
|
||||
.items
|
||||
.iter()
|
||||
.find(|a| a.id == "6485PhOtHzY")
|
||||
.find_map(|itm| {
|
||||
if let MusicItem::Track(track) = itm {
|
||||
if track.id == "6485PhOtHzY" {
|
||||
Some(track)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
panic!("could not find track, got {:#?}", &res.tracks);
|
||||
panic!("could not find track, got {:#?}", &res.items.items);
|
||||
});
|
||||
|
||||
Ok(track.view_count.is_some())
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use std::{
|
|||
use path_macro::path;
|
||||
use rustypipe::{
|
||||
client::{ClientType, RustyPipe},
|
||||
model::YouTubeItem,
|
||||
param::{
|
||||
search_filter::{self, ItemType, SearchFilter},
|
||||
ChannelVideoTab, Country,
|
||||
|
|
@ -392,7 +393,10 @@ async fn search() {
|
|||
}
|
||||
|
||||
let rp = rp_testfile(&json_path);
|
||||
rp.query().search("doobydoobap").await.unwrap();
|
||||
rp.query()
|
||||
.search::<YouTubeItem, _>("doobydoobap")
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
async fn search_cont() {
|
||||
|
|
@ -402,7 +406,11 @@ async fn search_cont() {
|
|||
}
|
||||
|
||||
let rp = RustyPipe::new();
|
||||
let search = rp.query().search("doobydoobap").await.unwrap();
|
||||
let search = rp
|
||||
.query()
|
||||
.search::<YouTubeItem, _>("doobydoobap")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let rp = rp_testfile(&json_path);
|
||||
search.items.next(rp.query()).await.unwrap().unwrap();
|
||||
|
|
@ -416,7 +424,7 @@ async fn search_playlists() {
|
|||
|
||||
let rp = rp_testfile(&json_path);
|
||||
rp.query()
|
||||
.search_filter("pop", &SearchFilter::new().item_type(ItemType::Playlist))
|
||||
.search_filter::<YouTubeItem, _>("pop", &SearchFilter::new().item_type(ItemType::Playlist))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
|
@ -429,7 +437,7 @@ async fn search_empty() {
|
|||
|
||||
let rp = rp_testfile(&json_path);
|
||||
rp.query()
|
||||
.search_filter(
|
||||
.search_filter::<YouTubeItem, _>(
|
||||
"test",
|
||||
&SearchFilter::new()
|
||||
.feature(search_filter::Feature::IsLive)
|
||||
|
|
@ -558,7 +566,7 @@ async fn music_search() {
|
|||
}
|
||||
|
||||
let rp = rp_testfile(&json_path);
|
||||
rp.query().music_search(query).await.unwrap();
|
||||
rp.query().music_search_main(query).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue