lofty/ogg/opus/
mod.rs

1pub(super) mod properties;
2
3use super::find_last_page;
4use super::tag::VorbisComments;
5use crate::config::ParseOptions;
6use crate::error::Result;
7use crate::ogg::constants::{OPUSHEAD, OPUSTAGS};
8use properties::OpusProperties;
9
10use std::io::{Read, Seek};
11
12use lofty_attr::LoftyFile;
13
14/// An OGG Opus file
15#[derive(LoftyFile)]
16#[lofty(read_fn = "Self::read_from")]
17pub struct OpusFile {
18	/// The vorbis comments contained in the file
19	///
20	/// NOTE: While a metadata packet is required, it isn't required to actually have any data.
21	#[lofty(tag_type = "VorbisComments")]
22	pub(crate) vorbis_comments_tag: VorbisComments,
23	/// The file's audio properties
24	pub(crate) properties: OpusProperties,
25}
26
27impl OpusFile {
28	fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<Self>
29	where
30		R: Read + Seek,
31	{
32		let file_information =
33			super::read::read_from(reader, OPUSHEAD, OPUSTAGS, 2, parse_options)?;
34
35		Ok(Self {
36			properties: if parse_options.read_properties {
37				properties::read_properties(reader, &file_information.1, &file_information.2)?
38			} else {
39				OpusProperties::default()
40			},
41			// A metadata packet is mandatory in Opus
42			vorbis_comments_tag: file_information.0.unwrap_or_default(),
43		})
44	}
45}