fix: stream ordering, downloader progress bar
This commit is contained in:
parent
6e2ba71f33
commit
a706eb172e
6 changed files with 43 additions and 45 deletions
|
|
@ -4,30 +4,26 @@ use crate::model::AudioCodec;
|
|||
|
||||
use super::{AudioStream, VideoStream};
|
||||
|
||||
impl PartialOrd for VideoStream {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(
|
||||
match (self.width * self.height).cmp(&(other.width * other.height)) {
|
||||
pub trait QualityOrd {
|
||||
fn quality_cmp(&self, other: &Self) -> Ordering;
|
||||
}
|
||||
|
||||
impl QualityOrd for VideoStream {
|
||||
fn quality_cmp(&self, other: &Self) -> Ordering {
|
||||
match (self.width * self.height).cmp(&(other.width * other.height)) {
|
||||
Ordering::Less => Ordering::Less,
|
||||
Ordering::Greater => Ordering::Greater,
|
||||
Ordering::Equal => match self.codec.cmp(&other.codec) {
|
||||
Ordering::Less => Ordering::Less,
|
||||
Ordering::Greater => Ordering::Greater,
|
||||
Ordering::Equal => match self.codec.cmp(&other.codec) {
|
||||
Ordering::Less => Ordering::Less,
|
||||
Ordering::Greater => Ordering::Greater,
|
||||
Ordering::Equal => self.average_bitrate.cmp(&other.average_bitrate),
|
||||
},
|
||||
Ordering::Equal => self.average_bitrate.cmp(&other.average_bitrate),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for VideoStream {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for AudioStream {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
impl QualityOrd for AudioStream {
|
||||
fn quality_cmp(&self, other: &Self) -> Ordering {
|
||||
fn cmp_bitrate(s: &AudioStream) -> u32 {
|
||||
match s.codec {
|
||||
// Opus is more efficient
|
||||
|
|
@ -36,12 +32,6 @@ impl PartialOrd for AudioStream {
|
|||
}
|
||||
}
|
||||
|
||||
Some(cmp_bitrate(self).cmp(&cmp_bitrate(other)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for AudioStream {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
cmp_bitrate(self).cmp(&cmp_bitrate(other))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue