Skip to main content

DownloadOption

Struct DownloadOption 

Source
pub struct DownloadOption<'a> {
    pub audio_path: Option<&'a Path>,
    pub video_path: Option<&'a Path>,
    pub output: Option<&'a Path>,
    pub video_quality: Option<VideoQuality>,
    pub video_encode: Option<VideoEncode>,
    pub audio_quality: Option<AudioQuality>,
    pub ffmpeg_path: Option<&'a Path>,
    pub on_video_progress: Option<ProgressCallback>,
    pub on_audio_progress: Option<ProgressCallback>,
}
Expand description

用于构造可选的下载参数

  • audio_path: 输出的音频文件路径
  • video_path: 输出视频(无音频)文件路径
  • output: 指定最后合并视频音频后输出的视频的路径,其他下载方法(单独下视频和音频)不生效
  • video_quality: 视频质量
  • video_encode: 视频编码格式
  • audio_quality: 音频质量
  • ffmpeg_path: ffmpeg路径,不设置时从系统变量获取

Fields§

§audio_path: Option<&'a Path>§video_path: Option<&'a Path>§output: Option<&'a Path>§video_quality: Option<VideoQuality>§video_encode: Option<VideoEncode>§audio_quality: Option<AudioQuality>§ffmpeg_path: Option<&'a Path>§on_video_progress: Option<ProgressCallback>§on_audio_progress: Option<ProgressCallback>

Implementations§

Source§

impl<'a> DownloadOption<'a>

Source

pub fn builder() -> DownloadOptionBuilder<'a>

Examples found in repository?
examples/download_audio.rs (line 18)
11async fn main() -> Result<(), Box<dyn Error>> {
12        let account = login::get_account().await?;
13        let biliclient = BiliClient::new(&account)?;
14        let bvid = "BV1JvPMedE5E";
15
16        let resp = PlayUrlResponse::new(&biliclient, bvid).await?;
17        fs::create_dir_all("output").await?;
18        let option = DownloadOption::builder()
19                .audio_path(Path::new("output/audio_example.m4a"))
20                .build();
21        actuator::download_audio(&biliclient, &resp, &option).await?;
22        println!("The res is outputed to output/audio_example.m4a");
23        Ok(())
24}
More examples
Hide additional examples
examples/download_video_with_no_audio.rs (line 17)
10async fn main() -> Result<(), Box<dyn Error>> {
11        let account = login::get_account().await?;
12        let biliclient = BiliClient::new(&account)?;
13        let bvid = "BV1JvPMedE5E";
14
15        let resp = PlayUrlResponse::new(&biliclient, bvid).await?;
16        fs::create_dir_all("output").await?;
17        let option = DownloadOption::builder()
18                // potplayer低于v1.7.21759,尝试GPU解码av1编码格式时会有黑屏问题,这里用avc编码
19                .video_encode(VideoEncode::AVC)
20                .video_path(Path::new("output/video_example.mp4"))
21                .build();
22        actuator::download_video_with_no_audio(&biliclient, &resp, &option).await?;
23        println!("The res is outputed to output/audio_example.mp4");
24        Ok(())
25}
examples/download_video.rs (line 17)
10async fn main() -> Result<(), Box<dyn Error>> {
11        let account = login::get_account().await?;
12        let biliclient = BiliClient::new(&account)?;
13        let bvid = "BV1JvPMedE5E";
14
15        let resp = PlayUrlResponse::new(&biliclient, bvid).await?;
16        fs::create_dir_all("output").await?;
17        let option = DownloadOption::builder()
18                // potplayer低于v1.7.21759,尝试GPU解码av1编码格式时会有黑屏问题,这里用avc编码
19                .video_encode(VideoEncode::AVC)
20                .audio_path(Path::new("output/audio_example.m4a"))
21                .video_path(Path::new("output/video_example.mp4"))
22                .output(Path::new("output/video_sample.mp4"))
23                .build();
24        actuator::download_video(&biliclient, &resp, &option).await?;
25        println!("The video is outputed to output/video_sample.mp4");
26        Ok(())
27}
examples/download_audio_with_metadata.rs (line 36)
20async fn main() -> Result<(), Box<dyn Error>> {
21        let account = login::get_account().await?;
22        let biliclient = BiliClient::new(&account)?;
23        let bvid = "BV1JvPMedE5E";
24
25        // 1. 拉取视频详细信息(标题、UP 主、简介、发布时间、分P)
26        let detail = actuator::get_video_detail(bvid, Some(&biliclient)).await?;
27        println!("标题: {}", detail.title);
28        println!("UP 主: {}", detail.owner.name);
29        println!("分区: {}", detail.tname);
30
31        fs::create_dir_all("output").await?;
32        let audio_path = Path::new("output/audio_with_metadata.m4a");
33
34        // 2. 下载音频
35        let resp = PlayUrlResponse::new(&biliclient, bvid).await?;
36        let option = DownloadOption::builder().audio_path(audio_path).build();
37        actuator::download_audio(&biliclient, &resp, &option).await?;
38
39        // 3. 先看一下将要写入的元数据
40        let meta = detail.media_meta(Some("我的收藏夹"), Some(detail.cid));
41        println!("{:#?}", meta);
42
43        // 4. 写入元数据 + 封面(已写入则自动跳过)
44        actuator::embed_metadata(
45                &biliclient,
46                audio_path,
47                &detail,
48                Some("我的收藏夹"),
49                Some(detail.cid),
50        )
51        .await?;
52
53        // 5. 验证结果
54        let tag = mp4ameta::Tag::read_from_path(audio_path)?;
55        println!("----------------------------------------");
56        println!("title:       {:?}", tag.title());
57        println!("artist:      {:?}", tag.artist());
58        println!("album:       {:?}", tag.album());
59        println!("genre:       {:?}", tag.genre());
60        println!("year:        {:?}", tag.year());
61        println!("track:       {:?}", tag.track());
62        println!("comment:     {:?}", tag.comment());
63        println!("description: {:?}", tag.description());
64        println!("keywords:    {:?}", tag.keywords().collect::<Vec<_>>());
65        println!("encoder:     {:?}", tag.encoder());
66        println!("cover:       {:?}", util::check_cover_box(audio_path)?);
67
68        Ok(())
69}

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DownloadOption<'a>

§

impl<'a> !UnwindSafe for DownloadOption<'a>

§

impl<'a> Freeze for DownloadOption<'a>

§

impl<'a> Send for DownloadOption<'a>

§

impl<'a> Sync for DownloadOption<'a>

§

impl<'a> Unpin for DownloadOption<'a>

§

impl<'a> UnsafeUnpin for DownloadOption<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more