Skip to content

Commit 6370529

Browse files
committed
MP4: Move AdvisoryRating to a new module
1 parent 0be82f7 commit 6370529

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

lofty/src/mp4/ilst/advisory_rating.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/// The parental advisory rating
2+
///
3+
/// See also:
4+
/// * <https://docs.mp3tag.de/mapping/#itunesadvisory>
5+
/// * <https://exiftool.org/TagNames/QuickTime.html>
6+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7+
pub enum AdvisoryRating {
8+
/// *Inoffensive*/*None* (0)
9+
Inoffensive,
10+
/// *Explicit* (1 or 4)
11+
///
12+
/// In the past Apple used the value `4` for explicit content
13+
/// that has later been replaced by `1`. Both values are considered
14+
/// as valid when reading but only the newer value `1` is written.
15+
Explicit,
16+
/// *Clean*/*Edited* (2)
17+
Clean,
18+
}
19+
20+
impl AdvisoryRating {
21+
/// Returns the rating as it appears in the `rtng` atom
22+
///
23+
/// # Examples
24+
///
25+
/// ```rust
26+
/// use lofty::mp4::AdvisoryRating;
27+
///
28+
/// assert_eq!(AdvisoryRating::Inoffensive.as_u8(), 0);
29+
/// assert_eq!(AdvisoryRating::Explicit.as_u8(), 1);
30+
/// assert_eq!(AdvisoryRating::Clean.as_u8(), 2);
31+
/// ```
32+
pub fn as_u8(&self) -> u8 {
33+
match self {
34+
AdvisoryRating::Inoffensive => 0,
35+
AdvisoryRating::Explicit => 1,
36+
AdvisoryRating::Clean => 2,
37+
}
38+
}
39+
}
40+
41+
impl TryFrom<u8> for AdvisoryRating {
42+
type Error = u8;
43+
44+
fn try_from(input: u8) -> Result<Self, Self::Error> {
45+
match input {
46+
0 => Ok(Self::Inoffensive),
47+
1 | 4 => Ok(Self::Explicit),
48+
2 => Ok(Self::Clean),
49+
value => Err(value),
50+
}
51+
}
52+
}

lofty/src/mp4/ilst/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub(super) mod advisory_rating;
12
pub(super) mod atom;
23
pub(super) mod constants;
34
pub(super) mod read;
@@ -16,6 +17,7 @@ use crate::tag::{
1617
use crate::util::flag_item;
1718
use crate::util::io::{FileLike, Length, Truncate};
1819
use atom::{AdvisoryRating, Atom, AtomData};
20+
use advisory_rating::AdvisoryRating;
1921

2022
use std::borrow::Cow;
2123
use std::io::Write;

lofty/src/mp4/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod constants {
2424
pub use crate::mp4::properties::{AudioObjectType, Mp4Codec, Mp4Properties};
2525
pub use atom_info::AtomIdent;
2626
pub use ilst::atom::{AdvisoryRating, Atom, AtomData};
27+
pub use ilst::advisory_rating::AdvisoryRating;
2728
pub use ilst::Ilst;
2829

2930
pub(crate) use properties::SAMPLE_RATES;

0 commit comments

Comments
 (0)