chore: cargo fmt
This commit is contained in:
parent
9f1e46dbee
commit
a683398ea2
2 changed files with 57 additions and 18 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<PathBuf, ItemMeta>::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<PathBuf, ItemMeta>, entries: &[PathBuf]) -> Vec<ItemMeta> {
|
||||
fn find_tv_show_children(
|
||||
path_cache: &HashMap<PathBuf, ItemMeta>,
|
||||
entries: &[PathBuf],
|
||||
) -> Vec<ItemMeta> {
|
||||
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<PathBuf, ItemMeta>, entries: &[Pat
|
|||
children
|
||||
}
|
||||
|
||||
fn find_season_children(_path_cache: &HashMap<PathBuf, ItemMeta>, entries: &[PathBuf], parent: &ItemData, args: &Args) -> Result<Vec<ItemMeta>> {
|
||||
fn find_season_children(
|
||||
_path_cache: &HashMap<PathBuf, ItemMeta>,
|
||||
entries: &[PathBuf],
|
||||
parent: &ItemData,
|
||||
args: &Args,
|
||||
) -> Result<Vec<ItemMeta>> {
|
||||
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<PathBuf, ItemMeta>, 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<PathBuf, ItemMeta>, entries: &[Pat
|
|||
|
||||
fn read_data(path: &Path) -> Result<ItemData> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue