use std::ops::{Deref, DerefMut};
use reqwest::Client;
use url::Url;
use crate::{IdBuf, Result};
use crate::blocking::descrambler::VideoDescrambler;
use crate::fetcher::VideoFetcher as AsyncVideoFetcher;
#[derive(Clone, Debug, derive_more::Display, PartialEq, Eq)]
pub struct VideoFetcher(AsyncVideoFetcher);
impl VideoFetcher {
#[inline]
pub fn from_url(url: &Url) -> Result<Self> {
Ok(Self(AsyncVideoFetcher::from_url(url)?))
}
#[inline]
pub fn from_id(video_id: IdBuf) -> Result<Self> {
Ok(Self(AsyncVideoFetcher::from_id(video_id)?))
}
#[inline]
pub fn from_id_with_client(video_id: IdBuf, client: Client) -> Self {
Self(AsyncVideoFetcher::from_id_with_client(video_id, client))
}
#[inline]
pub fn fetch(self) -> Result<VideoDescrambler> {
Ok(VideoDescrambler(block!(self.0.fetch())?))
}
}
impl Deref for VideoFetcher {
type Target = AsyncVideoFetcher;
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for VideoFetcher {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}