Refacto get_root_folder_read_library_items.
This commit is contained in:
@@ -6,6 +6,8 @@ use uuid::Uuid;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::DirEntry;
|
||||
use lumiere_domain::video::model::video::VideoFormat::{AVI, MKV, MP4, WEBM};
|
||||
use crate::video::video_format_detector::get_content_type;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct VideoAdapter {
|
||||
@@ -24,13 +26,21 @@ impl VideoAdapter {
|
||||
.map_err(|_| VideoError::FolderBrowsingTechnicalIssue)?;
|
||||
|
||||
root_folder_files.into_iter()
|
||||
.map(|file_entry|
|
||||
file_entry.map_err(|_| VideoError::FolderBrowsingTechnicalIssue)
|
||||
.and_then(Self::map_file_into_library_raw_item)
|
||||
)
|
||||
.flat_map(Result::ok)
|
||||
.filter(Self::file_is_video_or_folder)
|
||||
.map(Self::map_file_into_library_raw_item)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn file_is_video_or_folder(file_entry: &DirEntry) -> bool {
|
||||
if file_entry.path().is_dir() {
|
||||
true
|
||||
} else {
|
||||
let content_type = get_content_type(&file_entry.path());
|
||||
matches!(content_type, AVI | MKV | MP4 | WEBM)
|
||||
}
|
||||
}
|
||||
|
||||
fn map_file_into_library_raw_item(file: DirEntry) -> Result<LibraryRawItem, VideoError> {
|
||||
let item_type = if file.path().is_dir() {
|
||||
LibraryItemType::FOLDER
|
||||
|
||||
Reference in New Issue
Block a user