Skip to content

Commit 2a9d0fd

Browse files
committed
EBML: Stub implement EbmlFile and EbmlTag
1 parent 7fd0c3d commit 2a9d0fd

File tree

9 files changed

+163
-9
lines changed

9 files changed

+163
-9
lines changed

lofty_attr/src/internal.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use quote::quote;
99
pub(crate) fn opt_internal_file_type(
1010
struct_name: String,
1111
) -> Option<(proc_macro2::TokenStream, bool)> {
12-
const LOFTY_FILE_TYPES: [&str; 12] = [
13-
"Aac", "Aiff", "Ape", "Flac", "Mpeg", "Mp4", "Mpc", "Opus", "Vorbis", "Speex", "Wav",
14-
"WavPack",
12+
const LOFTY_FILE_TYPES: [&str; 13] = [
13+
"Aac", "Aiff", "Ape", "Ebml", "Flac", "Mpeg", "Mp4", "Mpc", "Opus", "Vorbis", "Speex",
14+
"Wav", "WavPack",
1515
];
1616

1717
const ID3V2_STRIPPABLE: [&str; 2] = ["Flac", "Ape"];

src/ebml/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! EBML specific items
2+
mod properties;
3+
mod read;
4+
mod tag;
5+
6+
use lofty_attr::LoftyFile;
7+
8+
// Exports
9+
10+
pub use properties::EbmlProperties;
11+
pub use tag::EbmlTag;
12+
13+
/// An EBML file
14+
#[derive(LoftyFile, Default)]
15+
#[lofty(read_fn = "read::read_from")]
16+
pub struct EbmlFile {
17+
/// An ID3v2 tag
18+
#[lofty(tag_type = "Id3v2")]
19+
pub(crate) ebml_tag: Option<EbmlTag>,
20+
/// The file's audio properties
21+
pub(crate) properties: EbmlProperties,
22+
}

src/ebml/properties.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::properties::FileProperties;
2+
3+
/// EBML audio properties
4+
#[derive(Debug, Clone, PartialEq, Default)]
5+
pub struct EbmlProperties {}
6+
7+
impl From<EbmlProperties> for FileProperties {
8+
fn from(input: EbmlProperties) -> Self {
9+
todo!()
10+
}
11+
}

src/ebml/read.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::EbmlFile;
2+
use crate::error::Result;
3+
use crate::probe::ParseOptions;
4+
5+
use std::io::{Read, Seek};
6+
7+
pub(super) fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<EbmlFile>
8+
where
9+
R: Read + Seek,
10+
{
11+
todo!()
12+
}

src/ebml/tag/mod.rs

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
use crate::error::LoftyError;
2+
use crate::tag::Tag;
3+
use crate::traits::{Accessor, MergeTag, SplitTag, TagExt};
4+
5+
use std::fs::File;
6+
use std::io::Write;
7+
use std::ops::Deref;
8+
use std::path::Path;
9+
10+
use lofty_attr::tag;
11+
12+
/// TODO
13+
#[derive(Default, Debug, PartialEq, Eq, Clone)]
14+
#[tag(description = "An `EBML` tag", supported_formats(Ebml))]
15+
pub struct EbmlTag {}
16+
17+
impl Accessor for EbmlTag {}
18+
19+
impl TagExt for EbmlTag {
20+
type Err = LoftyError;
21+
type RefKey<'a> = &'a str;
22+
23+
fn len(&self) -> usize {
24+
todo!()
25+
}
26+
27+
fn contains<'a>(&'a self, key: Self::RefKey<'a>) -> bool {
28+
todo!()
29+
}
30+
31+
fn is_empty(&self) -> bool {
32+
todo!()
33+
}
34+
35+
fn save_to(&self, file: &mut File) -> std::result::Result<(), Self::Err> {
36+
todo!()
37+
}
38+
39+
fn dump_to<W: Write>(&self, writer: &mut W) -> std::result::Result<(), Self::Err> {
40+
todo!()
41+
}
42+
43+
fn remove_from_path<P: AsRef<Path>>(&self, path: P) -> std::result::Result<(), Self::Err> {
44+
todo!()
45+
}
46+
47+
fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> {
48+
todo!()
49+
}
50+
51+
fn clear(&mut self) {
52+
todo!()
53+
}
54+
}
55+
56+
#[derive(Debug, Clone, Default)]
57+
pub struct SplitTagRemainder(EbmlTag);
58+
59+
impl From<SplitTagRemainder> for EbmlTag {
60+
fn from(from: SplitTagRemainder) -> Self {
61+
from.0
62+
}
63+
}
64+
65+
impl Deref for SplitTagRemainder {
66+
type Target = EbmlTag;
67+
68+
fn deref(&self) -> &Self::Target {
69+
&self.0
70+
}
71+
}
72+
73+
impl SplitTag for EbmlTag {
74+
type Remainder = SplitTagRemainder;
75+
76+
fn split_tag(mut self) -> (Self::Remainder, Tag) {
77+
todo!()
78+
}
79+
}
80+
81+
impl MergeTag for SplitTagRemainder {
82+
type Merged = EbmlTag;
83+
84+
fn merge_tag(self, tag: Tag) -> Self::Merged {
85+
todo!()
86+
}
87+
}
88+
89+
impl From<EbmlTag> for Tag {
90+
fn from(input: EbmlTag) -> Self {
91+
input.split_tag().1
92+
}
93+
}
94+
95+
impl From<Tag> for EbmlTag {
96+
fn from(input: Tag) -> Self {
97+
SplitTagRemainder::default().merge_tag(input)
98+
}
99+
}

src/file.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ pub enum FileType {
717717
Aac,
718718
Aiff,
719719
Ape,
720+
Ebml,
720721
Flac,
721722
Mpeg,
722723
Mp4,
@@ -755,6 +756,7 @@ impl FileType {
755756
match self {
756757
FileType::Aiff | FileType::Mpeg | FileType::Wav | FileType::Aac => TagType::Id3v2,
757758
FileType::Ape | FileType::Mpc | FileType::WavPack => TagType::Ape,
759+
FileType::Ebml => TagType::Ebml,
758760
FileType::Flac | FileType::Opus | FileType::Vorbis | FileType::Speex => {
759761
TagType::VorbisComments
760762
},
@@ -791,13 +793,14 @@ impl FileType {
791793
}
792794

793795
match tag_type {
796+
TagType::AiffText => crate::iff::aiff::AIFFTextChunks::SUPPORTED_FORMATS.contains(self),
794797
TagType::Ape => crate::ape::ApeTag::SUPPORTED_FORMATS.contains(self),
798+
TagType::Ebml => crate::ebml::EbmlTag::SUPPORTED_FORMATS.contains(self),
795799
TagType::Id3v1 => crate::id3::v1::Id3v1Tag::SUPPORTED_FORMATS.contains(self),
796800
TagType::Id3v2 => crate::id3::v2::Id3v2Tag::SUPPORTED_FORMATS.contains(self),
797801
TagType::Mp4Ilst => crate::mp4::Ilst::SUPPORTED_FORMATS.contains(self),
798-
TagType::VorbisComments => crate::ogg::VorbisComments::SUPPORTED_FORMATS.contains(self),
799802
TagType::RiffInfo => crate::iff::wav::RIFFInfoList::SUPPORTED_FORMATS.contains(self),
800-
TagType::AiffText => crate::iff::aiff::AIFFTextChunks::SUPPORTED_FORMATS.contains(self),
803+
TagType::VorbisComments => crate::ogg::VorbisComments::SUPPORTED_FORMATS.contains(self),
801804
}
802805
}
803806

@@ -827,6 +830,7 @@ impl FileType {
827830
"opus" => Some(Self::Opus),
828831
"flac" => Some(Self::Flac),
829832
"ogg" => Some(Self::Vorbis),
833+
"mka" | "mkv" | "webm" => Some(Self::Ebml),
830834
"mp4" | "m4a" | "m4b" | "m4p" | "m4r" | "m4v" | "3gp" => Some(Self::Mp4),
831835
"mpc" | "mp+" | "mpp" => Some(Self::Mpc),
832836
"spx" => Some(Self::Speex),
@@ -1002,6 +1006,7 @@ impl FileType {
10021006
None
10031007
},
10041008
119 if buf.len() >= 4 && &buf[..4] == b"wvpk" => Some(Self::WavPack),
1009+
26 if buf.starts_with(&[0x1A, 0x45, 0xDF, 0xA3]) => Some(Self::Ebml),
10051010
_ if buf.len() >= 8 && &buf[4..8] == b"ftyp" => Some(Self::Mp4),
10061011
_ if buf.starts_with(b"MPCK") || buf.starts_with(b"MP+") => Some(Self::Mpc),
10071012
_ => None,

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub(crate) mod _this_is_internal {}
147147

148148
pub mod aac;
149149
pub mod ape;
150+
pub mod ebml;
150151
pub mod error;
151152
pub(crate) mod file;
152153
pub mod flac;

src/probe.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::ogg::vorbis::VorbisFile;
1616
use crate::resolve::CUSTOM_RESOLVERS;
1717
use crate::wavpack::WavPackFile;
1818

19+
use crate::ebml::EbmlFile;
1920
use std::fs::File;
2021
use std::io::{BufReader, Cursor, Read, Seek, SeekFrom};
2122
use std::path::Path;
@@ -554,6 +555,7 @@ impl<R: Read + Seek> Probe<R> {
554555
FileType::Aac => AacFile::read_from(reader, options)?.into(),
555556
FileType::Aiff => AiffFile::read_from(reader, options)?.into(),
556557
FileType::Ape => ApeFile::read_from(reader, options)?.into(),
558+
FileType::Ebml => EbmlFile::read_from(reader, options)?.into(),
557559
FileType::Flac => FlacFile::read_from(reader, options)?.into(),
558560
FileType::Mpeg => MpegFile::read_from(reader, options)?.into(),
559561
FileType::Opus => OpusFile::read_from(reader, options)?.into(),

src/tag/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -609,20 +609,22 @@ impl MergeTag for SplitTagRemainder {
609609
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
610610
#[non_exhaustive]
611611
pub enum TagType {
612+
/// Represents AIFF text chunks
613+
AiffText,
612614
/// This covers both APEv1 and APEv2 as it doesn't matter much
613615
Ape,
616+
/// Represents an EBML tag element
617+
Ebml,
614618
/// Represents an ID3v1 tag
615619
Id3v1,
616620
/// This covers all ID3v2 versions since they all get upgraded to ID3v2.4
617621
Id3v2,
618622
/// Represents an MP4 ilst atom
619623
Mp4Ilst,
620-
/// Represents vorbis comments
621-
VorbisComments,
622624
/// Represents a RIFF INFO LIST
623625
RiffInfo,
624-
/// Represents AIFF text chunks
625-
AiffText,
626+
/// Represents vorbis comments
627+
VorbisComments,
626628
}
627629

628630
impl TagType {

0 commit comments

Comments
 (0)