mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
Start using UniCase for OGG formats
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
68ff71c889
commit
a9b78c7aa0
5 changed files with 19 additions and 15 deletions
|
@ -10,9 +10,9 @@ keywords = ["tags", "audio", "metadata"]
|
|||
categories = ["accessibility", "multimedia::audio"]
|
||||
|
||||
[dependencies]
|
||||
unicase = { version = "2.6.0", optional = true }
|
||||
# Ape
|
||||
ape = {version = "0.3.0", optional = true, git = "https://github.com/rossnomann/rust-ape"}
|
||||
unicase = { version = "2.6.0", optional = true }
|
||||
# Id3
|
||||
id3 = {version = "0.6.4", optional = true} # De/Encoding
|
||||
filepath = { version = "0.1.1", optional = true } # wav/aiff only supports paths for some reason
|
||||
|
@ -35,8 +35,8 @@ lofty_attr = "0.1.7"
|
|||
default = ["all_tags"]
|
||||
format-mp4 = ["mp4ameta"]
|
||||
format-flac = ["metaflac"]
|
||||
format-opus = ["ogg_pager"]
|
||||
format-vorbis = ["ogg_pager"]
|
||||
format-opus = ["ogg_pager", "unicase"]
|
||||
format-vorbis = ["ogg_pager", "unicase"]
|
||||
format-ape = ["ape", "unicase"]
|
||||
format-id3 = ["id3", "filepath"]
|
||||
format-aiff = []
|
||||
|
|
|
@ -5,11 +5,12 @@ use std::collections::HashMap;
|
|||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
|
||||
use metaflac::BlockType;
|
||||
use unicase::UniCase;
|
||||
|
||||
pub(crate) fn write_to<T>(
|
||||
mut data: T,
|
||||
vendor: &str,
|
||||
comments: &HashMap<String, String>,
|
||||
comments: &HashMap<UniCase<String>, String>,
|
||||
pictures: &Option<Cow<'static, [Picture]>>,
|
||||
) -> Result<()>
|
||||
where
|
||||
|
@ -37,7 +38,7 @@ where
|
|||
}
|
||||
|
||||
for (k, v) in comments.clone() {
|
||||
comment_collection.insert(k, vec![v]);
|
||||
comment_collection.insert(k.into_inner(), vec![v]);
|
||||
}
|
||||
|
||||
let comments = metaflac::Block::VorbisComment(metaflac::block::VorbisComment {
|
||||
|
|
|
@ -6,8 +6,9 @@ use std::io::{Read, Seek};
|
|||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use ogg_pager::Page;
|
||||
use unicase::UniCase;
|
||||
|
||||
pub type OGGTags = (String, Vec<Picture>, HashMap<String, String>, OggFormat);
|
||||
pub type OGGTags = (String, Vec<Picture>, HashMap<UniCase<String>, String>, OggFormat);
|
||||
|
||||
pub(crate) fn read_from<T>(
|
||||
mut data: T,
|
||||
|
@ -39,7 +40,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let mut md: HashMap<String, String> = HashMap::new();
|
||||
let mut md: HashMap<UniCase<String>, String> = HashMap::new();
|
||||
let mut pictures = Vec::new();
|
||||
|
||||
let reader = &mut &md_pages[..];
|
||||
|
@ -72,7 +73,7 @@ where
|
|||
if split[0] == "METADATA_BLOCK_PICTURE" {
|
||||
pictures.push(Picture::from_apic_bytes(split[1].as_bytes())?)
|
||||
} else {
|
||||
md.insert(split[0].to_string(), split[1].to_string());
|
||||
md.insert(UniCase::from(split[0].to_string()), split[1].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,13 @@ use std::io::{Cursor, Read, Seek, SeekFrom, Write};
|
|||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use ogg_pager::Page;
|
||||
use unicase::UniCase;
|
||||
|
||||
pub(crate) fn create_pages(
|
||||
file: &mut File,
|
||||
sig: &[u8],
|
||||
vendor: &str,
|
||||
comments: &HashMap<String, String>,
|
||||
comments: &HashMap<UniCase<String>, String>,
|
||||
pictures: &Option<Cow<'static, [Picture]>>,
|
||||
) -> Result<()> {
|
||||
let mut packet = Vec::new();
|
||||
|
|
|
@ -21,10 +21,11 @@ use std::fs::File;
|
|||
use std::io::{Read, Seek, SeekFrom};
|
||||
|
||||
use lofty_attr::{get_set_methods, impl_tag};
|
||||
use unicase::UniCase;
|
||||
|
||||
struct OggInnerTag {
|
||||
vendor: String,
|
||||
comments: HashMap<String, String>,
|
||||
comments: HashMap<UniCase<String>, String>,
|
||||
pictures: Option<Cow<'static, [Picture]>>,
|
||||
}
|
||||
|
||||
|
@ -128,11 +129,11 @@ impl TryFrom<metaflac::Tag> for OggTag {
|
|||
})
|
||||
}
|
||||
|
||||
let mut comment_collection: HashMap<String, String> = HashMap::new();
|
||||
let mut comment_collection: HashMap<UniCase<String>, String> = HashMap::new();
|
||||
|
||||
for (k, v) in user_comments.clone() {
|
||||
for e in v {
|
||||
comment_collection.insert(k.clone(), e.clone());
|
||||
comment_collection.insert(UniCase::from(k.clone()), e.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +167,7 @@ impl OggTag {
|
|||
fn get_value(&self, key: &str) -> Option<&str> {
|
||||
self.inner
|
||||
.comments
|
||||
.get_key_value(key)
|
||||
.get_key_value(&UniCase::from(key.to_string()))
|
||||
.map(|(_, v)| v.as_str())
|
||||
}
|
||||
|
||||
|
@ -174,11 +175,11 @@ impl OggTag {
|
|||
where
|
||||
V: Into<String>,
|
||||
{
|
||||
self.inner.comments.insert(key.to_string(), val.into());
|
||||
self.inner.comments.insert(UniCase::from(key.to_string()), val.into());
|
||||
}
|
||||
|
||||
fn remove_key(&mut self, key: &str) {
|
||||
self.inner.comments.remove(key);
|
||||
self.inner.comments.remove(&UniCase::from(key.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue