Last active
June 14, 2016 15:01
-
-
Save mmstick/1d249f12555dd33df38f37da744c249b to your computer and use it in GitHub Desktop.
Obtains a list of all videos in a given directory path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Collects a list of all of the episodes in a given directory. Files that are not videos are ignored. | |
pub fn get_episodes(directory: &str) -> Result<Vec<PathBuf>, &str> { | |
fs::read_dir(directory).ok().map_or(Err("tv-renamer: unable to read file"), |files| { | |
let video_extensions = try!(mimetypes::get_video_extensions()); | |
let mut episodes = Vec::new(); | |
for entry in files { | |
let status = entry.ok().map_or(Some("tv-renamer: unable to get file entry"), |entry| { | |
entry.metadata().ok().map_or(Some("tv-renamer: unable to get metadata"), |metadata| { | |
if metadata.is_file() { | |
for extension in &video_extensions { | |
if extension.as_str() == entry.path().extension().unwrap().to_str().unwrap() { | |
episodes.push(entry.path()); | |
} | |
} | |
} | |
None | |
}) | |
}); | |
if status.is_some() { return Err(status.unwrap()); } | |
} | |
episodes.sort_by(|a, b| a.to_string_lossy().to_lowercase().cmp(&b.to_string_lossy().to_lowercase())); | |
Ok(episodes) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment