aboutsummaryrefslogtreecommitdiff
path: root/common/src/impl.rs
blob: 55364ab3ddfd23567ec2d2e96df68da69e891b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use crate::{SourceTrack, SourceTrackKind};

impl SourceTrackKind {
    pub fn letter(&self) -> char {
        match self {
            SourceTrackKind::Video { .. } => 'v',
            SourceTrackKind::Audio { .. } => 'a',
            SourceTrackKind::Subtitles => 's',
        }
    }
}

impl std::fmt::Display for SourceTrack {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let kspec = match &self.kind {
            SourceTrackKind::Video { width, height, fps } => {
                format!("Video: {width}x{height} {fps}fps ")
            }
            SourceTrackKind::Audio {
                channels,
                sample_rate,
                bit_depth,
            } => format!("Audio: {channels}ch {sample_rate}Hz {bit_depth}bits "),
            SourceTrackKind::Subtitles => "Subtitles: ".to_string(),
        };
        f.write_fmt(format_args!(
            "{} {:?} {} ({})",
            kspec, self.name, self.language, self.codec
        ))
    }
}