mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-04 18:09:11 +00:00
MP4: Move AdvisoryRating
to a new module
This commit is contained in:
parent
0be82f7264
commit
637052978b
3 changed files with 55 additions and 0 deletions
52
lofty/src/mp4/ilst/advisory_rating.rs
Normal file
52
lofty/src/mp4/ilst/advisory_rating.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/// The parental advisory rating
|
||||
///
|
||||
/// See also:
|
||||
/// * <https://docs.mp3tag.de/mapping/#itunesadvisory>
|
||||
/// * <https://exiftool.org/TagNames/QuickTime.html>
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum AdvisoryRating {
|
||||
/// *Inoffensive*/*None* (0)
|
||||
Inoffensive,
|
||||
/// *Explicit* (1 or 4)
|
||||
///
|
||||
/// In the past Apple used the value `4` for explicit content
|
||||
/// that has later been replaced by `1`. Both values are considered
|
||||
/// as valid when reading but only the newer value `1` is written.
|
||||
Explicit,
|
||||
/// *Clean*/*Edited* (2)
|
||||
Clean,
|
||||
}
|
||||
|
||||
impl AdvisoryRating {
|
||||
/// Returns the rating as it appears in the `rtng` atom
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use lofty::mp4::AdvisoryRating;
|
||||
///
|
||||
/// assert_eq!(AdvisoryRating::Inoffensive.as_u8(), 0);
|
||||
/// assert_eq!(AdvisoryRating::Explicit.as_u8(), 1);
|
||||
/// assert_eq!(AdvisoryRating::Clean.as_u8(), 2);
|
||||
/// ```
|
||||
pub fn as_u8(&self) -> u8 {
|
||||
match self {
|
||||
AdvisoryRating::Inoffensive => 0,
|
||||
AdvisoryRating::Explicit => 1,
|
||||
AdvisoryRating::Clean => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for AdvisoryRating {
|
||||
type Error = u8;
|
||||
|
||||
fn try_from(input: u8) -> Result<Self, Self::Error> {
|
||||
match input {
|
||||
0 => Ok(Self::Inoffensive),
|
||||
1 | 4 => Ok(Self::Explicit),
|
||||
2 => Ok(Self::Clean),
|
||||
value => Err(value),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub(super) mod advisory_rating;
|
||||
pub(super) mod atom;
|
||||
pub(super) mod constants;
|
||||
pub(super) mod read;
|
||||
|
@ -16,6 +17,7 @@ use crate::tag::{
|
|||
use crate::util::flag_item;
|
||||
use crate::util::io::{FileLike, Length, Truncate};
|
||||
use atom::{AdvisoryRating, Atom, AtomData};
|
||||
use advisory_rating::AdvisoryRating;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::io::Write;
|
||||
|
|
|
@ -24,6 +24,7 @@ pub mod constants {
|
|||
pub use crate::mp4::properties::{AudioObjectType, Mp4Codec, Mp4Properties};
|
||||
pub use atom_info::AtomIdent;
|
||||
pub use ilst::atom::{AdvisoryRating, Atom, AtomData};
|
||||
pub use ilst::advisory_rating::AdvisoryRating;
|
||||
pub use ilst::Ilst;
|
||||
|
||||
pub(crate) use properties::SAMPLE_RATES;
|
||||
|
|
Loading…
Reference in a new issue