Cleanup lint.
This commit is contained in:
parent
8b809060ec
commit
6f579326b5
48
src/lib.rs
48
src/lib.rs
@ -123,30 +123,12 @@ enum Stream {
|
|||||||
Data {},
|
Data {},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stream {
|
|
||||||
pub fn dimension(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Debug, Serialize)]
|
#[derive(Clone, Deserialize, Debug, Serialize)]
|
||||||
struct Metadata {
|
struct Metadata {
|
||||||
format: Format,
|
format: Format,
|
||||||
streams: Vec<Stream>,
|
streams: Vec<Stream>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Metadata {
|
|
||||||
pub fn dimension(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
pub fn duration(&self) -> f32 {
|
|
||||||
self.format.duration
|
|
||||||
}
|
|
||||||
pub fn size(&self) -> usize {
|
|
||||||
self.format.size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Debug, Serialize)]
|
#[derive(Clone, Deserialize, Debug, Serialize)]
|
||||||
pub struct VideoFormat {
|
pub struct VideoFormat {
|
||||||
short_name: String,
|
short_name: String,
|
||||||
@ -198,6 +180,7 @@ pub struct SubtitleFormat {
|
|||||||
#[derive(Clone, Deserialize, Debug, Serialize)]
|
#[derive(Clone, Deserialize, Debug, Serialize)]
|
||||||
pub struct CompactMetadata {
|
pub struct CompactMetadata {
|
||||||
bit_rate: usize,
|
bit_rate: usize,
|
||||||
|
// TODO(wathiede): make this a custom Duration type that pretty prints H:M:S
|
||||||
pub duration: f32,
|
pub duration: f32,
|
||||||
filename: String,
|
filename: String,
|
||||||
format_name: String,
|
format_name: String,
|
||||||
@ -470,7 +453,10 @@ impl MovieLibrary {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn videos(&self, include_stale: bool) -> Result<(HashMap<String, CompactMetadata>), Error> {
|
pub fn videos(
|
||||||
|
&self,
|
||||||
|
_include_stale: bool,
|
||||||
|
) -> Result<(HashMap<String, CompactMetadata>), Error> {
|
||||||
// TODO(wathiede): implement include_stale.
|
// TODO(wathiede): implement include_stale.
|
||||||
let path = Path::new(&self.root).join(COMPACT_METADATA_FILENAME);
|
let path = Path::new(&self.root).join(COMPACT_METADATA_FILENAME);
|
||||||
// Open the file in read-only mode with buffer.
|
// Open the file in read-only mode with buffer.
|
||||||
@ -483,24 +469,11 @@ impl MovieLibrary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_metadata_from_file<P: AsRef<Path>>(path: P) -> Result<MetadataFile, Error> {
|
|
||||||
let path = path.as_ref();
|
|
||||||
// Open the file in read-only mode with buffer.
|
|
||||||
let f = File::open(path).context(format!("open {}", path.display()))?;
|
|
||||||
let r = BufReader::new(f);
|
|
||||||
|
|
||||||
// Read the JSON contents of the file as an instance of `User`.
|
|
||||||
let md = serde_json::from_reader(r)
|
|
||||||
.context(format!("serde_json::from_reader {}", path.display()))?;
|
|
||||||
|
|
||||||
// Return the `User`.
|
|
||||||
Ok(md)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn testdata_dir() -> String {
|
fn testdata_dir() -> String {
|
||||||
format!("{}/testdata", env::var("CARGO_MANIFEST_DIR").unwrap())
|
format!("{}/testdata", env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||||
}
|
}
|
||||||
@ -547,15 +520,6 @@ mod tests {
|
|||||||
assert_eq!(md.largest_dimension(), Some(Resolution(640, 480)));
|
assert_eq!(md.largest_dimension(), Some(Resolution(640, 480)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_read_full_metadata() {
|
|
||||||
let mdf = read_metadata_from_file(
|
|
||||||
Path::new(&testdata_dir()).join(&format!("Movies/{}", FULL_METADATA_FILENAME)),
|
|
||||||
)
|
|
||||||
.expect("failed to read metadata");
|
|
||||||
assert_eq!(mdf.metadata.len(), 1214);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#[test]
|
#[test]
|
||||||
fn test_movies() {
|
fn test_movies() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user