mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
Remove old dependencies
This commit is contained in:
parent
77278111a1
commit
bf703e474d
3 changed files with 78 additions and 81 deletions
|
@ -12,15 +12,10 @@ categories = ["accessibility", "multimedia::audio"]
|
|||
[dependencies]
|
||||
# Id3
|
||||
flate2 = { version = "1.0.20", optional = true }
|
||||
id3 = {version = "0.6.4", optional = true} # De/Encoding
|
||||
filepath = { version = "0.1.1", optional = true } # wav/aiff only supports paths for some reason
|
||||
# Ogg
|
||||
ogg_pager = { version = "0.1.7", optional = true }
|
||||
# Mp4
|
||||
mp4ameta = {version = "0.11.0", optional = true}
|
||||
simdutf8 = { version = "0.1.3", optional = true }
|
||||
# Case insensitive keys (APE/FLAC/Opus/Vorbis)
|
||||
unicase = { version = "2.6.0"}
|
||||
|
||||
# Quick string accessor methods for Tag
|
||||
paste = { version = "1.0.5", optional = true }
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use super::read::read_comments;
|
||||
use super::write::create_comments;
|
||||
use crate::error::{LoftyError, Result};
|
||||
use crate::picture::Picture;
|
||||
use crate::types::file::AudioFile;
|
||||
|
|
|
@ -10,80 +10,83 @@ use std::fs::File;
|
|||
use std::io::{Seek, SeekFrom, Write};
|
||||
|
||||
use ogg_pager::Page;
|
||||
use unicase::UniCase;
|
||||
|
||||
pub(crate) fn create_comments(packet: &mut Vec<u8>, comments: &HashMap<UniCase<String>, String>) {
|
||||
for (a, b) in comments {
|
||||
let comment = format!("{}={}", a, b);
|
||||
let comment_b = comment.as_bytes();
|
||||
packet.extend((comment_b.len() as u32).to_le_bytes().iter());
|
||||
packet.extend(comment_b.iter());
|
||||
}
|
||||
}
|
||||
// TODO
|
||||
// use unicase::UniCase;
|
||||
//
|
||||
// pub(crate) fn create_comments(packet: &mut Vec<u8>, comments: &HashMap<UniCase<String>, String>) {
|
||||
// for (a, b) in comments {
|
||||
// let comment = format!("{}={}", a, b);
|
||||
// let comment_b = comment.as_bytes();
|
||||
// packet.extend((comment_b.len() as u32).to_le_bytes().iter());
|
||||
// packet.extend(comment_b.iter());
|
||||
// }
|
||||
// }
|
||||
|
||||
pub(crate) fn create_pages(
|
||||
file: &mut File,
|
||||
sig: &[u8],
|
||||
vendor: &str,
|
||||
comments: &HashMap<UniCase<String>, String>,
|
||||
pictures: &Option<Cow<'static, [Picture]>>,
|
||||
) -> Result<()> {
|
||||
let mut packet = Vec::new();
|
||||
|
||||
packet.extend(sig.iter());
|
||||
packet.extend((vendor.len() as u32).to_le_bytes().iter());
|
||||
packet.extend(vendor.as_bytes().iter());
|
||||
|
||||
let comments_len = pictures.as_ref().map_or_else(
|
||||
|| comments.len() as u32,
|
||||
|pictures| (comments.len() + pictures.len()) as u32,
|
||||
);
|
||||
|
||||
packet.extend(comments_len.to_le_bytes().iter());
|
||||
create_comments(&mut packet, comments);
|
||||
|
||||
if let Some(pics) = pictures {
|
||||
for pic in pics.iter() {
|
||||
let comment = format!(
|
||||
"METADATA_BLOCK_PICTURE={}",
|
||||
base64::encode(pic.as_flac_bytes())
|
||||
);
|
||||
let comment_b = comment.as_bytes();
|
||||
packet.extend((comment_b.len() as u32).to_le_bytes().iter());
|
||||
packet.extend(comment_b.iter());
|
||||
}
|
||||
}
|
||||
|
||||
let mut pages = page_from_packet(&mut *packet)?;
|
||||
write_to(file, &mut pages, sig)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_to(mut data: &mut File, pages: &mut [Page], sig: &[u8]) -> Result<()> {
|
||||
let first_page = Page::read(&mut data, false)?;
|
||||
|
||||
let ser = first_page.serial;
|
||||
|
||||
let mut writer = Vec::new();
|
||||
writer.write_all(&*first_page.as_bytes())?;
|
||||
|
||||
let first_md_page = Page::read(&mut data, false)?;
|
||||
verify_signature(&first_md_page, sig)?;
|
||||
|
||||
match sig {
|
||||
VORBIS_COMMENT_HEAD => {
|
||||
vorbis::write_to(data, &mut writer, first_md_page.content, ser, pages)?;
|
||||
},
|
||||
OPUSTAGS => {
|
||||
opus::write_to(data, &mut writer, ser, pages)?;
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
data.seek(SeekFrom::Start(0))?;
|
||||
data.set_len(first_page.end as u64)?;
|
||||
data.write_all(&*writer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// TODO
|
||||
// pub(crate) fn create_pages(
|
||||
// file: &mut File,
|
||||
// sig: &[u8],
|
||||
// vendor: &str,
|
||||
// comments: &HashMap<UniCase<String>, String>,
|
||||
// pictures: &Option<Cow<'static, [Picture]>>,
|
||||
// ) -> Result<()> {
|
||||
// let mut packet = Vec::new();
|
||||
//
|
||||
// packet.extend(sig.iter());
|
||||
// packet.extend((vendor.len() as u32).to_le_bytes().iter());
|
||||
// packet.extend(vendor.as_bytes().iter());
|
||||
//
|
||||
// let comments_len = pictures.as_ref().map_or_else(
|
||||
// || comments.len() as u32,
|
||||
// |pictures| (comments.len() + pictures.len()) as u32,
|
||||
// );
|
||||
//
|
||||
// packet.extend(comments_len.to_le_bytes().iter());
|
||||
// create_comments(&mut packet, comments);
|
||||
//
|
||||
// if let Some(pics) = pictures {
|
||||
// for pic in pics.iter() {
|
||||
// let comment = format!(
|
||||
// "METADATA_BLOCK_PICTURE={}",
|
||||
// base64::encode(pic.as_flac_bytes())
|
||||
// );
|
||||
// let comment_b = comment.as_bytes();
|
||||
// packet.extend((comment_b.len() as u32).to_le_bytes().iter());
|
||||
// packet.extend(comment_b.iter());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let mut pages = page_from_packet(&mut *packet)?;
|
||||
// write_to(file, &mut pages, sig)?;
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// fn write_to(mut data: &mut File, pages: &mut [Page], sig: &[u8]) -> Result<()> {
|
||||
// let first_page = Page::read(&mut data, false)?;
|
||||
//
|
||||
// let ser = first_page.serial;
|
||||
//
|
||||
// let mut writer = Vec::new();
|
||||
// writer.write_all(&*first_page.as_bytes())?;
|
||||
//
|
||||
// let first_md_page = Page::read(&mut data, false)?;
|
||||
// verify_signature(&first_md_page, sig)?;
|
||||
//
|
||||
// match sig {
|
||||
// VORBIS_COMMENT_HEAD => {
|
||||
// vorbis::write_to(data, &mut writer, first_md_page.content, ser, pages)?;
|
||||
// },
|
||||
// OPUSTAGS => {
|
||||
// opus::write_to(data, &mut writer, ser, pages)?;
|
||||
// },
|
||||
// _ => unreachable!(),
|
||||
// }
|
||||
//
|
||||
// data.seek(SeekFrom::Start(0))?;
|
||||
// data.set_len(first_page.end as u64)?;
|
||||
// data.write_all(&*writer)?;
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue