Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/id3/v2/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ use crate::id3::v2::items::popularimeter::Popularimeter;
use std::convert::{TryFrom, TryInto};
use std::hash::{Hash, Hasher};

// <https://mutagen-specs.readthedocs.io/en/latest/id3/id3v2.4.0-structure.html>
//
// > The three byte language field, present in several frames, is used to describe
// > the language of the frame’s content, according to ISO-639-2 [ISO-639-2].
// > The language should be represented in lower case. If the language is not known
// > the string “XXX” should be used.
pub(super) const UNKNOWN_LANGUAGE: [u8; 3] = *b"XXX";

// TODO: Messy module, rough conversions

/// Represents an `ID3v2` frame
Expand Down Expand Up @@ -270,20 +278,19 @@ impl From<TagItem> for Option<Frame<'static>> {
let value;
match input.key().try_into().map(FrameID::into_owned) {
Ok(id) => {
// We make the VERY bold assumption the language is English
value = match (&id, input.item_value) {
(FrameID::Valid(ref s), ItemValue::Text(text)) if s == "COMM" => {
FrameValue::Comment(LanguageFrame {
encoding: TextEncoding::UTF8,
language: *b"eng",
language: UNKNOWN_LANGUAGE,
description: String::new(),
content: text,
})
},
(FrameID::Valid(ref s), ItemValue::Text(text)) if s == "USLT" => {
FrameValue::UnSyncText(LanguageFrame {
encoding: TextEncoding::UTF8,
language: *b"eng",
language: UNKNOWN_LANGUAGE,
description: String::new(),
content: text,
})
Expand Down Expand Up @@ -383,13 +390,13 @@ impl<'a> TryFrom<&'a TagItem> for FrameRef<'a> {
value: Cow::Owned(match (id, tag_item.value()) {
("COMM", ItemValue::Text(text)) => FrameValue::Comment(LanguageFrame {
encoding: TextEncoding::UTF8,
language: *b"eng",
language: UNKNOWN_LANGUAGE,
description: String::new(),
content: text.clone(),
}),
("USLT", ItemValue::Text(text)) => FrameValue::UnSyncText(LanguageFrame {
encoding: TextEncoding::UTF8,
language: *b"eng",
language: UNKNOWN_LANGUAGE,
description: String::new(),
content: text.clone(),
}),
Expand Down
6 changes: 3 additions & 3 deletions src/id3/v2/tag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::flags::ID3v2TagFlags;
use super::frame::id::FrameID;
use super::frame::{Frame, FrameFlags, FrameValue};
use super::frame::{Frame, FrameFlags, FrameValue, UNKNOWN_LANGUAGE};
use super::ID3v2Version;
use crate::error::{LoftyError, Result};
use crate::id3::v2::frame::FrameRef;
Expand Down Expand Up @@ -62,7 +62,7 @@ macro_rules! impl_accessor {
///
/// * [`ItemKey::Comment`](crate::ItemKey::Comment) and [`ItemKey::Lyrics`](crate::ItemKey::Lyrics) - Unlike a normal text frame, these require a [`LanguageFrame`].
/// An attempt is made to create this information, but it may be incorrect.
/// * `language` - Assumed to be "eng"
/// * `language` - Unknown and set to "XXX"
/// * `description` - Left empty, which is invalid if there are more than one of these frames. These frames can only be identified
/// by their descriptions, and as such they are expected to be unique for each.
/// * [`ItemKey::Unknown("WXXX" | "TXXX")`](crate::ItemKey::Unknown) - These frames are also identified by their descriptions.
Expand Down Expand Up @@ -422,7 +422,7 @@ impl Accessor for ID3v2Tag {
id: FrameID::Valid(Cow::Borrowed("COMM")),
value: FrameValue::Comment(LanguageFrame {
encoding: TextEncoding::UTF8,
language: *b"eng",
language: UNKNOWN_LANGUAGE,
description: String::new(),
content: value,
}),
Expand Down