Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **VorbisComments**: `ItemKey::Barcode` mapping ([PR](https://github.com/Serial-ATA/lofty-rs/pull/183))

### Changed
- **ID3v1**: `ID3v1Tag` -> `Id3v1Tag`
- **ID3v2**:
- `SyncTextInformation` no longer uses a String for its language ([PR](https://github.com/Serial-ATA/lofty-rs/pull/184))
- `FrameID` -> `FrameId`
- `ID3v2Version` -> `Id3v2Version`
- `ID3v2TagFlags` -> `Id3v2TagFlags`
- `ID3v2Tag` -> `Id3v2Tag`
- There are fewer redundant, intermediate allocations ([PR](https://github.com/Serial-ATA/lofty-rs/pull/194))
- **FileType/TagType/ItemKey**: All variants have been changed to UpperCamelCase ([PR](https://github.com/Serial-ATA/lofty-rs/pull/190))
- **MPEG**:
Expand Down
8 changes: 4 additions & 4 deletions benches/create_tag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lofty::ape::ApeTag;
use lofty::id3::v1::ID3v1Tag;
use lofty::id3::v2::ID3v2Tag;
use lofty::id3::v1::Id3v1Tag;
use lofty::id3::v2::Id3v2Tag;
use lofty::iff::aiff::AIFFTextChunks;
use lofty::iff::wav::RIFFInfoList;
use lofty::mp4::Ilst;
Expand Down Expand Up @@ -36,8 +36,8 @@ fn bench_write(c: &mut Criterion) {
[
("AIFF Text Chunks", AIFFTextChunks),
("APEv2", ApeTag),
("ID3v2", ID3v2Tag),
("ID3v1", ID3v1Tag),
("ID3v2", Id3v2Tag),
("ID3v1", Id3v1Tag),
("MP4 Ilst", Ilst),
("RIFF INFO", RIFFInfoList),
("Vorbis Comments", VorbisComments),
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_resolver/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lofty::ape::ApeTag;
use lofty::error::Result as LoftyResult;
use lofty::id3::v2::ID3v2Tag;
use lofty::id3::v2::Id3v2Tag;
use lofty::resolve::FileResolver;
use lofty::{FileProperties, FileType, ParseOptions, TagType};
use lofty_attr::LoftyFile;
Expand All @@ -26,7 +26,7 @@ struct MyFile {
// Specify a tag type
#[lofty(tag_type = "Id3v2")]
// Let's say our file *always* has an ID3v2Tag present.
pub id3v2_tag: ID3v2Tag,
pub id3v2_tag: Id3v2Tag,

// Our APE tag is optional in this format, so we wrap it in an `Option`
#[lofty(tag_type = "Ape")]
Expand All @@ -45,7 +45,7 @@ impl MyFile {
// Your parsing logic...

Ok(Self {
id3v2_tag: ID3v2Tag::default(),
id3v2_tag: Id3v2Tag::default(),
ape_tag: None,
properties: FileProperties::default(),
})
Expand Down
2 changes: 1 addition & 1 deletion lofty_attr/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn init_write_lookup(
} else {
insert!(map, Id3v2, {
lofty::id3::v2::tag::Id3v2TagRef {
flags: lofty::id3::v2::ID3v2TagFlags::default(),
flags: lofty::id3::v2::Id3v2TagFlags::default(),
frames: lofty::id3::v2::tag::tag_frames(tag),
}
.write_to(data)
Expand Down
8 changes: 4 additions & 4 deletions src/aac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod header;
mod properties;
mod read;

use crate::id3::v1::tag::ID3v1Tag;
use crate::id3::v2::tag::ID3v2Tag;
use crate::id3::v1::tag::Id3v1Tag;
use crate::id3::v2::tag::Id3v2Tag;

use lofty_attr::LoftyFile;

Expand All @@ -21,8 +21,8 @@ pub use properties::AACProperties;
#[lofty(internal_write_module_do_not_use_anywhere_else)]
pub struct AacFile {
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
pub(crate) id3v2_tag: Option<Id3v2Tag>,
#[lofty(tag_type = "Id3v1")]
pub(crate) id3v1_tag: Option<ID3v1Tag>,
pub(crate) id3v1_tag: Option<Id3v1Tag>,
pub(crate) properties: AACProperties,
}
8 changes: 4 additions & 4 deletions src/ape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod properties;
mod read;
pub(crate) mod tag;

use crate::id3::v1::tag::ID3v1Tag;
use crate::id3::v2::tag::ID3v2Tag;
use crate::id3::v1::tag::Id3v1Tag;
use crate::id3::v2::tag::Id3v2Tag;

use lofty_attr::LoftyFile;

Expand All @@ -30,10 +30,10 @@ pub use tag::ApeTag;
pub struct ApeFile {
/// An ID3v1 tag
#[lofty(tag_type = "Id3v1")]
pub(crate) id3v1_tag: Option<ID3v1Tag>,
pub(crate) id3v1_tag: Option<Id3v1Tag>,
/// An ID3v2 tag (Not officially supported)
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
pub(crate) id3v2_tag: Option<Id3v2Tag>,
/// An APEv1/v2 tag
#[lofty(tag_type = "Ape")]
pub(crate) ape_tag: Option<ApeTag>,
Expand Down
8 changes: 4 additions & 4 deletions src/ape/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use super::tag::read::read_ape_tag;
use super::tag::ApeTag;
use super::{ApeFile, ApeProperties};
use crate::error::Result;
use crate::id3::v1::tag::ID3v1Tag;
use crate::id3::v1::tag::Id3v1Tag;
use crate::id3::v2::read::parse_id3v2;
use crate::id3::v2::tag::ID3v2Tag;
use crate::id3::v2::tag::Id3v2Tag;
use crate::id3::{find_id3v1, find_id3v2, find_lyrics3v2, ID3FindResults};
use crate::macros::decode_err;
use crate::probe::ParseOptions;
Expand All @@ -24,8 +24,8 @@ where

let mut stream_len = end - start;

let mut id3v2_tag: Option<ID3v2Tag> = None;
let mut id3v1_tag: Option<ID3v1Tag> = None;
let mut id3v2_tag: Option<Id3v2Tag> = None;
let mut id3v1_tag: Option<Id3v1Tag> = None;
let mut ape_tag: Option<ApeTag> = None;

// ID3v2 tags are unsupported in APE files, but still possible
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub enum Id3v2ErrorKind {
InvalidUnsynchronisation,
/// Arises when a text encoding other than Latin-1 or UTF-16 appear in an ID3v2.2 tag
V2InvalidTextEncoding,
/// Arises when an invalid picture format is parsed. Only applicable to [`ID3v2Version::V2`](crate::id3::v2::ID3v2Version::V2)
/// Arises when an invalid picture format is parsed. Only applicable to [`ID3v2Version::V2`](crate::id3::v2::Id3v2Version::V2)
BadPictureFormat(String),
/// Arises when invalid data is encountered while reading an ID3v2 synchronized text frame
BadSyncText,
Expand Down
4 changes: 2 additions & 2 deletions src/flac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) mod write;

use crate::error::Result;
use crate::file::{FileType, TaggedFile};
use crate::id3::v2::tag::ID3v2Tag;
use crate::id3::v2::tag::Id3v2Tag;
use crate::ogg::tag::VorbisCommentsRef;
use crate::ogg::{OggPictureStorage, VorbisComments};
use crate::picture::{Picture, PictureInformation};
Expand Down Expand Up @@ -44,7 +44,7 @@ pub use properties::FlacProperties;
pub struct FlacFile {
/// An ID3v2 tag
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
pub(crate) id3v2_tag: Option<Id3v2Tag>,
/// The vorbis comments contained in the file
#[lofty(tag_type = "VorbisComments")]
pub(crate) vorbis_comments_tag: Option<VorbisComments>,
Expand Down
6 changes: 3 additions & 3 deletions src/id3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod v2;

use crate::error::{ErrorKind, LoftyError, Result};
use crate::macros::try_vec;
use v2::{read_id3v2_header, ID3v2Header};
use v2::{read_id3v2_header, Id3v2Header};

use std::io::{Read, Seek, SeekFrom};
use std::ops::Neg;
Expand Down Expand Up @@ -49,7 +49,7 @@ where
pub(crate) fn find_id3v1<R>(
data: &mut R,
read: bool,
) -> Result<ID3FindResults<(), Option<v1::tag::ID3v1Tag>>>
) -> Result<ID3FindResults<(), Option<v1::tag::Id3v1Tag>>>
where
R: Read + Seek,
{
Expand Down Expand Up @@ -85,7 +85,7 @@ where
pub(crate) fn find_id3v2<R>(
data: &mut R,
read: bool,
) -> Result<ID3FindResults<ID3v2Header, Option<Vec<u8>>>>
) -> Result<ID3FindResults<Id3v2Header, Option<Vec<u8>>>>
where
R: Read + Seek,
{
Expand Down
4 changes: 2 additions & 2 deletions src/id3/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! # ID3v1 notes
//!
//! See also: [`ID3v1Tag`]
//! See also: [`Id3v1Tag`]
//!
//! ## Genres
//!
Expand All @@ -22,4 +22,4 @@ pub(crate) mod write;
// Exports

pub use constants::GENRES;
pub use tag::ID3v1Tag;
pub use tag::Id3v1Tag;
6 changes: 3 additions & 3 deletions src/id3/v1/read.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::constants::GENRES;
use super::tag::ID3v1Tag;
use super::tag::Id3v1Tag;

pub fn parse_id3v1(reader: [u8; 128]) -> ID3v1Tag {
let mut tag = ID3v1Tag {
pub fn parse_id3v1(reader: [u8; 128]) -> Id3v1Tag {
let mut tag = Id3v1Tag {
title: None,
artist: None,
album: None,
Expand Down
30 changes: 15 additions & 15 deletions src/id3/v1/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ macro_rules! impl_accessor {
description = "An ID3v1 tag",
supported_formats(Aac, Ape, Mpeg, WavPack)
)]
pub struct ID3v1Tag {
pub struct Id3v1Tag {
/// Track title, 30 bytes max
pub title: Option<String>,
/// Track artist, 30 bytes max
Expand Down Expand Up @@ -89,24 +89,24 @@ pub struct ID3v1Tag {
pub genre: Option<u8>,
}

impl ID3v1Tag {
impl Id3v1Tag {
/// Create a new empty `ID3v1Tag`
///
/// # Examples
///
/// ```rust
/// use lofty::id3::v1::ID3v1Tag;
/// use lofty::id3::v1::Id3v1Tag;
/// use lofty::TagExt;
///
/// let id3v1_tag = ID3v1Tag::new();
/// let id3v1_tag = Id3v1Tag::new();
/// assert!(id3v1_tag.is_empty());
/// ```
pub fn new() -> Self {
Self::default()
}
}

impl Accessor for ID3v1Tag {
impl Accessor for Id3v1Tag {
impl_accessor!(title, artist, album,);

fn genre(&self) -> Option<Cow<'_, str>> {
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Accessor for ID3v1Tag {
}
}

impl TagExt for ID3v1Tag {
impl TagExt for Id3v1Tag {
type Err = LoftyError;
type RefKey<'a> = &'a ItemKey;

Expand Down Expand Up @@ -254,7 +254,7 @@ impl TagExt for ID3v1Tag {
#[derive(Debug, Clone, Default)]
pub struct SplitTagRemainder;

impl SplitTag for ID3v1Tag {
impl SplitTag for Id3v1Tag {
type Remainder = SplitTagRemainder;

fn split_tag(mut self) -> (Self::Remainder, Tag) {
Expand Down Expand Up @@ -292,20 +292,20 @@ impl SplitTag for ID3v1Tag {
}

impl MergeTag for SplitTagRemainder {
type Merged = ID3v1Tag;
type Merged = Id3v1Tag;

fn merge_tag(self, tag: Tag) -> Self::Merged {
tag.into()
}
}

impl From<ID3v1Tag> for Tag {
fn from(input: ID3v1Tag) -> Self {
impl From<Id3v1Tag> for Tag {
fn from(input: Id3v1Tag) -> Self {
input.split_tag().1
}
}

impl From<Tag> for ID3v1Tag {
impl From<Tag> for Id3v1Tag {
fn from(mut input: Tag) -> Self {
let title = input.take_strings(&ItemKey::TrackTitle).next();
let artist = input.take_strings(&ItemKey::TrackArtist).next();
Expand Down Expand Up @@ -345,7 +345,7 @@ pub(crate) struct Id3v1TagRef<'a> {
pub genre: Option<u8>,
}

impl<'a> Into<Id3v1TagRef<'a>> for &'a ID3v1Tag {
impl<'a> Into<Id3v1TagRef<'a>> for &'a Id3v1Tag {
fn into(self) -> Id3v1TagRef<'a> {
Id3v1TagRef {
title: self.title.as_deref(),
Expand Down Expand Up @@ -409,12 +409,12 @@ impl<'a> Id3v1TagRef<'a> {

#[cfg(test)]
mod tests {
use crate::id3::v1::ID3v1Tag;
use crate::id3::v1::Id3v1Tag;
use crate::{Tag, TagExt, TagType};

#[test]
fn parse_id3v1() {
let expected_tag = ID3v1Tag {
let expected_tag = Id3v1Tag {
title: Some(String::from("Foo title")),
artist: Some(String::from("Bar artist")),
album: Some(String::from("Baz album")),
Expand Down Expand Up @@ -457,7 +457,7 @@ mod tests {
fn tag_to_id3v1() {
let tag = crate::tag::utils::test_utils::create_tag(TagType::Id3v1);

let id3v1_tag: ID3v1Tag = tag.into();
let id3v1_tag: Id3v1Tag = tag.into();

assert_eq!(id3v1_tag.title.as_deref(), Some("Foo title"));
assert_eq!(id3v1_tag.artist.as_deref(), Some("Bar artist"));
Expand Down
2 changes: 1 addition & 1 deletion src/id3/v1/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) fn write_id3v1(file: &mut File, tag: &Id3v1TagRef<'_>) -> Result<()>
let probe = Probe::new(file).guess_file_type()?;

match probe.file_type() {
Some(ft) if super::ID3v1Tag::SUPPORTED_FORMATS.contains(&ft) => {},
Some(ft) if super::Id3v1Tag::SUPPORTED_FORMATS.contains(&ft) => {},
_ => err!(UnsupportedTag),
}

Expand Down
2 changes: 1 addition & 1 deletion src/id3/v2/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::restrictions::TagRestrictions;
/// Flags that apply to the entire tag
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
#[allow(clippy::struct_excessive_bools)]
pub struct ID3v2TagFlags {
pub struct Id3v2TagFlags {
/// Whether or not all frames are unsynchronised. See [`FrameFlags::unsynchronisation`](crate::id3::v2::FrameFlags::unsynchronisation)
pub unsynchronisation: bool,
/// Indicates if the tag is in an experimental stage
Expand Down
12 changes: 6 additions & 6 deletions src/id3/v2/frame/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::id3::v2::items::{
AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Popularimeter,
TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, UrlLinkFrame,
};
use crate::id3::v2::ID3v2Version;
use crate::id3::v2::Id3v2Version;
use crate::macros::err;
use crate::util::text::TextEncoding;

use std::io::Read;

#[rustfmt::skip]
pub(super) fn parse_content<R: Read>(
reader: &mut R,
id: &str,
version: ID3v2Version,
reader: &mut R,
id: &str,
version: Id3v2Version,
) -> Result<Option<FrameValue>> {
Ok(match id {
// The ID was previously upgraded, but the content remains unchanged, so version is necessary
Expand Down Expand Up @@ -45,9 +45,9 @@ pub(super) fn parse_content<R: Read>(

pub(in crate::id3::v2) fn verify_encoding(
encoding: u8,
version: ID3v2Version,
version: Id3v2Version,
) -> Result<TextEncoding> {
if version == ID3v2Version::V2 && (encoding != 0 && encoding != 1) {
if version == Id3v2Version::V2 && (encoding != 0 && encoding != 1) {
return Err(Id3v2Error::new(Id3v2ErrorKind::V2InvalidTextEncoding).into());
}

Expand Down
Loading