mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
Give FLAC its own module
This commit is contained in:
parent
ebb5dae2c6
commit
301d457cd3
14 changed files with 39 additions and 23 deletions
|
@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- The method still only supports PNG and JPEG, but rather than error when it encounters an unknown image, it will return
|
||||
`PictureInformation::default`
|
||||
- `lofty::read_from` will now wrap the `File` in a `BufReader`
|
||||
- **FLAC**: FLAC now has its own module at `lofty::flac`
|
||||
|
||||
### Fixed
|
||||
- **MP4**: Non-full `meta` atoms are now properly handled.
|
||||
|
|
|
@ -5,17 +5,17 @@ use std::io::{Read, Seek, SeekFrom};
|
|||
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
|
||||
pub(super) struct Block {
|
||||
pub(super) byte: u8,
|
||||
pub(super) ty: u8,
|
||||
pub(super) last: bool,
|
||||
pub(super) content: Vec<u8>,
|
||||
pub(super) start: u64,
|
||||
pub(super) end: u64,
|
||||
pub(crate) struct Block {
|
||||
pub(crate) byte: u8,
|
||||
pub(crate) ty: u8,
|
||||
pub(crate) last: bool,
|
||||
pub(crate) content: Vec<u8>,
|
||||
pub(crate) start: u64,
|
||||
pub(crate) end: u64,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
pub(in crate::ogg) fn read<R>(data: &mut R) -> Result<Self>
|
||||
pub(crate) fn read<R>(data: &mut R) -> Result<Self>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
|
@ -1,21 +1,35 @@
|
|||
//! Items for FLAC
|
||||
//!
|
||||
//! ## File notes
|
||||
//!
|
||||
//! * See [`FlacFile`]
|
||||
|
||||
mod block;
|
||||
mod properties;
|
||||
mod read;
|
||||
#[cfg(feature = "vorbis_comments")]
|
||||
pub(crate) mod write;
|
||||
|
||||
#[cfg(feature = "vorbis_comments")]
|
||||
use super::tag::VorbisComments;
|
||||
use crate::error::Result;
|
||||
use crate::file::{AudioFile, FileType, TaggedFile};
|
||||
#[cfg(feature = "id3v2")]
|
||||
use crate::id3::v2::tag::Id3v2Tag;
|
||||
#[cfg(feature = "vorbis_comments")]
|
||||
use crate::ogg::VorbisComments;
|
||||
use crate::properties::FileProperties;
|
||||
use crate::tag::TagType;
|
||||
|
||||
use std::io::{Read, Seek};
|
||||
|
||||
/// A FLAC file
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
/// * The ID3v2 tag is **read only**, and it's use is discouraged by spec
|
||||
/// * Picture blocks will be stored in the `VorbisComments` tag, meaning a file could have no vorbis
|
||||
/// comments block, but `FlacFile::vorbis_comments` will exist.
|
||||
/// * When writing, the pictures will be stored in their own picture blocks
|
||||
/// * This behavior will likely change in the future
|
||||
pub struct FlacFile {
|
||||
#[cfg(feature = "id3v2")]
|
||||
/// An ID3v2 tag
|
|
@ -6,7 +6,7 @@ use std::time::Duration;
|
|||
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
|
||||
pub(super) fn read_properties<R>(
|
||||
pub(crate) fn read_properties<R>(
|
||||
stream_info: &mut R,
|
||||
stream_length: u64,
|
||||
file_length: u64,
|
|
@ -14,7 +14,7 @@ use crate::{
|
|||
|
||||
use std::io::{Read, Seek, SeekFrom};
|
||||
|
||||
pub(super) fn verify_flac<R>(data: &mut R) -> Result<Block>
|
||||
pub(crate) fn verify_flac<R>(data: &mut R) -> Result<Block>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ where
|
|||
Ok(block)
|
||||
}
|
||||
|
||||
pub(super) fn read_from<R>(data: &mut R, read_properties: bool) -> Result<FlacFile>
|
||||
pub(crate) fn read_from<R>(data: &mut R, read_properties: bool) -> Result<FlacFile>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
|
@ -12,7 +12,7 @@ use byteorder::{LittleEndian, WriteBytesExt};
|
|||
|
||||
const MAX_BLOCK_SIZE: u32 = 16_777_215;
|
||||
|
||||
pub(in crate) fn write_to<'a, II, IP>(
|
||||
pub(crate) fn write_to<'a, II, IP>(
|
||||
data: &mut File,
|
||||
tag: &mut VorbisCommentsRef<'a, II, IP>,
|
||||
) -> Result<()>
|
|
@ -167,6 +167,7 @@
|
|||
pub mod ape;
|
||||
pub mod error;
|
||||
pub(crate) mod file;
|
||||
pub mod flac;
|
||||
pub mod id3;
|
||||
pub mod iff;
|
||||
pub(crate) mod macros;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
//!
|
||||
//! The only supported tag format is [`VorbisComments`]
|
||||
pub(crate) mod constants;
|
||||
pub(crate) mod flac;
|
||||
pub(crate) mod opus;
|
||||
pub(crate) mod read;
|
||||
pub(crate) mod speex;
|
||||
|
@ -28,7 +27,6 @@ cfg_if::cfg_if! {
|
|||
}
|
||||
}
|
||||
|
||||
pub use flac::FlacFile;
|
||||
pub use opus::properties::OpusProperties;
|
||||
pub use opus::OpusFile;
|
||||
pub use speex::properties::SpeexProperties;
|
||||
|
|
|
@ -19,7 +19,7 @@ pub type OGGTags = (Option<VorbisComments>, Page);
|
|||
pub type OGGTags = (Option<()>, Page);
|
||||
|
||||
#[cfg(feature = "vorbis_comments")]
|
||||
pub(super) fn read_comments<R>(data: &mut R, tag: &mut VorbisComments) -> Result<()>
|
||||
pub(crate) fn read_comments<R>(data: &mut R, tag: &mut VorbisComments) -> Result<()>
|
||||
where
|
||||
R: Read,
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::tag::item::{ItemKey, ItemValue, TagItem};
|
|||
use crate::tag::{Tag, TagType};
|
||||
use crate::traits::{Accessor, TagExt};
|
||||
|
||||
use crate::flac::write;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Cursor, Write};
|
||||
use std::path::Path;
|
||||
|
@ -289,7 +290,7 @@ where
|
|||
let file = probe.into_inner();
|
||||
|
||||
match f_ty {
|
||||
Some(FileType::FLAC) => super::flac::write::write_to(file, self),
|
||||
Some(FileType::FLAC) => write::write_to(file, self),
|
||||
Some(FileType::Opus) => super::write::write(file, self, OGGFormat::Opus),
|
||||
Some(FileType::Vorbis) => super::write::write(file, self, OGGFormat::Vorbis),
|
||||
Some(FileType::Speex) => super::write::write(file, self, OGGFormat::Speex),
|
||||
|
|
|
@ -11,6 +11,7 @@ use std::convert::TryFrom;
|
|||
use std::fs::File;
|
||||
use std::io::{Cursor, Read, Seek, SeekFrom, Write};
|
||||
|
||||
use crate::flac::write;
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use ogg_pager::Page;
|
||||
|
||||
|
@ -45,7 +46,7 @@ pub(in crate) fn write_to(file: &mut File, tag: &Tag, file_type: FileType) -> Re
|
|||
};
|
||||
|
||||
if let FileType::FLAC = file_type {
|
||||
return super::flac::write::write_to(file, &mut comments_ref);
|
||||
return write::write_to(file, &mut comments_ref);
|
||||
}
|
||||
|
||||
let format = match file_type {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crate::ape::ApeFile;
|
||||
use crate::error::{ErrorKind, LoftyError, Result};
|
||||
use crate::file::{AudioFile, FileType, TaggedFile};
|
||||
use crate::flac::FlacFile;
|
||||
use crate::iff::aiff::AiffFile;
|
||||
use crate::iff::wav::WavFile;
|
||||
use crate::mp3::header::search_for_frame_sync;
|
||||
use crate::mp3::Mp3File;
|
||||
use crate::mp4::Mp4File;
|
||||
use crate::ogg::flac::FlacFile;
|
||||
use crate::ogg::opus::OpusFile;
|
||||
use crate::ogg::speex::SpeexFile;
|
||||
use crate::ogg::vorbis::VorbisFile;
|
||||
|
|
|
@ -60,12 +60,12 @@ impl FileProperties {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ape::{ApeFile, ApeProperties};
|
||||
use crate::flac::FlacFile;
|
||||
use crate::iff::{AiffFile, WavFile, WavFormat, WavProperties};
|
||||
use crate::mp3::{ChannelMode, Emphasis, Layer, Mp3File, Mp3Properties, MpegVersion};
|
||||
use crate::mp4::{AudioObjectType, Mp4Codec, Mp4File, Mp4Properties};
|
||||
use crate::ogg::{
|
||||
FlacFile, OpusFile, OpusProperties, SpeexFile, SpeexProperties, VorbisFile,
|
||||
VorbisProperties,
|
||||
OpusFile, OpusProperties, SpeexFile, SpeexProperties, VorbisFile, VorbisProperties,
|
||||
};
|
||||
use crate::{AudioFile, FileProperties};
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ fn remove(path: &str, tag_type: TagType) {
|
|||
|
||||
#[test]
|
||||
fn flac_with_id3v2() {
|
||||
use lofty::ogg::FlacFile;
|
||||
use lofty::flac::FlacFile;
|
||||
use lofty::{Accessor, AudioFile};
|
||||
|
||||
let file = std::fs::read("tests/files/assets/flac_with_id3v2.flac").unwrap();
|
||||
|
|
Loading…
Reference in a new issue