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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
mod block;
mod properties;
mod read;
#[cfg(feature = "vorbis_comments")]
pub(crate) mod write;
#[cfg(feature = "vorbis_comments")]
use super::tag::VorbisComments;
use crate::error::Result;
use crate::types::file::{AudioFile, FileType, TaggedFile};
use crate::types::properties::FileProperties;
use crate::types::tag::TagType;
use std::io::{Read, Seek};
pub struct FlacFile {
#[cfg(feature = "vorbis_comments")]
pub(crate) vorbis_comments: Option<VorbisComments>,
pub(crate) properties: FileProperties,
}
impl From<FlacFile> for TaggedFile {
fn from(input: FlacFile) -> Self {
Self {
ty: FileType::FLAC,
properties: input.properties,
#[cfg(feature = "vorbis_comments")]
tags: input
.vorbis_comments
.map_or_else(Vec::new, |t| vec![t.into()]),
#[cfg(not(feature = "vorbis_comments"))]
tags: Vec::new(),
}
}
}
impl AudioFile for FlacFile {
type Properties = FileProperties;
fn read_from<R>(reader: &mut R, read_properties: bool) -> Result<Self>
where
R: Read + Seek,
{
read::read_from(reader, read_properties)
}
fn properties(&self) -> &Self::Properties {
&self.properties
}
fn contains_tag(&self) -> bool {
#[cfg(feature = "vorbis_comments")]
return self.vorbis_comments.is_some();
#[cfg(not(feature = "vorbis_comments"))]
return false;
}
#[allow(unused_variables)]
fn contains_tag_type(&self, tag_type: TagType) -> bool {
#[cfg(feature = "vorbis_comments")]
return tag_type == TagType::VorbisComments && self.vorbis_comments.is_some();
#[cfg(not(feature = "vorbis_comments"))]
return false;
}
}
impl FlacFile {
crate::macros::tag_methods! {
#[cfg(feature = "vorbis_comments")]
vorbis_comments, VorbisComments
}
}