Compare commits
No commits in common. "3458924018c6b1d943f20e1fc0a3f22e62f4b483" and "2a4233e5d529c527ab7db0e6da23eb28b08a534f" have entirely different histories.
3458924018
...
2a4233e5d5
3 changed files with 26 additions and 89 deletions
|
@ -25,9 +25,6 @@ impl RustyPipeQuery {
|
||||||
/// Note that the hostname of the URL is not checked, so this function also accepts URLs
|
/// Note that the hostname of the URL is not checked, so this function also accepts URLs
|
||||||
/// from alternative YouTube frontends like Piped or Invidious.
|
/// from alternative YouTube frontends like Piped or Invidious.
|
||||||
///
|
///
|
||||||
/// The `resolve_albums` flag enables resolving YTM album URLs (e.g.
|
|
||||||
/// `OLAK5uy_k0yFrZlFRgCf3rLPza-lkRmCrtLPbK9pE`) to their short album id (`MPREb_GyH43gCvdM5`).
|
|
||||||
///
|
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// # use rustypipe::client::RustyPipe;
|
/// # use rustypipe::client::RustyPipe;
|
||||||
|
@ -199,9 +196,6 @@ impl RustyPipeQuery {
|
||||||
/// Accepted input strings include YouTube URLs (see [`RustyPipeQuery::resolve_url`]),
|
/// Accepted input strings include YouTube URLs (see [`RustyPipeQuery::resolve_url`]),
|
||||||
/// Video/Channel/Playlist/Album IDs and channel handles / vanity IDs.
|
/// Video/Channel/Playlist/Album IDs and channel handles / vanity IDs.
|
||||||
///
|
///
|
||||||
/// The `resolve_albums` flag enables resolving YTM album URLs and IDs (e.g.
|
|
||||||
/// `OLAK5uy_k0yFrZlFRgCf3rLPza-lkRmCrtLPbK9pE`) to their short album id (`MPREb_GyH43gCvdM5`).
|
|
||||||
///
|
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// # use rustypipe::client::RustyPipe;
|
/// # use rustypipe::client::RustyPipe;
|
||||||
|
@ -220,47 +214,51 @@ impl RustyPipeQuery {
|
||||||
/// );
|
/// );
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn resolve_string<S: AsRef<str>>(
|
pub async fn resolve_string(
|
||||||
self,
|
self,
|
||||||
s: S,
|
string: &str,
|
||||||
resolve_albums: bool,
|
resolve_albums: bool,
|
||||||
) -> Result<UrlTarget, Error> {
|
) -> Result<UrlTarget, Error> {
|
||||||
let s = s.as_ref();
|
|
||||||
|
|
||||||
// URL with protocol
|
// URL with protocol
|
||||||
if s.starts_with("http://") || s.starts_with("https://") {
|
if string.starts_with("http://") || string.starts_with("https://") {
|
||||||
self.resolve_url(s, resolve_albums).await
|
self.resolve_url(string, resolve_albums).await
|
||||||
}
|
}
|
||||||
// URL without protocol
|
// URL without protocol
|
||||||
else if s.contains('/') && s.contains('.') {
|
else if string.contains('/') && string.contains('.') {
|
||||||
self.resolve_url(&format!("https://{s}"), resolve_albums)
|
self.resolve_url(&format!("https://{string}"), resolve_albums)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
// ID only
|
// ID only
|
||||||
else if util::VIDEO_ID_REGEX.is_match(s) {
|
else if util::VIDEO_ID_REGEX.is_match(string) {
|
||||||
Ok(UrlTarget::Video {
|
Ok(UrlTarget::Video {
|
||||||
id: s.to_owned(),
|
id: string.to_owned(),
|
||||||
start_time: 0,
|
start_time: 0,
|
||||||
})
|
})
|
||||||
} else if util::CHANNEL_ID_REGEX.is_match(s) {
|
} else if util::CHANNEL_ID_REGEX.is_match(string) {
|
||||||
Ok(UrlTarget::Channel { id: s.to_owned() })
|
Ok(UrlTarget::Channel {
|
||||||
} else if util::PLAYLIST_ID_REGEX.is_match(s) {
|
id: string.to_owned(),
|
||||||
if resolve_albums && s.starts_with(util::PLAYLIST_ID_ALBUM_PREFIX) {
|
})
|
||||||
|
} else if util::PLAYLIST_ID_REGEX.is_match(string) {
|
||||||
|
if resolve_albums && string.starts_with(util::PLAYLIST_ID_ALBUM_PREFIX) {
|
||||||
self._navigation_resolve_url(
|
self._navigation_resolve_url(
|
||||||
&format!("/playlist?list={s}"),
|
&format!("/playlist?list={string}"),
|
||||||
ClientType::DesktopMusic,
|
ClientType::DesktopMusic,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
Ok(UrlTarget::Playlist { id: s.to_owned() })
|
Ok(UrlTarget::Playlist {
|
||||||
|
id: string.to_owned(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else if util::ALBUM_ID_REGEX.is_match(s) {
|
} else if util::ALBUM_ID_REGEX.is_match(string) {
|
||||||
Ok(UrlTarget::Album { id: s.to_owned() })
|
Ok(UrlTarget::Album {
|
||||||
|
id: string.to_owned(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// Channel name only
|
// Channel name only
|
||||||
else if util::VANITY_PATH_REGEX.is_match(s) {
|
else if util::VANITY_PATH_REGEX.is_match(string) {
|
||||||
self._navigation_resolve_url(
|
self._navigation_resolve_url(
|
||||||
&format!("/{}", s.trim_start_matches('/')),
|
&format!("/{}", string.trim_start_matches('/')),
|
||||||
ClientType::Desktop,
|
ClientType::Desktop,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use super::{
|
use super::{
|
||||||
AlbumItem, ArtistId, ArtistItem, Channel, ChannelId, ChannelItem, ChannelTag, MusicArtist,
|
AlbumItem, ArtistItem, Channel, ChannelId, ChannelItem, ChannelTag, MusicItem,
|
||||||
MusicItem, MusicPlaylistItem, PlaylistItem, PlaylistVideo, TrackItem, VideoId, VideoItem,
|
MusicPlaylistItem, PlaylistItem, TrackItem, VideoItem, YouTubeItem,
|
||||||
YouTubeItem,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Trait for casting generic YouTube/YouTube music items to a specific kind.
|
/// Trait for casting generic YouTube/YouTube music items to a specific kind.
|
||||||
|
@ -126,53 +125,3 @@ impl<T> From<Channel<T>> for ChannelId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MusicArtist> for ChannelId {
|
|
||||||
fn from(artist: MusicArtist) -> Self {
|
|
||||||
Self {
|
|
||||||
id: artist.id,
|
|
||||||
name: artist.name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<ArtistId> for ChannelId {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn try_from(artist: ArtistId) -> Result<Self, Self::Error> {
|
|
||||||
match artist.id {
|
|
||||||
Some(id) => Ok(Self {
|
|
||||||
id,
|
|
||||||
name: artist.name,
|
|
||||||
}),
|
|
||||||
None => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VideoItem> for VideoId {
|
|
||||||
fn from(video: VideoItem) -> Self {
|
|
||||||
Self {
|
|
||||||
id: video.id,
|
|
||||||
name: video.name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<PlaylistVideo> for VideoId {
|
|
||||||
fn from(video: PlaylistVideo) -> Self {
|
|
||||||
Self {
|
|
||||||
id: video.id,
|
|
||||||
name: video.name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TrackItem> for VideoId {
|
|
||||||
fn from(track: TrackItem) -> Self {
|
|
||||||
Self {
|
|
||||||
id: track.id,
|
|
||||||
name: track.name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -893,16 +893,6 @@ pub struct PlaylistItem {
|
||||||
pub video_count: Option<u64>,
|
pub video_count: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// YouTube video identifier
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
||||||
#[non_exhaustive]
|
|
||||||
pub struct VideoId {
|
|
||||||
/// Video ID
|
|
||||||
pub id: String,
|
|
||||||
/// Video title
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#MUSIC
|
#MUSIC
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue