99 lines
2.0 KiB
Rust
99 lines
2.0 KiB
Rust
use serde::Deserialize;
|
|
use std::io;
|
|
use std::process::ExitStatus;
|
|
use std::string::FromUtf8Error;
|
|
use tokio::task::JoinError;
|
|
use url::Url;
|
|
extern crate quick_xml;
|
|
extern crate reqwest;
|
|
extern crate serde_json;
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct InvidiousVideo {
|
|
pub video_id: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct VideoURL {
|
|
pub url: Url,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct VideoData {
|
|
#[serde(default)]
|
|
pub requested_formats: Vec<VideoURL>,
|
|
#[serde(default)]
|
|
pub url: Option<Url>,
|
|
pub duration: u64,
|
|
pub id: String,
|
|
pub title: String,
|
|
#[serde(default)]
|
|
pub thumbnail: Option<Url>,
|
|
#[serde(default)]
|
|
pub is_live: Option<bool>,
|
|
#[serde(skip)]
|
|
pub json: String,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct YoutubeDLError {
|
|
pub status: ExitStatus,
|
|
pub output: String,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
IO(io::Error),
|
|
JoinError(JoinError),
|
|
Reqwest(reqwest::Error),
|
|
QuickXML(quick_xml::Error),
|
|
SerdeJSON(serde_json::Error),
|
|
FromUtf8Error(FromUtf8Error),
|
|
YoutubeDL(YoutubeDLError),
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
#[inline]
|
|
fn from(error: io::Error) -> Error {
|
|
Error::IO(error)
|
|
}
|
|
}
|
|
|
|
impl From<JoinError> for Error {
|
|
#[inline]
|
|
fn from(error: JoinError) -> Error {
|
|
Error::JoinError(error)
|
|
}
|
|
}
|
|
|
|
impl From<reqwest::Error> for Error {
|
|
#[inline]
|
|
fn from(error: reqwest::Error) -> Error {
|
|
Error::Reqwest(error)
|
|
}
|
|
}
|
|
|
|
impl From<quick_xml::Error> for Error {
|
|
#[inline]
|
|
fn from(error: quick_xml::Error) -> Error {
|
|
Error::QuickXML(error)
|
|
}
|
|
}
|
|
|
|
impl From<serde_json::Error> for Error {
|
|
#[inline]
|
|
fn from(error: serde_json::Error) -> Error {
|
|
Error::SerdeJSON(error)
|
|
}
|
|
}
|
|
|
|
impl From<FromUtf8Error> for Error {
|
|
#[inline]
|
|
fn from(error: FromUtf8Error) -> Error {
|
|
Error::FromUtf8Error(error)
|
|
}
|
|
}
|