ybd_core/model/
download.rs1use std::{path::Path, sync::Arc};
6
7use crate::model::quality::{AudioQuality, VideoEncode, VideoQuality};
8
9pub struct DownloadOption<'a> {
19 pub audio_path: Option<&'a Path>,
20 pub video_path: Option<&'a Path>,
21 pub output: Option<&'a Path>,
22 pub video_quality: Option<VideoQuality>,
23 pub video_encode: Option<VideoEncode>,
24 pub audio_quality: Option<AudioQuality>,
25 pub ffmpeg_path: Option<&'a Path>,
26 pub on_video_progress: Option<ProgressCallback>,
27 pub on_audio_progress: Option<ProgressCallback>,
28}
29
30impl<'a> DownloadOption<'a> {
31 pub fn builder() -> DownloadOptionBuilder<'a> {
32 DownloadOptionBuilder::new()
33 }
34}
35
36pub type ProgressCallback = Arc<dyn Fn(u64, Option<u64>) + Send + Sync>;
37
38pub struct DownloadOptionBuilder<'a> {
39 audio_path: Option<&'a Path>,
40 video_path: Option<&'a Path>,
41 output: Option<&'a Path>,
42 video_quality: Option<VideoQuality>,
43 video_encode: Option<VideoEncode>,
44 audio_quality: Option<AudioQuality>,
45 ffmpeg_path: Option<&'a Path>,
46 on_video_progress: Option<ProgressCallback>,
47 on_audio_progress: Option<ProgressCallback>,
48}
49
50impl<'a> DownloadOptionBuilder<'a> {
51 pub fn new() -> Self {
52 Self {
53 audio_path: None,
54 video_path: None,
55 output: None,
56 video_quality: None,
57 video_encode: None,
58 audio_quality: None,
59 ffmpeg_path: None,
60 on_video_progress: None,
61 on_audio_progress: None,
62 }
63 }
64 pub fn audio_path(
65 mut self,
66 audio_path: &'a Path,
67 ) -> Self {
68 self.audio_path = Some(audio_path);
69 self
70 }
71 pub fn video_path(
72 mut self,
73 video_path: &'a Path,
74 ) -> Self {
75 self.video_path = Some(video_path);
76 self
77 }
78 pub fn output(
79 mut self,
80 output: &'a Path,
81 ) -> Self {
82 self.output = Some(output);
83 self
84 }
85 pub fn video_quality(
86 mut self,
87 video_quality: VideoQuality,
88 ) -> Self {
89 self.video_quality = Some(video_quality);
90 self
91 }
92 pub fn video_encode(
93 mut self,
94 video_encode: VideoEncode,
95 ) -> Self {
96 self.video_encode = Some(video_encode);
97 self
98 }
99 pub fn audio_quality(
100 mut self,
101 audio_quality: AudioQuality,
102 ) -> Self {
103 self.audio_quality = Some(audio_quality);
104 self
105 }
106 pub fn ffmpeg_path(
107 mut self,
108 ffmpeg_path: &'a Path,
109 ) -> Self {
110 self.ffmpeg_path = Some(ffmpeg_path);
111 self
112 }
113 pub fn on_video_progress(
114 mut self,
115 on_progress: ProgressCallback,
116 ) -> Self {
117 self.on_video_progress = Some(on_progress);
118 self
119 }
120 pub fn on_audio_progress(
121 mut self,
122 on_progress: ProgressCallback,
123 ) -> Self {
124 self.on_audio_progress = Some(on_progress);
125 self
126 }
127 pub fn build(self) -> DownloadOption<'a> {
128 DownloadOption {
129 audio_path: self.audio_path,
130 video_path: self.video_path,
131 output: self.output,
132 video_quality: self.video_quality,
133 video_encode: self.video_encode,
134 audio_quality: self.audio_quality,
135 ffmpeg_path: self.ffmpeg_path,
136 on_video_progress: self.on_video_progress,
137 on_audio_progress: self.on_audio_progress,
138 }
139 }
140}
141
142impl<'a> Default for DownloadOptionBuilder<'a> {
143 fn default() -> Self {
144 Self::new()
145 }
146}