Preserve vendor string on VorbisFile/OpusFile -> TaggedFile conversion

This commit is contained in:
Serial 2021-08-28 20:34:12 -04:00
parent 575d7af692
commit fa97d27eb1
3 changed files with 30 additions and 9 deletions

View file

@ -48,12 +48,11 @@ pub(crate) fn parse_id3v2(bytes: &mut &[u8]) -> Result<Tag> {
&& flags & 0x20 == 0x20, && flags & 0x20 == 0x20,
footer: (version == Id3v2Version::V4 || version == Id3v2Version::V3) footer: (version == Id3v2Version::V4 || version == Id3v2Version::V3)
&& flags & 0x10 == 0x10, && flags & 0x10 == 0x10,
crc: false, // Retrieved later if applicable crc: false, // Retrieved later if applicable
#[cfg(feature = "id3v2_restrictions")] #[cfg(feature = "id3v2_restrictions")]
restrictions: (false, TagRestrictions::default()), // Retrieved later if applicable restrictions: (false, TagRestrictions::default()), // Retrieved later if applicable
}; };
#[cfg(feature = "id3v2_restrictions")]
if flags_parsed.extended_header { if flags_parsed.extended_header {
let extended_size = decode_u32(bytes.read_u32::<BigEndian>()?); let extended_size = decode_u32(bytes.read_u32::<BigEndian>()?);
@ -78,6 +77,7 @@ pub(crate) fn parse_id3v2(bytes: &mut &[u8]) -> Result<Tag> {
bytes.read_exact(&mut crc)?; bytes.read_exact(&mut crc)?;
} }
#[cfg(feature = "id3v2_restrictions")]
if extended_flags & 0x10 == 0x10 { if extended_flags & 0x10 == 0x10 {
flags_parsed.restrictions.0 = true; flags_parsed.restrictions.0 = true;
flags_parsed.restrictions.1 = parse_restrictions(bytes)?; flags_parsed.restrictions.1 = parse_restrictions(bytes)?;

View file

@ -1,7 +1,5 @@
use crate::types::file::AudioFile; use crate::types::file::AudioFile;
use crate::{ use crate::{FileProperties, ItemKey, ItemValue, LoftyError, Result, Tag, TagItem, TagType};
FileProperties, ItemKey, ItemValue, LoftyError, Result, Tag, TagItem, TagType
};
use std::io::{Read, Seek, SeekFrom}; use std::io::{Read, Seek, SeekFrom};
use std::time::Duration; use std::time::Duration;

View file

@ -1,6 +1,9 @@
use crate::logic::id3::v2::Id3v2Version; use super::item::ItemKey;
use crate::{FileProperties, LoftyError, Result, Tag, TagType}; use super::properties::FileProperties;
use super::tag::{ItemValue, Tag, TagItem, TagType};
use crate::error::{LoftyError, Result};
use crate::logic::ape::ApeFile; use crate::logic::ape::ApeFile;
use crate::logic::id3::v2::Id3v2Version;
use crate::logic::iff::aiff::AiffFile; use crate::logic::iff::aiff::AiffFile;
use crate::logic::iff::wav::WavFile; use crate::logic::iff::wav::WavFile;
use crate::logic::mp4::Mp4File; use crate::logic::mp4::Mp4File;
@ -124,20 +127,40 @@ impl From<AiffFile> for TaggedFile {
impl From<OpusFile> for TaggedFile { impl From<OpusFile> for TaggedFile {
fn from(input: OpusFile) -> Self { fn from(input: OpusFile) -> Self {
// Preserve vendor string
let mut tag = input.vorbis_comments;
if !input.vendor.is_empty() {
tag.insert_item_unchecked(TagItem::new(
ItemKey::EncoderSoftware,
ItemValue::Text(input.vendor),
))
}
Self { Self {
ty: FileType::Opus, ty: FileType::Opus,
properties: input.properties, properties: input.properties,
tags: vec![input.vorbis_comments], tags: vec![tag],
} }
} }
} }
impl From<VorbisFile> for TaggedFile { impl From<VorbisFile> for TaggedFile {
fn from(input: VorbisFile) -> Self { fn from(input: VorbisFile) -> Self {
// Preserve vendor string
let mut tag = input.vorbis_comments;
if !input.vendor.is_empty() {
tag.insert_item_unchecked(TagItem::new(
ItemKey::EncoderSoftware,
ItemValue::Text(input.vendor),
))
}
Self { Self {
ty: FileType::Vorbis, ty: FileType::Vorbis,
properties: input.properties, properties: input.properties,
tags: vec![input.vorbis_comments], tags: vec![tag],
} }
} }
} }