Added support for Flac metadata
This commit is contained in:
parent
c3e5e27f23
commit
88318e5b4f
5 changed files with 42 additions and 2 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -10,6 +10,7 @@ dependencies = [
|
||||||
"iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"kernel32-sys 0.2.2 (git+https://github.com/retep998/winapi-rs)",
|
"kernel32-sys 0.2.2 (git+https://github.com/retep998/winapi-rs)",
|
||||||
"lewton 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lewton 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"metaflac 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mount 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mount 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ogg 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ogg 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"oven 1.0.0 (git+https://github.com/agersant/oven?branch=remove_cookie_dep)",
|
"oven 1.0.0 (git+https://github.com/agersant/oven?branch=remove_cookie_dep)",
|
||||||
|
@ -454,6 +455,17 @@ dependencies = [
|
||||||
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "metaflac"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
@ -1131,6 +1143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
|
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
|
||||||
"checksum matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "15305656809ce5a4805b1ff2946892810992197ce1270ff79baded852187942e"
|
"checksum matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "15305656809ce5a4805b1ff2946892810992197ce1270ff79baded852187942e"
|
||||||
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
|
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
|
||||||
|
"checksum metaflac 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "66d5865b6103db7bccad008e6d50195236116a44ef67879645bcbc1ce1e9c58b"
|
||||||
"checksum mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5c93a4bd787ddc6e7833c519b73a50883deb5863d76d9b71eb8216fb7f94e66"
|
"checksum mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5c93a4bd787ddc6e7833c519b73a50883deb5863d76d9b71eb8216fb7f94e66"
|
||||||
"checksum mime_guess 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a7d89cb3bce9145b0d0339a0588b044e3e3e3faa1dcd74822ebdc36bfac020"
|
"checksum mime_guess 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a7d89cb3bce9145b0d0339a0588b044e3e3e3faa1dcd74822ebdc36bfac020"
|
||||||
"checksum miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d1f4d337a01c32e1f2122510fed46393d53ca35a7f429cb0450abaedfa3ed54"
|
"checksum miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d1f4d337a01c32e1f2122510fed46393d53ca35a7f429cb0450abaedfa3ed54"
|
||||||
|
|
|
@ -14,6 +14,7 @@ id3 = { git = "https://github.com/jameshurst/rust-id3" }
|
||||||
image = "0.10.3"
|
image = "0.10.3"
|
||||||
iron = "0.4.0"
|
iron = "0.4.0"
|
||||||
lewton = "0.4.0"
|
lewton = "0.4.0"
|
||||||
|
metaflac = "0.1.4"
|
||||||
mount = "0.2.1"
|
mount = "0.2.1"
|
||||||
ogg = "0.4.0"
|
ogg = "0.4.0"
|
||||||
oven = { git = "https://github.com/agersant/oven", branch = "remove_cookie_dep" }
|
oven = { git = "https://github.com/agersant/oven", branch = "remove_cookie_dep" }
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::io;
|
||||||
use id3;
|
use id3;
|
||||||
use image;
|
use image;
|
||||||
use lewton;
|
use lewton;
|
||||||
|
use metaflac;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PError {
|
pub enum PError {
|
||||||
|
@ -58,6 +59,12 @@ impl From<lewton::VorbisError> for PError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<metaflac::Error> for PError {
|
||||||
|
fn from(_: metaflac::Error) -> PError {
|
||||||
|
PError::MetadataDecodingError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl error::Error for PError {
|
impl error::Error for PError {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -6,6 +6,7 @@ extern crate id3;
|
||||||
extern crate image;
|
extern crate image;
|
||||||
extern crate iron;
|
extern crate iron;
|
||||||
extern crate lewton;
|
extern crate lewton;
|
||||||
|
extern crate metaflac;
|
||||||
extern crate mount;
|
extern crate mount;
|
||||||
extern crate ogg;
|
extern crate ogg;
|
||||||
extern crate oven;
|
extern crate oven;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use ape;
|
use ape;
|
||||||
use id3::Tag;
|
use id3;
|
||||||
use lewton::inside_ogg::OggStreamReader;
|
use lewton::inside_ogg::OggStreamReader;
|
||||||
|
use metaflac;
|
||||||
use ogg::PacketReader;
|
use ogg::PacketReader;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -23,6 +24,7 @@ pub struct SongTags {
|
||||||
impl SongTags {
|
impl SongTags {
|
||||||
pub fn read(path: &Path) -> Result<SongTags, PError> {
|
pub fn read(path: &Path) -> Result<SongTags, PError> {
|
||||||
match utils::get_audio_format(path) {
|
match utils::get_audio_format(path) {
|
||||||
|
Some(AudioFormat::FLAC) => SongTags::read_flac(path),
|
||||||
Some(AudioFormat::MP3) => SongTags::read_id3(path),
|
Some(AudioFormat::MP3) => SongTags::read_id3(path),
|
||||||
Some(AudioFormat::MPC) => SongTags::read_ape(path),
|
Some(AudioFormat::MPC) => SongTags::read_ape(path),
|
||||||
Some(AudioFormat::OGG) => SongTags::read_vorbis(path),
|
Some(AudioFormat::OGG) => SongTags::read_vorbis(path),
|
||||||
|
@ -31,7 +33,7 @@ impl SongTags {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_id3(path: &Path) -> Result<SongTags, PError> {
|
fn read_id3(path: &Path) -> Result<SongTags, PError> {
|
||||||
let tag = try!(Tag::read_from_path(path));
|
let tag = try!(id3::Tag::read_from_path(path));
|
||||||
|
|
||||||
let artist = tag.artist().map(|s| s.to_string());
|
let artist = tag.artist().map(|s| s.to_string());
|
||||||
let album_artist = tag.album_artist().map(|s| s.to_string());
|
let album_artist = tag.album_artist().map(|s| s.to_string());
|
||||||
|
@ -133,4 +135,20 @@ impl SongTags {
|
||||||
|
|
||||||
Ok(tags)
|
Ok(tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_flac(path: &Path) -> Result<SongTags, PError> {
|
||||||
|
let tag = try!(metaflac::Tag::read_from_path(path));
|
||||||
|
let vorbis = try!(tag.vorbis_comments().ok_or(PError::MetadataDecodingError));
|
||||||
|
let disc_number = vorbis.get("DISCNUMBER").and_then(|d| d[0].parse::<u32>().ok());
|
||||||
|
let year = vorbis.get("DATE").and_then(|d| d[0].parse::<i32>().ok());
|
||||||
|
Ok(SongTags {
|
||||||
|
artist: vorbis.artist().map(|v| v[0].clone()),
|
||||||
|
album_artist: vorbis.album_artist().map(|v| v[0].clone()),
|
||||||
|
album: vorbis.album().map(|v| v[0].clone()),
|
||||||
|
title: vorbis.title().map(|v| v[0].clone()),
|
||||||
|
disc_number: disc_number,
|
||||||
|
track_number: vorbis.track(),
|
||||||
|
year: year,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue