refactor: use generic string arguments
This commit is contained in:
parent
94b55711cb
commit
8097873fe1
12 changed files with 111 additions and 60 deletions
|
|
@ -41,12 +41,13 @@ enum Params {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
async fn _channel_videos(
|
async fn _channel_videos<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
channel_id: &str,
|
channel_id: S,
|
||||||
params: Params,
|
params: Params,
|
||||||
operation: &str,
|
operation: &str,
|
||||||
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
||||||
|
let channel_id = channel_id.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QChannel {
|
let request_body = QChannel {
|
||||||
context,
|
context,
|
||||||
|
|
@ -57,41 +58,42 @@ impl RustyPipeQuery {
|
||||||
self.execute_request::<response::Channel, _, _>(
|
self.execute_request::<response::Channel, _, _>(
|
||||||
ClientType::Desktop,
|
ClientType::Desktop,
|
||||||
operation,
|
operation,
|
||||||
channel_id,
|
channel_id.as_ref(),
|
||||||
"browse",
|
"browse",
|
||||||
&request_body,
|
&request_body,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn channel_videos(
|
pub async fn channel_videos<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
channel_id: &str,
|
channel_id: S,
|
||||||
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
||||||
self._channel_videos(channel_id, Params::Videos, "channel_videos")
|
self._channel_videos(channel_id, Params::Videos, "channel_videos")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn channel_shorts(
|
pub async fn channel_shorts<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
channel_id: &str,
|
channel_id: S,
|
||||||
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
||||||
self._channel_videos(channel_id, Params::Shorts, "channel_shorts")
|
self._channel_videos(channel_id, Params::Shorts, "channel_shorts")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn channel_livestreams(
|
pub async fn channel_livestreams<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
channel_id: &str,
|
channel_id: S,
|
||||||
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
) -> Result<Channel<Paginator<VideoItem>>, Error> {
|
||||||
self._channel_videos(channel_id, Params::Live, "channel_livestreams")
|
self._channel_videos(channel_id, Params::Live, "channel_livestreams")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn channel_playlists(
|
pub async fn channel_playlists<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
channel_id: &str,
|
channel_id: S,
|
||||||
) -> Result<Channel<Paginator<PlaylistItem>>, Error> {
|
) -> Result<Channel<Paginator<PlaylistItem>>, Error> {
|
||||||
|
let channel_id = channel_id.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QChannel {
|
let request_body = QChannel {
|
||||||
context,
|
context,
|
||||||
|
|
@ -109,7 +111,11 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn channel_info(&self, channel_id: &str) -> Result<Channel<ChannelInfo>, Error> {
|
pub async fn channel_info<S: AsRef<str>>(
|
||||||
|
&self,
|
||||||
|
channel_id: S,
|
||||||
|
) -> Result<Channel<ChannelInfo>, Error> {
|
||||||
|
let channel_id = channel_id.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QChannel {
|
let request_body = QChannel {
|
||||||
context,
|
context,
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ use crate::{
|
||||||
use super::{response, RustyPipeQuery};
|
use super::{response, RustyPipeQuery};
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn channel_rss(&self, channel_id: &str) -> Result<ChannelRss, Error> {
|
pub async fn channel_rss<S: AsRef<str>>(&self, channel_id: S) -> Result<ChannelRss, Error> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"https://www.youtube.com/feeds/videos.xml?channel_id={}",
|
"https://www.youtube.com/feeds/videos.xml?channel_id={}",
|
||||||
channel_id
|
channel_id.as_ref()
|
||||||
);
|
);
|
||||||
let xml = self
|
let xml = self
|
||||||
.client
|
.client
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,13 @@ struct QBrowseParams<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn music_artist(
|
pub async fn music_artist<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
artist_id: &str,
|
artist_id: S,
|
||||||
all_albums: bool,
|
all_albums: bool,
|
||||||
) -> Result<MusicArtist, Error> {
|
) -> Result<MusicArtist, Error> {
|
||||||
|
let artist_id = artist_id.as_ref();
|
||||||
|
|
||||||
if all_albums {
|
if all_albums {
|
||||||
let visitor_data = self.get_ytm_visitor_data().await?;
|
let visitor_data = self.get_ytm_visitor_data().await?;
|
||||||
let context = self
|
let context = self
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@ struct QRadio<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn music_details(&self, video_id: &str) -> Result<TrackDetails, Error> {
|
pub async fn music_details<S: AsRef<str>>(&self, video_id: S) -> Result<TrackDetails, Error> {
|
||||||
|
let video_id = video_id.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 = QMusicDetails {
|
let request_body = QMusicDetails {
|
||||||
context,
|
context,
|
||||||
|
|
@ -57,7 +58,8 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_lyrics(&self, lyrics_id: &str) -> Result<Lyrics, Error> {
|
pub async fn music_lyrics<S: AsRef<str>>(&self, lyrics_id: S) -> Result<Lyrics, Error> {
|
||||||
|
let lyrics_id = lyrics_id.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 = QBrowse {
|
let request_body = QBrowse {
|
||||||
context,
|
context,
|
||||||
|
|
@ -74,7 +76,8 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_related(&self, related_id: &str) -> Result<MusicRelated, Error> {
|
pub async fn music_related<S: AsRef<str>>(&self, related_id: S) -> Result<MusicRelated, Error> {
|
||||||
|
let related_id = related_id.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 = QBrowse {
|
let request_body = QBrowse {
|
||||||
context,
|
context,
|
||||||
|
|
@ -91,7 +94,11 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_radio(&self, radio_id: &str) -> Result<Paginator<TrackItem>, Error> {
|
pub async fn music_radio<S: AsRef<str>>(
|
||||||
|
&self,
|
||||||
|
radio_id: S,
|
||||||
|
) -> Result<Paginator<TrackItem>, Error> {
|
||||||
|
let radio_id = radio_id.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 = QRadio {
|
let request_body = QRadio {
|
||||||
context,
|
context,
|
||||||
|
|
@ -112,15 +119,20 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_radio_track(&self, video_id: &str) -> Result<Paginator<TrackItem>, Error> {
|
pub async fn music_radio_track<S: AsRef<str>>(
|
||||||
self.music_radio(&format!("RDAMVM{}", video_id)).await
|
&self,
|
||||||
|
video_id: S,
|
||||||
|
) -> Result<Paginator<TrackItem>, Error> {
|
||||||
|
self.music_radio(&format!("RDAMVM{}", video_id.as_ref()))
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_radio_playlist(
|
pub async fn music_radio_playlist<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
playlist_id: &str,
|
playlist_id: S,
|
||||||
) -> Result<Paginator<TrackItem>, Error> {
|
) -> Result<Paginator<TrackItem>, Error> {
|
||||||
self.music_radio(&format!("RDAMPL{}", playlist_id)).await
|
self.music_radio(&format!("RDAMPL{}", playlist_id.as_ref()))
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@ use super::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn music_playlist(&self, playlist_id: &str) -> Result<MusicPlaylist, Error> {
|
pub async fn music_playlist<S: AsRef<str>>(
|
||||||
|
&self,
|
||||||
|
playlist_id: S,
|
||||||
|
) -> Result<MusicPlaylist, Error> {
|
||||||
|
let playlist_id = playlist_id.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 = QBrowse {
|
let request_body = QBrowse {
|
||||||
context,
|
context,
|
||||||
|
|
@ -33,7 +37,8 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_album(&self, album_id: &str) -> Result<MusicAlbum, Error> {
|
pub async fn music_album<S: AsRef<str>>(&self, album_id: S) -> Result<MusicAlbum, Error> {
|
||||||
|
let album_id = album_id.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 = QBrowse {
|
let request_body = QBrowse {
|
||||||
context,
|
context,
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ enum Params {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn music_search(&self, query: &str) -> Result<MusicSearchResult, Error> {
|
pub async fn music_search<S: AsRef<str>>(&self, query: S) -> Result<MusicSearchResult, Error> {
|
||||||
|
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,
|
||||||
|
|
@ -68,25 +69,26 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_search_tracks(
|
pub async fn music_search_tracks<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
) -> Result<MusicSearchFiltered<TrackItem>, Error> {
|
) -> Result<MusicSearchFiltered<TrackItem>, Error> {
|
||||||
self._music_search_tracks(query, Params::Tracks).await
|
self._music_search_tracks(query, Params::Tracks).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_search_videos(
|
pub async fn music_search_videos<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
) -> Result<MusicSearchFiltered<TrackItem>, Error> {
|
) -> Result<MusicSearchFiltered<TrackItem>, Error> {
|
||||||
self._music_search_tracks(query, Params::Videos).await
|
self._music_search_tracks(query, Params::Videos).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _music_search_tracks(
|
async fn _music_search_tracks<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
params: Params,
|
params: Params,
|
||||||
) -> Result<MusicSearchFiltered<TrackItem>, Error> {
|
) -> Result<MusicSearchFiltered<TrackItem>, Error> {
|
||||||
|
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,
|
||||||
|
|
@ -104,10 +106,11 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_search_albums(
|
pub async fn music_search_albums<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
) -> Result<MusicSearchFiltered<AlbumItem>, Error> {
|
) -> Result<MusicSearchFiltered<AlbumItem>, Error> {
|
||||||
|
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,
|
||||||
|
|
@ -146,16 +149,16 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_search_playlists(
|
pub async fn music_search_playlists<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
||||||
self._music_search_playlists(query, Params::Playlists).await
|
self._music_search_playlists(query, Params::Playlists).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_search_playlists_filter(
|
pub async fn music_search_playlists_filter<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
community: bool,
|
community: bool,
|
||||||
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
||||||
self._music_search_playlists(
|
self._music_search_playlists(
|
||||||
|
|
@ -168,11 +171,12 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _music_search_playlists(
|
async fn _music_search_playlists<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
params: Params,
|
params: Params,
|
||||||
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
) -> Result<MusicSearchFiltered<MusicPlaylistItem>, Error> {
|
||||||
|
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,
|
||||||
|
|
@ -190,7 +194,11 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn music_search_suggestion(&self, query: &str) -> Result<Vec<String>, Error> {
|
pub async fn music_search_suggestion<S: AsRef<str>>(
|
||||||
|
&self,
|
||||||
|
query: S,
|
||||||
|
) -> Result<Vec<String>, Error> {
|
||||||
|
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 = QSearchSuggestion {
|
let request_body = QSearchSuggestion {
|
||||||
context,
|
context,
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,13 @@ use super::response::music_item::{map_queue_item, MusicListMapper, PlaylistPanel
|
||||||
use super::{response, ClientType, MapResponse, QContinuation, RustyPipeQuery};
|
use super::{response, ClientType, MapResponse, QContinuation, RustyPipeQuery};
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn continuation<T: FromYtItem>(
|
pub async fn continuation<T: FromYtItem, S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
ctoken: &str,
|
ctoken: S,
|
||||||
endpoint: ContinuationEndpoint,
|
endpoint: ContinuationEndpoint,
|
||||||
visitor_data: Option<&str>,
|
visitor_data: Option<&str>,
|
||||||
) -> Result<Paginator<T>, Error> {
|
) -> Result<Paginator<T>, Error> {
|
||||||
|
let ctoken = ctoken.as_ref();
|
||||||
if endpoint.is_music() {
|
if endpoint.is_music() {
|
||||||
let context = self
|
let context = self
|
||||||
.get_context(ClientType::DesktopMusic, true, visitor_data)
|
.get_context(ClientType::DesktopMusic, true, visitor_data)
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ struct QContentPlaybackContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn player(&self, video_id: &str) -> Result<VideoPlayer, Error> {
|
pub async fn player<S: AsRef<str>>(&self, video_id: S) -> Result<VideoPlayer, Error> {
|
||||||
|
let video_id = video_id.as_ref();
|
||||||
let q1 = self.clone();
|
let q1 = self.clone();
|
||||||
let android_res = q1.player_from_client(video_id, ClientType::Android).await;
|
let android_res = q1.player_from_client(video_id, ClientType::Android).await;
|
||||||
|
|
||||||
|
|
@ -85,11 +86,12 @@ impl RustyPipeQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn player_from_client(
|
pub async fn player_from_client<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
video_id: &str,
|
video_id: S,
|
||||||
client_type: ClientType,
|
client_type: ClientType,
|
||||||
) -> Result<VideoPlayer, Error> {
|
) -> Result<VideoPlayer, Error> {
|
||||||
|
let video_id = video_id.as_ref();
|
||||||
let (context, deobf) = tokio::join!(
|
let (context, deobf) = tokio::join!(
|
||||||
self.get_context(client_type, false, None),
|
self.get_context(client_type, false, None),
|
||||||
self.client.get_deobf()
|
self.client.get_deobf()
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ use crate::{
|
||||||
use super::{response, ClientType, MapResponse, MapResult, QBrowse, QContinuation, RustyPipeQuery};
|
use super::{response, ClientType, MapResponse, MapResult, QBrowse, QContinuation, RustyPipeQuery};
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn playlist(&self, playlist_id: &str) -> Result<Playlist, Error> {
|
pub async fn playlist<S: AsRef<str>>(&self, playlist_id: S) -> Result<Playlist, Error> {
|
||||||
|
let playlist_id = playlist_id.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QBrowse {
|
let request_body = QBrowse {
|
||||||
context,
|
context,
|
||||||
|
|
@ -31,10 +32,11 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn playlist_continuation(
|
pub async fn playlist_continuation<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
ctoken: &str,
|
ctoken: S,
|
||||||
) -> Result<Paginator<PlaylistVideo>, Error> {
|
) -> Result<Paginator<PlaylistVideo>, Error> {
|
||||||
|
let ctoken = ctoken.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QContinuation {
|
let request_body = QContinuation {
|
||||||
context,
|
context,
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ struct QSearch<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn search(&self, query: &str) -> Result<SearchResult, Error> {
|
pub async fn search<S: AsRef<str>>(&self, query: S) -> Result<SearchResult, Error> {
|
||||||
|
let query = query.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QSearch {
|
let request_body = QSearch {
|
||||||
context,
|
context,
|
||||||
|
|
@ -39,11 +40,12 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn search_filter(
|
pub async fn search_filter<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: S,
|
||||||
filter: &SearchFilter,
|
filter: &SearchFilter,
|
||||||
) -> Result<SearchResult, Error> {
|
) -> Result<SearchResult, Error> {
|
||||||
|
let query = query.as_ref();
|
||||||
let context = self.get_context(ClientType::Desktop, true, None).await;
|
let context = self.get_context(ClientType::Desktop, true, None).await;
|
||||||
let request_body = QSearch {
|
let request_body = QSearch {
|
||||||
context,
|
context,
|
||||||
|
|
@ -61,9 +63,9 @@ impl RustyPipeQuery {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn search_suggestion(&self, query: &str) -> Result<Vec<String>, Error> {
|
pub async fn search_suggestion<S: AsRef<str>>(&self, query: S) -> Result<Vec<String>, Error> {
|
||||||
let url = url::Url::parse_with_params("https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&gs_rn=64&gs_ri=youtube&ds=yt&cp=1&gs_id=4&xhr=t&xssi=t",
|
let url = url::Url::parse_with_params("https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&gs_rn=64&gs_ri=youtube&ds=yt&cp=1&gs_id=4&xhr=t&xssi=t",
|
||||||
&[("hl", self.opts.lang.to_string()), ("gl", self.opts.country.to_string()), ("q", query.to_string())]
|
&[("hl", self.opts.lang.to_string()), ("gl", self.opts.country.to_string()), ("q", query.as_ref().to_owned())]
|
||||||
).map_err(|_| Error::Other("could not build url".into()))?;
|
).map_err(|_| Error::Other("could not build url".into()))?;
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,12 @@ struct QResolveUrl<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustyPipeQuery {
|
impl RustyPipeQuery {
|
||||||
pub async fn resolve_url(self, url: &str, resolve_albums: bool) -> Result<UrlTarget, Error> {
|
pub async fn resolve_url<S: AsRef<str>>(
|
||||||
let (url, params) = util::url_to_params(url)?;
|
self,
|
||||||
|
url: S,
|
||||||
|
resolve_albums: bool,
|
||||||
|
) -> Result<UrlTarget, Error> {
|
||||||
|
let (url, params) = util::url_to_params(url.as_ref())?;
|
||||||
|
|
||||||
let mut is_shortlink = url.domain().and_then(|d| match d {
|
let mut is_shortlink = url.domain().and_then(|d| match d {
|
||||||
"youtu.be" => Some(true),
|
"youtu.be" => Some(true),
|
||||||
|
|
|
||||||
|
|
@ -1609,8 +1609,15 @@ async fn music_search_episode() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let track = &res.items.items[0];
|
let (i, track) = &res
|
||||||
assert_eq!(track.id, "Zq_-LDy7AgE");
|
.items
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_, a)| a.id == "Zq_-LDy7AgE")
|
||||||
|
.unwrap();
|
||||||
|
assert!(*i < 3);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
track.title,
|
track.title,
|
||||||
"Blond - Da muss man dabei gewesen sein: Das Hörspiel - Fall #1"
|
"Blond - Da muss man dabei gewesen sein: Das Hörspiel - Fall #1"
|
||||||
|
|
|
||||||
Reference in a new issue