use error::*;
use std::collections::hash_map::*;
use std::str;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum StreamKey { LD, SD, HD }
impl str::FromStr for StreamKey {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"small" => Ok(StreamKey::LD),
"sd_src" | "medium" => Ok(StreamKey::SD),
"hd_src" | "hd720" | "large" => Ok(StreamKey::HD),
_ => Err(Error::video("Invalid stream key")),
}
}
}
pub struct Video {
identifier: String,
streams: HashMap<StreamKey, String>
}
impl Video {
pub fn new<T: Into<String>>(identifier: T, streams: HashMap<StreamKey, String>) -> Video {
Video {
identifier: identifier.into(),
streams
}
}
pub fn identifier(&self) -> &str {
&self.identifier
}
pub fn get_stream(&self, key: StreamKey) -> Option<&str> {
self.streams.get(&key).map(|s| s.as_ref())
}
pub fn best_stream(&self) -> Option<&str> {
unimplemented!()
}
pub fn streams(&self) -> Iter<StreamKey, String> {
self.streams.iter()
}
}