Skip to content

Commit 59e8b6f

Browse files
committed
more impls
1 parent 3aa0b53 commit 59e8b6f

4 files changed

Lines changed: 22 additions & 20 deletions

File tree

vsd/examples/download.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{path::PathBuf, sync::Arc};
77
use vsd::{
88
Downloader, Error, Muxer, Result,
99
playlist::MediaType,
10-
progress::{ProgressCallback, ProgressState},
10+
progress::{ByteSize, Eta, ProgressCallback, ProgressState},
1111
reqwest::Client,
1212
tokio,
1313
tokio_util::sync::CancellationToken,
@@ -18,16 +18,18 @@ struct Progress;
1818
impl ProgressCallback for Progress {
1919
fn on_progress(&self, state: &ProgressState) {
2020
println!(
21-
"{}% ({}/{})",
22-
state.percent, state.downloaded_parts, state.total_parts
21+
"{}% | {}/~{} | {}/{} | {}",
22+
state.percent,
23+
ByteSize(state.downloaded_bytes),
24+
ByteSize(state.estimated_bytes),
25+
state.downloaded_parts,
26+
state.total_parts,
27+
Eta(state.eta_seconds)
2328
);
2429
}
2530

2631
fn on_finish(&self, state: &ProgressState) {
27-
println!(
28-
"{}% ({}/{})",
29-
state.percent, state.downloaded_parts, state.total_parts
30-
);
32+
self.on_progress(state);
3133
}
3234
}
3335

vsd/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ pub use error::{Error, Result};
2121
pub use reqwest;
2222
pub use tokio;
2323
pub use tokio_util;
24-
pub use utils::find_ffmpeg;
24+
pub use utils::{find_ffmpeg, gen_id};
2525
pub use vsd_mp4;

vsd/src/playlist/types.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use serde::Serialize;
1+
use serde::{Deserialize, Serialize};
22
use std::collections::HashSet;
33

4-
#[derive(Debug, Serialize)]
4+
#[derive(Debug, Default, Deserialize, Serialize)]
55
pub struct MasterPlaylist {
66
pub playlist_type: PlaylistType,
77
pub uri: String,
88
pub streams: Vec<MediaPlaylist>,
99
}
1010

11-
#[derive(Default, Debug, Serialize)]
11+
#[derive(Debug, Default, Deserialize, Serialize)]
1212
pub struct MediaPlaylist {
1313
pub bandwidth: Option<u64>,
1414
pub channels: Option<f32>,
@@ -27,7 +27,7 @@ pub struct MediaPlaylist {
2727
pub uri: String,
2828
}
2929

30-
#[derive(Clone, Debug, Default, Serialize)]
30+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
3131
pub struct Segment {
3232
pub duration: f32,
3333
pub key: Option<Key>,
@@ -36,24 +36,24 @@ pub struct Segment {
3636
pub uri: String,
3737
}
3838

39-
#[derive(Clone, Debug, Default, Serialize)]
39+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
4040
pub struct Key {
4141
pub default_kid: Option<String>,
4242
pub iv: Option<String>,
4343
pub method: KeyMethod,
4444
pub uri: Option<String>,
4545
}
4646

47-
#[derive(Clone, Debug, Serialize)]
47+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
4848
pub struct Map {
4949
pub range: Option<Range>,
5050
pub uri: String,
5151
}
5252

53-
#[derive(Clone, Debug, Serialize)]
53+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
5454
pub struct Range(pub u64, pub u64);
5555

56-
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
56+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
5757
pub enum MediaType {
5858
Video,
5959
Audio,
@@ -62,14 +62,14 @@ pub enum MediaType {
6262
Undefined,
6363
}
6464

65-
#[derive(Clone, Debug, Default, Serialize)]
65+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
6666
pub enum PlaylistType {
6767
Dash,
6868
#[default]
6969
Hls,
7070
}
7171

72-
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
72+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
7373
pub enum KeyMethod {
7474
Aes128,
7575
Cenc,
@@ -79,7 +79,7 @@ pub enum KeyMethod {
7979
SampleAes,
8080
}
8181

82-
#[derive(Clone, Debug, Serialize)]
82+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
8383
pub struct StreamMetadata {
8484
pub bandwidth: Option<u64>,
8585
pub channels: Option<f32>,

vsd/src/progress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl std::fmt::Display for ByteSize {
234234
}
235235
}
236236

237-
pub struct Eta(usize);
237+
pub struct Eta(pub usize);
238238

239239
impl std::fmt::Display for Eta {
240240
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

0 commit comments

Comments
 (0)