From a683398ea269344f8c75261f7d136bd6c1f177b6 Mon Sep 17 00:00:00 2001 From: Ashhhleyyy Date: Sat, 20 Jan 2024 13:56:00 +0000 Subject: [PATCH] chore: cargo fmt --- src/nfo.rs | 8 ++++-- src/walker.rs | 67 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/nfo.rs b/src/nfo.rs index 0b4b531..abdb01c 100644 --- a/src/nfo.rs +++ b/src/nfo.rs @@ -172,7 +172,10 @@ pub struct SubtitleTrack { impl SubtitleTrack { pub fn from_nfo(subtitle: Subtitle, video_url: &str) -> Self { Self { - url: video_url.replace(".mp4", &format!(".{}.{}", subtitle.language, subtitle.ext().unwrap())), + url: video_url.replace( + ".mp4", + &format!(".{}.{}", subtitle.language, subtitle.ext().unwrap()), + ), label: Self::label_from_lang(&subtitle.language).to_string(), lang: subtitle.language, } @@ -184,6 +187,7 @@ impl SubtitleTrack { "eng" => "English", "spa" => "Spanish", lang => lang, - }.to_string() + } + .to_string() } } diff --git a/src/walker.rs b/src/walker.rs index 62bed6a..2017977 100644 --- a/src/walker.rs +++ b/src/walker.rs @@ -1,18 +1,28 @@ -use std::{path::{Path, PathBuf}, fs::File, collections::HashMap}; +use std::{ + collections::HashMap, + fs::File, + path::{Path, PathBuf}, +}; -use color_eyre::{Result, eyre::eyre}; +use color_eyre::{eyre::eyre, Result}; -use crate::{nfo::{ContentType, ItemMeta, ItemData, SubtitleTrack}, Args, templates, util::get_url, PlayerKind}; +use crate::{ + nfo::{ContentType, ItemData, ItemMeta, SubtitleTrack}, + templates, + util::get_url, + Args, PlayerKind, +}; pub fn walk_metadata(args: &Args) -> Result<()> { let mut path_cache = HashMap::::new(); - let walk = walkdir::WalkDir::new(&args.dir) - .contents_first(true); + let walk = walkdir::WalkDir::new(&args.dir).contents_first(true); for entry in walk { let entry = entry?; - if !entry.file_type().is_dir() { continue; } + if !entry.file_type().is_dir() { + continue; + } let path = entry.path(); let read = std::fs::read_dir(path)?; let mut entries = Vec::with_capacity(read.size_hint().0); @@ -31,19 +41,28 @@ pub fn walk_metadata(args: &Args) -> Result<()> { let children = find_tv_show_children(&path_cache, &entries); let rendered = templates::tv_show(&info, args, &children)?; std::fs::write(output_path, rendered.0)?; - }, + } ContentType::Season => { - let mut children = find_season_children(&path_cache, &entries, &info.data, args)?; + let mut children = + find_season_children(&path_cache, &entries, &info.data, args)?; for child in &mut children { - let aspect = child.data.file_info.stream_details.video.aspect_ratio.replace(':', "/"); + let aspect = child + .data + .file_info + .stream_details + .video + .aspect_ratio + .replace(':', "/"); let rendered = match args.player { PlayerKind::Vidstack => templates::vidstack_player( &child.data.title, &child.url, &aspect, child.data.art.poster.as_ref().unwrap(), - &if let Some(subtitle) = &child.data.file_info.stream_details.subtitle { + &if let Some(subtitle) = + &child.data.file_info.stream_details.subtitle + { vec![SubtitleTrack::from_nfo(subtitle.clone(), &child.url)] } else { vec![] @@ -55,7 +74,9 @@ pub fn walk_metadata(args: &Args) -> Result<()> { &child.url, &aspect, child.data.art.poster.as_ref().unwrap(), - &if let Some(subtitle) = &child.data.file_info.stream_details.subtitle { + &if let Some(subtitle) = + &child.data.file_info.stream_details.subtitle + { vec![SubtitleTrack::from_nfo(subtitle.clone(), &child.url)] } else { vec![] @@ -70,7 +91,7 @@ pub fn walk_metadata(args: &Args) -> Result<()> { let rendered = templates::tv_show(&info, args, &children)?; std::fs::write(output_path, rendered.0)?; - }, + } ContentType::Episode => unreachable!(), } println!("{path:?}: {:?}", info.ty); @@ -83,7 +104,10 @@ pub fn walk_metadata(args: &Args) -> Result<()> { Ok(()) } -fn find_tv_show_children(path_cache: &HashMap, entries: &[PathBuf]) -> Vec { +fn find_tv_show_children( + path_cache: &HashMap, + entries: &[PathBuf], +) -> Vec { let mut children = vec![]; for entry in entries { if let Some(info) = path_cache.get(entry) { @@ -96,7 +120,12 @@ fn find_tv_show_children(path_cache: &HashMap, entries: &[Pat children } -fn find_season_children(_path_cache: &HashMap, entries: &[PathBuf], parent: &ItemData, args: &Args) -> Result> { +fn find_season_children( + _path_cache: &HashMap, + entries: &[PathBuf], + parent: &ItemData, + args: &Args, +) -> Result> { let mut children = vec![]; for entry in entries { if let (Some(stem), Some(ext)) = (entry.file_stem(), entry.extension()) { @@ -104,7 +133,12 @@ fn find_season_children(_path_cache: &HashMap, entries: &[Pat if stem.contains("Episode") && ext == "nfo" { let data = read_data(entry)?; let video = entry.with_extension("mp4"); - let url = get_url(&video.to_string_lossy().replace("/stuff/ash/Series", "/media/Shows"), args)?; + let url = get_url( + &video + .to_string_lossy() + .replace("/stuff/ash/Series", "/media/Shows"), + args, + )?; children.push(ItemMeta { url, ty: ContentType::Episode, @@ -121,7 +155,8 @@ fn find_season_children(_path_cache: &HashMap, entries: &[Pat fn read_data(path: &Path) -> Result { let mut f = File::open(path)?; - let data: ItemData = yaserde::de::from_reader(&mut f).map_err(|e| eyre!("failed to parse directory meta: {e}"))?; + let data: ItemData = yaserde::de::from_reader(&mut f) + .map_err(|e| eyre!("failed to parse directory meta: {e}"))?; Ok(data) }