Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/mp4/ilst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TITLE: AtomIdent<'_> = AtomIdent::Fourcc(*b"\xa9nam");
const ALBUM: AtomIdent<'_> = AtomIdent::Fourcc(*b"\xa9alb");
const GENRE: AtomIdent<'_> = AtomIdent::Fourcc(*b"\xa9gen");
const COMMENT: AtomIdent<'_> = AtomIdent::Fourcc(*b"\xa9cmt");
const ADVISORY_RATING: AtomIdent<'_> = AtomIdent::Fourcc(*b"rtng");

macro_rules! impl_accessor {
($($name:ident => $const:ident;)+) => {
Expand Down Expand Up @@ -156,7 +157,7 @@ impl Ilst {

/// Returns the parental advisory rating according to the `rtng` atom
pub fn advisory_rating(&self) -> Option<AdvisoryRating> {
if let Some(atom) = self.atom(&AtomIdent::Fourcc(*b"rtng")) {
if let Some(atom) = self.atom(&ADVISORY_RATING) {
let rating = match atom.data().next() {
Some(AtomData::SignedInteger(si)) => *si as u8,
Some(AtomData::Unknown { data: c, .. }) if !c.is_empty() => c[0],
Expand All @@ -174,7 +175,7 @@ impl Ilst {
let byte = advisory_rating.as_u8();

self.replace_atom(Atom {
ident: AtomIdent::Fourcc(*b"rtng"),
ident: ADVISORY_RATING,
data: AtomDataStorage::Single(AtomData::SignedInteger(i32::from(byte))),
})
}
Expand Down Expand Up @@ -373,6 +374,10 @@ impl From<Ilst> for Tag {
tag.pictures.push(pic);
continue;
},
AtomData::Bool(b) => {
let text = if b { "1".to_owned() } else { "0".to_owned() };
ItemValue::Text(text)
},
// We have to special case track/disc numbers since they are stored together
AtomData::Unknown { code: 0, data } if data.len() >= 6 => {
if let AtomIdent::Fourcc(ref fourcc) = ident {
Expand Down Expand Up @@ -465,6 +470,22 @@ impl From<Tag> for Ilst {
ItemKey::TrackTotal => convert_to_uint(&mut tracks.1, data.as_str()),
ItemKey::DiscNumber => convert_to_uint(&mut discs.0, data.as_str()),
ItemKey::DiscTotal => convert_to_uint(&mut discs.1, data.as_str()),
ItemKey::FlagCompilation => {
if let Ok(num) = data.as_str().parse::<u8>() {
let data = match num {
0 => false,
1 => true,
_ => {
// Ignore all other, unexpected values
continue;
},
};
ilst.atoms.push(Atom {
ident: ident.into_owned(),
data: AtomDataStorage::Single(AtomData::Bool(data)),
})
}
},
_ => ilst.atoms.push(Atom {
ident: ident.into_owned(),
data: AtomDataStorage::Single(AtomData::UTF8(data)),
Expand Down