use std::fmt;
use std::time::Duration;
use crate::{AudioInfo, ChannelConfig, SampleRate, Tag, util};
impl Tag {
pub fn audio_info(&self) -> &AudioInfo {
&self.info
}
pub fn duration(&self) -> Duration {
self.info.duration
}
pub(crate) fn format_duration(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "duration: ")?;
util::format_duration(f, self.duration())?;
writeln!(f)
}
pub fn channel_config(&self) -> Option<ChannelConfig> {
self.info.channel_config
}
pub(crate) fn format_channel_config(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.channel_config() {
Some(c) => writeln!(f, "channel config: {c}"),
None => Ok(()),
}
}
pub fn sample_rate(&self) -> Option<SampleRate> {
self.info.sample_rate
}
pub(crate) fn format_sample_rate(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.sample_rate() {
Some(r) => writeln!(f, "sample rate: {r}"),
None => Ok(()),
}
}
pub fn avg_bitrate(&self) -> Option<u32> {
self.info.avg_bitrate
}
pub(crate) fn format_avg_bitrate(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.avg_bitrate() {
Some(c) => writeln!(f, "average bitrate: {}kbps", c / 1024),
None => Ok(()),
}
}
pub fn max_bitrate(&self) -> Option<u32> {
self.info.max_bitrate
}
pub(crate) fn format_max_bitrate(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.max_bitrate() {
Some(c) => writeln!(f, "maximum bitrate: {}kbps", c / 1024),
None => Ok(()),
}
}
}
impl Tag {
pub fn filetype(&self) -> &str {
self.ftyp.as_str()
}
}