From f4542bbfca8b7cb427b2528480c418bde8d37c89 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:01:35 -0400 Subject: [PATCH] EBML: Rename `TagType::Ebml` -> `TagType::Matroska` --- lofty/src/ebml/mod.rs | 4 +- lofty/src/ebml/read/segment.rs | 4 +- lofty/src/ebml/read/segment_attachments.rs | 4 +- lofty/src/ebml/read/segment_chapters.rs | 4 +- lofty/src/ebml/read/segment_tags.rs | 4 +- lofty/src/ebml/tag/generic.rs | 6 +-- lofty/src/ebml/tag/mod.rs | 52 +++++++++++----------- lofty/src/file/file_type.rs | 5 ++- lofty/src/tag/companion_tag.rs | 9 ++++ lofty/src/tag/item.rs | 2 +- lofty/src/tag/split_merge_tag.rs | 4 +- lofty/src/tag/tag_ext.rs | 4 +- lofty/src/tag/tag_type.rs | 4 +- lofty/src/tag/utils.rs | 4 ++ lofty/tests/files/matroska.rs | 9 ++-- lofty_attr/src/internal.rs | 2 +- 16 files changed, 69 insertions(+), 52 deletions(-) diff --git a/lofty/src/ebml/mod.rs b/lofty/src/ebml/mod.rs index 148b58b1..ce5a179f 100644 --- a/lofty/src/ebml/mod.rs +++ b/lofty/src/ebml/mod.rs @@ -19,8 +19,8 @@ pub use vint::*; #[lofty(internal_write_module_do_not_use_anywhere_else)] pub struct EbmlFile { /// An EBML tag - #[lofty(tag_type = "Ebml")] - pub(crate) ebml_tag: Option, + #[lofty(tag_type = "Matroska")] + pub(crate) ebml_tag: Option, /// The file's audio properties pub(crate) properties: EbmlProperties, } diff --git a/lofty/src/ebml/read/segment.rs b/lofty/src/ebml/read/segment.rs index d111617b..1709ccb1 100644 --- a/lofty/src/ebml/read/segment.rs +++ b/lofty/src/ebml/read/segment.rs @@ -2,7 +2,7 @@ use super::{segment_attachments, segment_info, segment_tags, segment_tracks}; use crate::config::ParseOptions; use crate::ebml::element_reader::{ElementHeader, ElementIdent, ElementReader, ElementReaderYield}; use crate::ebml::properties::EbmlProperties; -use crate::ebml::tag::EbmlTag; +use crate::ebml::tag::MatroskaTag; use crate::ebml::ElementId; use crate::error::Result; @@ -12,7 +12,7 @@ pub(super) fn read_from( element_reader: &mut ElementReader, parse_options: ParseOptions, properties: &mut EbmlProperties, -) -> Result> +) -> Result> where R: Read + Seek, { diff --git a/lofty/src/ebml/read/segment_attachments.rs b/lofty/src/ebml/read/segment_attachments.rs index 81f25454..4db7a286 100644 --- a/lofty/src/ebml/read/segment_attachments.rs +++ b/lofty/src/ebml/read/segment_attachments.rs @@ -2,7 +2,7 @@ use crate::config::ParseOptions; use crate::ebml::element_reader::{ ElementChildIterator, ElementIdent, ElementReader, ElementReaderYield, }; -use crate::ebml::{AttachedFile, EbmlTag}; +use crate::ebml::{AttachedFile, MatroskaTag}; use crate::error::Result; use crate::macros::decode_err; use crate::picture::MimeType; @@ -13,7 +13,7 @@ use std::io::{Read, Seek}; pub(super) fn read_from( children_reader: &mut ElementChildIterator<'_, R>, _parse_options: ParseOptions, - tag: &mut EbmlTag, + tag: &mut MatroskaTag, ) -> Result<()> where R: Read + Seek, diff --git a/lofty/src/ebml/read/segment_chapters.rs b/lofty/src/ebml/read/segment_chapters.rs index 965b3ce2..b75cb511 100644 --- a/lofty/src/ebml/read/segment_chapters.rs +++ b/lofty/src/ebml/read/segment_chapters.rs @@ -1,6 +1,6 @@ use crate::config::ParseOptions; use crate::ebml::element_reader::ElementChildIterator; -use crate::ebml::EbmlTag; +use crate::ebml::MatroskaTag; use crate::error::Result; use std::io::{Read, Seek}; @@ -9,7 +9,7 @@ use std::io::{Read, Seek}; pub(super) fn read_from( _children_reader: &mut ElementChildIterator<'_, R>, _parse_options: ParseOptions, - _tag: &mut EbmlTag, + _tag: &mut MatroskaTag, ) -> Result<()> where R: Read + Seek, diff --git a/lofty/src/ebml/read/segment_tags.rs b/lofty/src/ebml/read/segment_tags.rs index c3d837f8..6e361570 100644 --- a/lofty/src/ebml/read/segment_tags.rs +++ b/lofty/src/ebml/read/segment_tags.rs @@ -1,6 +1,6 @@ use crate::config::ParseOptions; use crate::ebml::element_reader::{ElementChildIterator, ElementIdent, ElementReaderYield}; -use crate::ebml::{EbmlTag, Language, SimpleTag, Tag, TagValue, Target, TargetType}; +use crate::ebml::{Language, MatroskaTag, SimpleTag, Tag, TagValue, Target, TargetType}; use crate::error::Result; use crate::macros::decode_err; @@ -9,7 +9,7 @@ use std::io::{Read, Seek}; pub(super) fn read_from( children_reader: &mut ElementChildIterator<'_, R>, _parse_options: ParseOptions, - tag: &mut EbmlTag, + tag: &mut MatroskaTag, ) -> Result<()> where R: Read + Seek, diff --git a/lofty/src/ebml/tag/generic.rs b/lofty/src/ebml/tag/generic.rs index 5dec1df5..0ff2e9b2 100644 --- a/lofty/src/ebml/tag/generic.rs +++ b/lofty/src/ebml/tag/generic.rs @@ -2,7 +2,7 @@ //! //! NOTE: We can **ONLY** convert `SimpleTags` that come from a target with **NO** uids -use super::{EbmlTag, Language, SimpleTag, TargetType, TOMBSTONE_SIMPLE_TAG}; +use super::{Language, MatroskaTag, SimpleTag, TargetType, TOMBSTONE_SIMPLE_TAG}; use crate::tag::items::Lang; use crate::tag::{ItemKey, Tag, TagItem, TagType}; @@ -135,8 +135,8 @@ matroska_mapping_tables!( const TAG_RETAINED: bool = true; const TAG_CONSUMED: bool = false; -pub(super) fn split_tag(mut ebml_tag: EbmlTag) -> (EbmlTag, Tag) { - let mut tag = Tag::new(TagType::Ebml); +pub(super) fn split_tag(mut ebml_tag: MatroskaTag) -> (MatroskaTag, Tag) { + let mut tag = Tag::new(TagType::Matroska); // TODO: Pictures, can they be handled in a generic way? // What about the uid and referral? diff --git a/lofty/src/ebml/tag/mod.rs b/lofty/src/ebml/tag/mod.rs index 7bd809ca..bffc4783 100644 --- a/lofty/src/ebml/tag/mod.rs +++ b/lofty/src/ebml/tag/mod.rs @@ -31,7 +31,7 @@ macro_rules! impl_accessor { paste::paste! { $( fn $method(&self) -> Option> { - self.get_str(EbmlTagKey(TargetType::$target, Cow::Borrowed($name))) + self.get_str(MatroskaTagKey(TargetType::$target, Cow::Borrowed($name))) } fn [](&mut self, value: String) { @@ -57,18 +57,18 @@ macro_rules! impl_accessor { /// * [`Target`] /// * [`AttachedFile`] #[derive(Default, Debug, PartialEq, Eq, Clone)] -#[tag(description = "An `EBML` \"tag\"", supported_formats(Ebml))] -pub struct EbmlTag { +#[tag(description = "A Matroska/WebM \"tag\"", supported_formats(Ebml))] +pub struct MatroskaTag { pub(crate) tags: Vec>, pub(crate) attached_files: Vec>, } // TODO #[allow(missing_docs)] -pub struct EbmlTagKey<'a>(TargetType, Cow<'a, str>); +pub struct MatroskaTagKey<'a>(TargetType, Cow<'a, str>); -impl EbmlTag { - fn get(&self, key: EbmlTagKey<'_>) -> Option<&SimpleTag<'_>> { +impl MatroskaTag { + fn get(&self, key: MatroskaTagKey<'_>) -> Option<&SimpleTag<'_>> { fn tag_matches_target(tag: &Tag<'_>, target_type: TargetType) -> bool { let Some(target) = &tag.target else { // An empty target is implicitly `Album` @@ -78,7 +78,7 @@ impl EbmlTag { target.is_candidate_for_type(target_type) } - let EbmlTagKey(target, key) = key; + let MatroskaTagKey(target, key) = key; let applicable_tags = self .tags @@ -98,7 +98,7 @@ impl EbmlTag { None } - fn get_str(&self, key: EbmlTagKey<'_>) -> Option> { + fn get_str(&self, key: MatroskaTagKey<'_>) -> Option> { let simple_tag = self.get(key)?; simple_tag.get_str().map(Cow::from) } @@ -131,11 +131,11 @@ impl EbmlTag { /// # Examples /// /// ```rust,no_run - /// use lofty::ebml::EbmlTag; + /// use lofty::ebml::MatroskaTag; /// use lofty::picture::Picture; /// /// # fn main() -> lofty::error::Result<()> { - /// let mut tag = EbmlTag::default(); + /// let mut tag = MatroskaTag::default(); /// /// let mut picture = std::fs::read("something.png")?; /// let mut picture2 = std::fs::read("something_else.png")?; @@ -153,14 +153,14 @@ impl EbmlTag { /// Inserts a new [`Picture`] /// - /// Note: See [`EbmlTag::insert_attached_file`] + /// Note: See [`MatroskaTag::insert_attached_file`] /// /// ```rust,no_run - /// use lofty::ebml::EbmlTag; + /// use lofty::ebml::MatroskaTag; /// use lofty::picture::Picture; /// /// # fn main() -> lofty::error::Result<()> { - /// let mut tag = EbmlTag::default(); + /// let mut tag = MatroskaTag::default(); /// /// let mut picture_file = std::fs::read("something.png")?; /// tag.insert_picture(Picture::from_reader(&mut &picture_file[..])?); @@ -219,7 +219,7 @@ impl EbmlTag { } } -impl Accessor for EbmlTag { +impl Accessor for MatroskaTag { impl_accessor!( artist => (Track, "ARTIST"), title => (Track, "TITLE"), @@ -267,13 +267,13 @@ impl Accessor for EbmlTag { } } -impl TagExt for EbmlTag { +impl TagExt for MatroskaTag { type Err = LoftyError; - type RefKey<'a> = EbmlTagKey<'a>; + type RefKey<'a> = MatroskaTagKey<'a>; #[inline] fn tag_type(&self) -> TagType { - TagType::Ebml + TagType::Matroska } fn len(&self) -> usize { @@ -281,7 +281,7 @@ impl TagExt for EbmlTag { } fn contains<'a>(&'a self, key: Self::RefKey<'a>) -> bool { - let EbmlTagKey(target_type, key) = key; + let MatroskaTagKey(target_type, key) = key; self.tags.iter().any(|tag| { if let Some(target) = &tag.target { return target.target_type == target_type @@ -338,23 +338,23 @@ impl TagExt for EbmlTag { #[doc(hidden)] #[derive(Debug, Clone, Default)] -pub struct SplitTagRemainder(EbmlTag); +pub struct SplitTagRemainder(MatroskaTag); -impl From for EbmlTag { +impl From for MatroskaTag { fn from(from: SplitTagRemainder) -> Self { from.0 } } impl Deref for SplitTagRemainder { - type Target = EbmlTag; + type Target = MatroskaTag; fn deref(&self) -> &Self::Target { &self.0 } } -impl SplitTag for EbmlTag { +impl SplitTag for MatroskaTag { type Remainder = SplitTagRemainder; fn split_tag(mut self) -> (Self::Remainder, crate::tag::Tag) { @@ -364,20 +364,20 @@ impl SplitTag for EbmlTag { } impl MergeTag for SplitTagRemainder { - type Merged = EbmlTag; + type Merged = MatroskaTag; fn merge_tag(self, _tag: crate::tag::Tag) -> Self::Merged { todo!() } } -impl From for crate::tag::Tag { - fn from(input: EbmlTag) -> Self { +impl From for crate::tag::Tag { + fn from(input: MatroskaTag) -> Self { input.split_tag().1 } } -impl From for EbmlTag { +impl From for MatroskaTag { fn from(input: crate::tag::Tag) -> Self { SplitTagRemainder::default().merge_tag(input) } diff --git a/lofty/src/file/file_type.rs b/lofty/src/file/file_type.rs index 17c5b658..6295c461 100644 --- a/lofty/src/file/file_type.rs +++ b/lofty/src/file/file_type.rs @@ -35,6 +35,7 @@ impl FileType { /// | `Ape` , `Mpc`, `WavPack` | `Ape` | /// | `Flac`, `Opus`, `Vorbis`, `Speex` | `VorbisComments` | /// | `Mp4` | `Mp4Ilst` | + /// | `Ebml` | `Matroska` | /// /// # Panics /// @@ -53,7 +54,7 @@ impl FileType { match self { FileType::Aac | FileType::Aiff | FileType::Mpeg | FileType::Wav => TagType::Id3v2, FileType::Ape | FileType::Mpc | FileType::WavPack => TagType::Ape, - FileType::Ebml => TagType::Ebml, + FileType::Ebml => TagType::Matroska, FileType::Flac | FileType::Opus | FileType::Vorbis | FileType::Speex => { TagType::VorbisComments }, @@ -92,7 +93,7 @@ impl FileType { match tag_type { TagType::Ape => crate::ape::ApeTag::SUPPORTED_FORMATS.contains(self), - TagType::Ebml => crate::ebml::EbmlTag::SUPPORTED_FORMATS.contains(self), + TagType::Matroska => crate::ebml::MatroskaTag::SUPPORTED_FORMATS.contains(self), TagType::Id3v1 => crate::id3::v1::Id3v1Tag::SUPPORTED_FORMATS.contains(self), TagType::Id3v2 => crate::id3::v2::Id3v2Tag::SUPPORTED_FORMATS.contains(self), TagType::Mp4Ilst => crate::mp4::Ilst::SUPPORTED_FORMATS.contains(self), diff --git a/lofty/src/tag/companion_tag.rs b/lofty/src/tag/companion_tag.rs index 6c36bf35..9e37d43d 100644 --- a/lofty/src/tag/companion_tag.rs +++ b/lofty/src/tag/companion_tag.rs @@ -1,3 +1,4 @@ +use crate::ebml::MatroskaTag; use crate::id3::v2::Id3v2Tag; use crate::mp4::Ilst; @@ -5,6 +6,7 @@ use crate::mp4::Ilst; pub(crate) enum CompanionTag { Id3v2(Id3v2Tag), Ilst(Ilst), + Matroska(MatroskaTag), } impl CompanionTag { @@ -21,4 +23,11 @@ impl CompanionTag { _ => None, } } + + pub(crate) fn matroska(self) -> Option { + match self { + CompanionTag::Matroska(tag) => Some(tag), + _ => None, + } + } } diff --git a/lofty/src/tag/item.rs b/lofty/src/tag/item.rs index cdf15ab0..b38aa5aa 100644 --- a/lofty/src/tag/item.rs +++ b/lofty/src/tag/item.rs @@ -902,7 +902,7 @@ impl TagItem { return VALID_ITEMKEYS.contains(&self.item_key); } - if tag_type == TagType::Ebml { + if tag_type == TagType::Matroska { use crate::ebml::tag::SUPPORTED_ITEMKEYS; return SUPPORTED_ITEMKEYS.contains(&self.item_key); diff --git a/lofty/src/tag/split_merge_tag.rs b/lofty/src/tag/split_merge_tag.rs index 18f7c623..4d5e59a7 100644 --- a/lofty/src/tag/split_merge_tag.rs +++ b/lofty/src/tag/split_merge_tag.rs @@ -70,7 +70,7 @@ pub trait MergeTag: private::Sealed { // https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed mod private { use crate::ape::ApeTag; - use crate::ebml::EbmlTag; + use crate::ebml::MatroskaTag; use crate::id3::v1::Id3v1Tag; use crate::id3::v2::Id3v2Tag; use crate::iff::aiff::AiffTextChunks; @@ -86,7 +86,7 @@ mod private { impl Sealed for ApeTag {} impl Sealed for crate::ape::tag::SplitTagRemainder {} - impl Sealed for EbmlTag {} + impl Sealed for MatroskaTag {} impl Sealed for crate::ebml::tag::SplitTagRemainder {} impl Sealed for Id3v1Tag {} diff --git a/lofty/src/tag/tag_ext.rs b/lofty/src/tag/tag_ext.rs index 36d216ab..34f1caca 100644 --- a/lofty/src/tag/tag_ext.rs +++ b/lofty/src/tag/tag_ext.rs @@ -153,7 +153,7 @@ pub trait TagExt: Accessor + Into + Sized + private::Sealed { // https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed mod private { use crate::ape::ApeTag; - use crate::ebml::EbmlTag; + use crate::ebml::MatroskaTag; use crate::id3::v1::Id3v1Tag; use crate::id3::v2::Id3v2Tag; use crate::iff::aiff::AiffTextChunks; @@ -166,7 +166,7 @@ mod private { impl Sealed for AiffTextChunks {} impl Sealed for ApeTag {} - impl Sealed for EbmlTag {} + impl Sealed for MatroskaTag {} impl Sealed for Id3v1Tag {} impl Sealed for Id3v2Tag {} impl Sealed for Ilst {} diff --git a/lofty/src/tag/tag_type.rs b/lofty/src/tag/tag_type.rs index 8d826db1..6abf4b65 100644 --- a/lofty/src/tag/tag_type.rs +++ b/lofty/src/tag/tag_type.rs @@ -15,8 +15,8 @@ use std::path::Path; pub enum TagType { /// This covers both APEv1 and APEv2 as it doesn't matter much Ape, - /// Represents an EBML tag element - Ebml, + /// Represents a `\Segment\Tags` element in Matroska/WebM + Matroska, /// Represents an ID3v1 tag Id3v1, /// This covers all ID3v2 versions since they all get upgraded to ID3v2.4 diff --git a/lofty/src/tag/utils.rs b/lofty/src/tag/utils.rs index a949ba77..a5dbfb6b 100644 --- a/lofty/src/tag/utils.rs +++ b/lofty/src/tag/utils.rs @@ -34,6 +34,7 @@ where FileType::Aac => aac::write::write_to(file, tag, write_options), FileType::Aiff => iff::aiff::write::write_to(file, tag, write_options), FileType::Ape => ape::write::write_to(file, tag, write_options), + FileType::Ebml => todo!("write EBML tags"), FileType::Flac => flac::write::write_to(file, tag, write_options), FileType::Opus | FileType::Speex | FileType::Vorbis => { crate::ogg::write::write_to(file, tag, file_type, write_options) @@ -98,6 +99,9 @@ pub(crate) fn dump_tag( } } .dump_to(writer, write_options), + TagType::Matroska => { + todo!("Dump EBML tags") + }, _ => Ok(()), } } diff --git a/lofty/tests/files/matroska.rs b/lofty/tests/files/matroska.rs index 8b2d4309..0e91f681 100644 --- a/lofty/tests/files/matroska.rs +++ b/lofty/tests/files/matroska.rs @@ -36,7 +36,7 @@ fn write() { assert_eq!(tagged_file.file_type(), FileType::Ebml); // Tags - crate::set_artist!(tagged_file, tag_mut, TagType::Ebml, "Foo artist", 1 => file, "Bar artist"); + crate::set_artist!(tagged_file, tag_mut, TagType::Matroska, "Foo artist", 1 => file, "Bar artist"); // Now reread the file file.rewind().unwrap(); @@ -48,12 +48,15 @@ fn write() { .read() .unwrap(); - crate::set_artist!(tagged_file, tag_mut, TagType::Ebml, "Bar artist", 1 => file, "Foo artist"); + crate::set_artist!(tagged_file, tag_mut, TagType::Matroska, "Bar artist", 1 => file, "Foo artist"); } #[test_log::test] fn remove() { - crate::remove_tag!("tests/files/assets/minimal/full_test.mka", TagType::Ebml); + crate::remove_tag!( + "tests/files/assets/minimal/full_test.mka", + TagType::Matroska + ); } #[test_log::test] diff --git a/lofty_attr/src/internal.rs b/lofty_attr/src/internal.rs index 507af517..123e3dab 100644 --- a/lofty_attr/src/internal.rs +++ b/lofty_attr/src/internal.rs @@ -51,7 +51,7 @@ pub(crate) fn init_write_lookup( .write_to(file, write_options) }); - insert!(map, Ebml, { todo!() }); + insert!(map, Matroska, { todo!("Generated Matroska tag writer") }); insert!(map, Id3v1, { Into::>::into(tag).write_to(file, write_options)