diff --git a/Cargo.toml b/Cargo.toml index 3a8a1b7..6e2c49c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ quick-js = { path = "../quickjs-rs" } once_cell = "1.12.0" fancy-regex = "0.10.0" anyhow = "1.0" -thiserror = "1.0.31" url = "2.2.2" log = "0.4.17" reqwest = {version = "0.11.11", default-features = false, features = ["json", "gzip", "brotli", "stream"]} diff --git a/notes/video_ids.txt b/notes/video_ids.txt index 36bd655..363c455 100644 --- a/notes/video_ids.txt +++ b/notes/video_ids.txt @@ -18,7 +18,7 @@ DRM: 1bfOsni7EgI Album with unknown artists: https://music.youtube.com/playlist?list=OLAK5uy_mEX9ljZeeEWgTM1xLL1isyiGaWXoPyoOk -Throttling issue: Y8JFxS1HlDo +Comment by artist: 3pv_rHKnwAs # Playlists 962 Songs: PL4lEESSgxM_5O81EvKCmBIm_JT5Q7JeaI diff --git a/src/client/playlist.rs b/src/client/playlist.rs index 152e041..d01c83a 100644 --- a/src/client/playlist.rs +++ b/src/client/playlist.rs @@ -259,21 +259,22 @@ fn map_playlist_items( } impl Paginator { - pub async fn next(&self, query: RustyPipeQuery) -> Result { - match &self.ctoken { - Some(ctoken) => Ok(query.get_playlist_continuation(ctoken).await?), - None => Err(crate::error::Error::PaginatorExhausted), - } + pub async fn next(&self, query: RustyPipeQuery) -> Result> { + Ok(match &self.ctoken { + Some(ctoken) => Some(query.get_playlist_continuation(ctoken).await?), + None => None, + }) } - pub async fn extend(&mut self, query: RustyPipeQuery) -> Result<(), crate::error::Error> { + pub async fn extend(&mut self, query: RustyPipeQuery) -> Result { match self.next(query).await { - Ok(paginator) => { + Ok(Some(paginator)) => { let mut items = paginator.items; self.items.append(&mut items); self.ctoken = paginator.ctoken; - Ok(()) + Ok(true) } + Ok(None) => Ok(false), Err(e) => Err(e), } } @@ -281,11 +282,11 @@ impl Paginator { pub async fn extend_pages(&mut self, query: RustyPipeQuery, n_pages: usize) -> Result<()> { for _ in 0..n_pages { match self.extend(query.clone()).await { - Err(crate::error::Error::PaginatorExhausted) => { + Ok(false) => { break; } Err(e) => { - return Err(e.into()); + return Err(e); } _ => {} } @@ -296,11 +297,11 @@ impl Paginator { pub async fn extend_limit(&mut self, query: RustyPipeQuery, n_items: usize) -> Result<()> { while self.items.len() < n_items { match self.extend(query.clone()).await { - Err(crate::error::Error::PaginatorExhausted) => { + Ok(false) => { break; } Err(e) => { - return Err(e.into()); + return Err(e); } _ => {} } diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 98a75ae..0000000 --- a/src/error.rs +++ /dev/null @@ -1,50 +0,0 @@ -/// Errors that can occur during the id extraction or the video download process. -#[derive(thiserror::Error, Debug)] -pub enum Error { - /* - #[error("the provided raw Id does not match any known Id-pattern")] - BadIdFormat, - #[cfg(feature = "fetch")] - #[error("the video you requested is unavailable:\n{0:#?}")] - VideoUnavailable(Box), - #[cfg(feature = "download")] - #[error("the video contains no streams")] - NoStreams, - - #[error(transparent)] - #[cfg(feature = "fetch")] - IO(#[from] std::io::Error), - #[error(transparent)] - #[cfg(feature = "fetch")] - Request(#[from] reqwest::Error), - #[error("YouTube returned an unexpected response: `{0}`")] - UnexpectedResponse(String), - #[error(transparent)] - #[cfg(feature = "fetch")] - QueryDeserialization(#[from] serde_qs::Error), - #[error(transparent)] - #[cfg(feature = "fetch")] - JsonDeserialization(#[from] serde_json::Error), - #[error(transparent)] - UrlParseError(#[from] url::ParseError), - - #[error("{0}")] - Custom(String), - #[error("a potentially dangerous error occurred: {0}")] - Fatal(String), - #[error( - "the error, which occurred is not meant an error, but is used for internal comunication.\ - This error should never be propagated to the public API." - )] - Internal(&'static str), - #[error("The internal channel has been closed")] - #[cfg(feature = "callback")] - ChannelClosed, - */ - #[error("paginator is exhausted")] - PaginatorExhausted, - - // TODO: Remove anyhow - #[error(transparent)] - Anyhow(#[from] anyhow::Error), -} diff --git a/src/lib.rs b/src/lib.rs index aec1241..e4cd2a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,6 @@ mod util; pub mod cache; pub mod client; pub mod download; -pub mod error; pub mod model; pub mod report; pub mod timeago;