mirror of
https://github.com/agersant/polaris
synced 2024-11-10 10:14:12 +00:00
Added data structures for artist/album info
This commit is contained in:
parent
bc2ea2b64f
commit
f62113b83c
2 changed files with 55 additions and 27 deletions
|
@ -10,9 +10,9 @@ version = "0.4.0"
|
||||||
git = "https://github.com/servo/rust-url"
|
git = "https://github.com/servo/rust-url"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-serialize = "0.3"
|
|
||||||
router = "*"
|
|
||||||
mount = "*"
|
mount = "*"
|
||||||
staticfile = "*"
|
|
||||||
regex = "0.1"
|
regex = "0.1"
|
||||||
|
router = "*"
|
||||||
|
rustc-serialize = "0.3"
|
||||||
|
staticfile = "*"
|
||||||
toml = "0.2"
|
toml = "0.2"
|
|
@ -9,11 +9,45 @@ use toml;
|
||||||
use vfs::*;
|
use vfs::*;
|
||||||
use error::*;
|
use error::*;
|
||||||
|
|
||||||
|
#[derive(Debug, RustcEncodable)]
|
||||||
|
pub struct Album {
|
||||||
|
name: Option<String>,
|
||||||
|
year: Option<String>,
|
||||||
|
album_art: Option<String>,
|
||||||
|
artist: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Album {
|
||||||
|
fn read(collection: &Collection, path: &Path) -> Result<Option<Album>, PError> {
|
||||||
|
let name = None;
|
||||||
|
let year = None;
|
||||||
|
let artist = None;
|
||||||
|
|
||||||
|
let album_art = collection.get_album_art(path).unwrap_or(None);
|
||||||
|
let album_art = match album_art {
|
||||||
|
Some(p) => Some(try!(collection.vfs.real_to_virtual(p.as_path()))),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
let album_art = match album_art {
|
||||||
|
None => None,
|
||||||
|
Some(a) => a.to_str().map(|p| p.to_string()),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Some(Album {
|
||||||
|
name: name,
|
||||||
|
year: year,
|
||||||
|
album_art: album_art,
|
||||||
|
artist: artist,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, RustcEncodable)]
|
#[derive(Debug, RustcEncodable)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
path: String,
|
path: String,
|
||||||
display_name: String,
|
album: Album,
|
||||||
album_art: String,
|
title: Option<String>,
|
||||||
|
artist: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Song {
|
impl Song {
|
||||||
|
@ -21,20 +55,18 @@ impl Song {
|
||||||
let virtual_path = try!(collection.vfs.real_to_virtual(path));
|
let virtual_path = try!(collection.vfs.real_to_virtual(path));
|
||||||
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
|
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
|
||||||
|
|
||||||
let display_name = virtual_path.file_stem().unwrap();
|
let name = virtual_path.file_stem().unwrap();
|
||||||
let display_name = display_name.to_str().unwrap();
|
let name = name.to_str().unwrap();
|
||||||
let display_name = display_name.to_string();
|
let name = name.to_string();
|
||||||
|
|
||||||
let album_art = match collection.get_album_art(path) {
|
let album = try!(Album::read(collection, path));
|
||||||
Ok(Some(p)) => try!(collection.vfs.real_to_virtual(p.as_path())),
|
let album = album.unwrap();
|
||||||
_ => PathBuf::new(),
|
|
||||||
};
|
|
||||||
let album_art = try!(album_art.to_str().ok_or(PError::PathDecoding));
|
|
||||||
|
|
||||||
Ok(Song {
|
Ok(Song {
|
||||||
path: path_string.to_string(),
|
path: path_string.to_string(),
|
||||||
display_name: display_name,
|
album: album,
|
||||||
album_art: album_art.to_string(),
|
artist: None,
|
||||||
|
title: Some(name),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +92,8 @@ impl Song {
|
||||||
#[derive(Debug, RustcEncodable)]
|
#[derive(Debug, RustcEncodable)]
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
path: String,
|
path: String,
|
||||||
display_name: String,
|
name: String,
|
||||||
album_art: String,
|
album: Option<Album>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Directory {
|
impl Directory {
|
||||||
|
@ -69,20 +101,16 @@ impl Directory {
|
||||||
let virtual_path = try!(collection.vfs.real_to_virtual(path));
|
let virtual_path = try!(collection.vfs.real_to_virtual(path));
|
||||||
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
|
let path_string = try!(virtual_path.to_str().ok_or(PError::PathDecoding));
|
||||||
|
|
||||||
let display_name = virtual_path.iter().last().unwrap();
|
let name = virtual_path.iter().last().unwrap();
|
||||||
let display_name = display_name.to_str().unwrap();
|
let name = name.to_str().unwrap();
|
||||||
let display_name = display_name.to_string();
|
let name = name.to_string();
|
||||||
|
|
||||||
let album_art = match collection.get_album_art(path) {
|
let album = try!(Album::read(collection, path));
|
||||||
Ok(Some(p)) => try!(collection.vfs.real_to_virtual(p.as_path())),
|
|
||||||
_ => PathBuf::new(),
|
|
||||||
};
|
|
||||||
let album_art = try!(album_art.to_str().ok_or(PError::PathDecoding));
|
|
||||||
|
|
||||||
Ok(Directory {
|
Ok(Directory {
|
||||||
path: path_string.to_string(),
|
path: path_string.to_string(),
|
||||||
display_name: display_name,
|
name: name,
|
||||||
album_art: album_art.to_string(),
|
album: album,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue