1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
//! Error produced by YouTube and this library
/// Errors produced by this Library
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// A Error that can occur when requesting web content
#[error("An Error occurred while requesting web content: {0}")]
Request(#[from] reqwest::Error),
/// A Error reported by YouTube
#[error(transparent)]
Youtube(#[from] Youtube),
}
/// A Error reported by YouTube.
///
/// This Error is `#[non_exhaustive]` because YouTube can add errors at any
/// moment and breaking major version every time is annoying.
#[derive(Debug, thiserror::Error, PartialEq, Eq, Clone)]
#[non_exhaustive]
pub enum Youtube {
/// A entity was not found. This can be:
///
/// - [`Videos`](crate::Video)
/// - [`Playlists`](crate::Playlist)
/// - [`Channels`](crate::Channel)
/// - [`Streams`](crate::Stream)
#[error("a entity was not found")]
NotFound,
/// A entity is private. This can be:
///
/// - [`Videos`](crate::Video)
/// - [`Playlists`](crate::Playlist)
/// - [`Channels`](crate::Channel)
/// - [`Streams`](crate::Stream)
#[error("a entity is private")]
Private,
/// A Video is not available due to Community Guideline violations.
#[error("a video is not available due to community guideline violations")]
CommunityGuidelineViolation,
/// A Video is not available in your country.
#[error("a video is not available in your country")]
GeoRestricted,
/// A [`Stream`](crate::Stream) is only available after a purchase.
#[error("a purchase is required to watch get this stream")]
PurchaseRequired,
/// A [`Playlist`](crate::Playlist) could not be viewed. Reasons being:
///
/// - The playlist is a "Mix" or "My Mix" playlist
#[error("a playlist could not be viewed")]
Unviewable,
/// A [`Video`](crate::Video) is age-restricted and its
/// [`Streams`](crate::Stream) could not be fetched.
#[error("a video is age-restricted")]
AgeRestricted,
/// A [`Video`](crate::Video) is not available due to nudity or sexual content violations.
#[error("a video is not available due to nudity or sexual content violations")]
NudityOrSexualContentViolation,
/// The channel or the channel associated with a video was terminated.
#[error("the channel or the channel associated with a video was terminated")]
AccountTerminated,
/// A [`Video`](crate::Video) was removed by the uploader.
#[error("a video was removed by the uploader")]
RemovedByUploader,
/// A [`Video`](crate::Video) is not available due to violations of YouTube's Terms of Service.
#[error("a video is not available due to violations of YouTube's Terms of Service")]
TermsOfServiceViolation,
/// A [`Video`](crate::Video) is not available due to a copyright claim by the `claiment`
#[error("a video is not available due to a copyright claim by '{claiment}'")]
CopyrightClaim {
/// The person that made this copyright claim
claiment: String,
},
}
/// The Error produced when a invalid Id is found
#[derive(thiserror::Error, Debug, Clone)]
pub enum Id<const N: usize> {
/// A invalid Id was found.
///
/// A Id is only valid when all characters are on of:
///
/// - `0..=9`
/// - `a..=z`
/// - `A..=Z`
/// - `_`
/// - `-`
#[error("Found invalid id: '{0}'")]
InvalidId(String),
/// A Id was not the expected length
#[error("Expected a id of length {N} but found a id of length {0}")]
InvalidLength(usize),
}