1use crate::*;
2use alux_ext::ext;
3use rsynko_download::*;
4use rsynko_media::*;
5use std::fmt::Display;
6use std::path::PathBuf;
7use thiserror::Error;
8
9#[ext(name = YoutubeApplicationExt)]
11pub impl<This, Request, RequestError, ResponseError, ChallengeError, FetchError, PublishError, Event, Progress> This
12where
13 This: YoutubeSorts<Request = Request>
14 + YoutubeRequestAlg
15 + YoutubeClientAlg
16 + YoutubeProgramAlg
17 + YoutubeRequestBytesAlg<Error = RequestError>
18 + YoutubeResponseAlg<Error = ResponseError>
19 + YoutubeChallengeAlg<Error = ChallengeError>
20 + YoutubeSolutionAlg
21 + YoutubeUrlAlg
22 + MetadataAlg
23 + FormatAlg
24 + ExtractionAlg
25 + ExtractionViewAlg
26 + MediaViewAlg
27 + FormatViewAlg
28 + FormatSelectionApplyAlg
29 + FormatSourceAlg<Request>
30 + FetchStreamAlg<Request, Error = FetchError>
31 + AtomicPublishAlg<Error = PublishError>
32 + DownloadObservationAlg<Event = Event, Progress = Progress>
33 + DownloadProgressAlg<Progress = Progress>
34 + DownloadReportAlg<Event = Event>,
35 FetchError: Display,
36 PublishError: Display,
37{
38 fn download_youtube(
44 &self,
45 url: &str,
46 selection: &This::Selection,
47 target: &OutputTarget,
48 ) -> Result<PathBuf, YoutubeApplicationError<RequestError, ResponseError, ChallengeError, FetchError, PublishError>>
49 {
50 let extraction = self.extract_youtube(url).map_err(YoutubeApplicationError::Extraction)?;
51 self.download_extraction(extraction, selection, target).map_err(YoutubeApplicationError::Media)
52 }
53}
54
55#[derive(Debug, Error)]
57pub enum YoutubeApplicationError<RequestError, ResponseError, ChallengeError, FetchError, PublishError> {
58 #[error("{0}")]
60 Extraction(YoutubeError<RequestError, ResponseError, ChallengeError>),
61 #[error("{0}")]
63 Media(MediaDownloadError<FetchError, PublishError>),
64}