diff --git a/lofty/src/ebml/element_reader.rs b/lofty/src/ebml/element_reader.rs index 95e249e8..066cff22 100644 --- a/lofty/src/ebml/element_reader.rs +++ b/lofty/src/ebml/element_reader.rs @@ -8,6 +8,7 @@ use std::ops::{Deref, DerefMut}; use byteorder::{BigEndian, ReadBytesExt}; use lofty_attr::ebml_master_elements; +#[derive(Copy, Clone, Eq, PartialEq, Debug)] pub struct ElementHeader { pub(crate) id: VInt, pub(crate) size: VInt, @@ -25,7 +26,7 @@ impl ElementHeader { } } -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum ElementDataType { SignedInt, UnsignedInt, @@ -37,13 +38,13 @@ pub enum ElementDataType { Binary, } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] struct MasterElement { id: ElementIdent, children: &'static [(VInt, ChildElementDescriptor)], } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub(crate) struct ChildElementDescriptor { pub(crate) ident: ElementIdent, pub(crate) data_type: ElementDataType, @@ -124,6 +125,23 @@ ebml_master_elements! { ], }, + // segment.tags + Tags: { + id: 0x1254_C367, + children: [ + Tag: { 0x7373, Master }, + ], + }, + + // segment.tags.tag + Tag: { + id: 0x7373, + children: [ + Targets: { 0x63C0, Master }, + SimpleTag: { 0x67C8, Master }, + ], + }, + // segment.attachments Attachments: { id: 0x1941_A469, diff --git a/lofty/src/ebml/read.rs b/lofty/src/ebml/read.rs index 30b8bacb..341cf38b 100644 --- a/lofty/src/ebml/read.rs +++ b/lofty/src/ebml/read.rs @@ -1,5 +1,9 @@ mod segment; +mod segment_attachments; +mod segment_chapters; +mod segment_cluster; mod segment_info; +mod segment_tags; mod segment_tracks; use super::EbmlFile; diff --git a/lofty/src/ebml/read/segment.rs b/lofty/src/ebml/read/segment.rs index 6947c9c2..1ee7020f 100644 --- a/lofty/src/ebml/read/segment.rs +++ b/lofty/src/ebml/read/segment.rs @@ -1,4 +1,7 @@ -use super::{segment_info, segment_tracks}; +use super::{ + segment_attachments, segment_chapters, segment_cluster, segment_info, segment_tags, + segment_tracks, +}; use crate::config::ParseOptions; use crate::ebml::element_reader::{ElementIdent, ElementReader, ElementReaderYield}; use crate::ebml::properties::EbmlProperties; @@ -22,16 +25,36 @@ where while let Some(child) = children_reader.next()? { match child { ElementReaderYield::Master((id, size)) => match id { - ElementIdent::Info => { + ElementIdent::Info if parse_options.read_properties => { segment_info::read_from(children_reader.inner(), parse_options, properties)? }, - ElementIdent::Cluster => todo!("Support segment.Cluster"), - ElementIdent::Tracks => { + ElementIdent::Cluster if parse_options.read_properties => { + segment_cluster::read_from(children_reader.inner(), parse_options, properties)? + }, + ElementIdent::Tracks if parse_options.read_properties => { segment_tracks::read_from(children_reader.inner(), parse_options, properties)? }, - ElementIdent::Tags => todo!("Support segment.Tags"), - ElementIdent::Attachments => todo!("Support segment.Attachments"), - ElementIdent::Chapters => todo!("Support segment.Chapters"), + ElementIdent::Tags | ElementIdent::Attachments | ElementIdent::Chapters => { + let mut tag = tags.unwrap_or_default(); + + if id == ElementIdent::Tags { + segment_tags::read_from(children_reader.inner(), parse_options, &mut tag)? + } else if id == ElementIdent::Attachments { + segment_attachments::read_from( + children_reader.inner(), + parse_options, + &mut tag, + )? + } else { + segment_chapters::read_from( + children_reader.inner(), + parse_options, + &mut tag, + )? + } + + tags = Some(tag); + }, _ => { // We do not end up using information from all of the segment // elements, so we can just skip any useless ones. diff --git a/lofty/src/ebml/read/segment_attachments.rs b/lofty/src/ebml/read/segment_attachments.rs new file mode 100644 index 00000000..8b8c2c06 --- /dev/null +++ b/lofty/src/ebml/read/segment_attachments.rs @@ -0,0 +1,17 @@ +use crate::config::ParseOptions; +use crate::ebml::element_reader::ElementReader; +use crate::ebml::EbmlTag; +use crate::error::Result; + +use std::io::{Read, Seek}; + +pub(super) fn read_from( + _element_reader: &mut ElementReader, + _parse_options: ParseOptions, + _tag: &mut EbmlTag, +) -> Result<()> +where + R: Read + Seek, +{ + unimplemented!("\\Ebml\\Segment\\Attachments") +} diff --git a/lofty/src/ebml/read/segment_chapters.rs b/lofty/src/ebml/read/segment_chapters.rs new file mode 100644 index 00000000..da4b3ba3 --- /dev/null +++ b/lofty/src/ebml/read/segment_chapters.rs @@ -0,0 +1,17 @@ +use crate::config::ParseOptions; +use crate::ebml::element_reader::ElementReader; +use crate::ebml::EbmlTag; +use crate::error::Result; + +use std::io::{Read, Seek}; + +pub(super) fn read_from( + _element_reader: &mut ElementReader, + _parse_options: ParseOptions, + _tag: &mut EbmlTag, +) -> Result<()> +where + R: Read + Seek, +{ + unimplemented!("\\Ebml\\Segment\\Chapters") +} diff --git a/lofty/src/ebml/read/segment_cluster.rs b/lofty/src/ebml/read/segment_cluster.rs new file mode 100644 index 00000000..aaad83ae --- /dev/null +++ b/lofty/src/ebml/read/segment_cluster.rs @@ -0,0 +1,17 @@ +use crate::config::ParseOptions; +use crate::ebml::element_reader::ElementReader; +use crate::ebml::properties::EbmlProperties; +use crate::error::Result; + +use std::io::{Read, Seek}; + +pub(super) fn read_from( + _element_reader: &mut ElementReader, + _parse_options: ParseOptions, + _properties: &mut EbmlProperties, +) -> Result<()> +where + R: Read + Seek, +{ + unimplemented!("\\Ebml\\Segment\\Cluster") +} diff --git a/lofty/src/ebml/read/segment_tags.rs b/lofty/src/ebml/read/segment_tags.rs new file mode 100644 index 00000000..9bff8f47 --- /dev/null +++ b/lofty/src/ebml/read/segment_tags.rs @@ -0,0 +1,17 @@ +use crate::config::ParseOptions; +use crate::ebml::element_reader::ElementReader; +use crate::ebml::EbmlTag; +use crate::error::Result; + +use std::io::{Read, Seek}; + +pub(super) fn read_from( + _element_reader: &mut ElementReader, + _parse_options: ParseOptions, + _tag: &mut EbmlTag, +) -> Result<()> +where + R: Read + Seek, +{ + unimplemented!("\\Ebml\\Segment\\Tags") +}