You've already forked flix
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
b6ad592951
|
@@ -1,18 +1,10 @@
|
|||||||
{
|
{
|
||||||
"project_name": null,
|
|
||||||
|
|
||||||
"auto_install_extensions": {
|
|
||||||
"tombi": true,
|
|
||||||
"cargo-appraiser": true,
|
|
||||||
},
|
|
||||||
|
|
||||||
"languages": {
|
"languages": {
|
||||||
"TOML": {
|
"TOML": {
|
||||||
"format_on_save": "on",
|
"format_on_save": "on",
|
||||||
"formatter": { "language_server": { "name": "tombi" } },
|
"formatter": { "language_server": { "name": "tombi" } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"lsp": {
|
"lsp": {
|
||||||
"rust-analyzer": {
|
"rust-analyzer": {
|
||||||
"initialization_options": {
|
"initialization_options": {
|
||||||
|
|||||||
Generated
+229
-245
File diff suppressed because it is too large
Load Diff
+12
-7
@@ -9,14 +9,15 @@ edition = "2024"
|
|||||||
rust-version = "1.89.0"
|
rust-version = "1.89.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
flix = { path = "crates/flix", version = "=0.0.18", default-features = false }
|
flix = { path = "crates/flix", version = "=0.0.19", default-features = false }
|
||||||
flix-cli = { path = "crates/cli", version = "=0.0.18", default-features = false }
|
flix-cli = { path = "crates/cli", version = "=0.0.19", default-features = false }
|
||||||
flix-db = { path = "crates/db", version = "=0.0.18", default-features = false }
|
flix-db = { path = "crates/db", version = "=0.0.19", default-features = false }
|
||||||
flix-fs = { path = "crates/fs", version = "=0.0.18", default-features = false }
|
flix-fs = { path = "crates/fs", version = "=0.0.19", default-features = false }
|
||||||
flix-model = { path = "crates/model", version = "=0.0.18", default-features = false }
|
flix-model = { path = "crates/model", version = "=0.0.19", default-features = false }
|
||||||
flix-tmdb = { path = "crates/tmdb", version = "=0.0.18", default-features = false }
|
flix-mux = { path = "crates/cli-mux", version = "=0.0.19", default-features = false }
|
||||||
|
flix-tmdb = { path = "crates/tmdb", version = "=0.0.19", default-features = false }
|
||||||
|
|
||||||
seamantic = { version = "^0.0.13", default-features = false }
|
seamantic = { version = "^0.0.14", default-features = false }
|
||||||
|
|
||||||
sea-orm = { version = "=2.0.0-rc.38", default-features = false }
|
sea-orm = { version = "=2.0.0-rc.38", default-features = false }
|
||||||
sea-orm-migration = { version = "=2.0.0-rc.38", default-features = false }
|
sea-orm-migration = { version = "=2.0.0-rc.38", default-features = false }
|
||||||
@@ -26,9 +27,12 @@ async-stream = { version = "^0.3", default-features = false }
|
|||||||
bytes = { version = "^1", default-features = false }
|
bytes = { version = "^1", default-features = false }
|
||||||
chrono = { version = "^0.4", default-features = false }
|
chrono = { version = "^0.4", default-features = false }
|
||||||
clap = { version = "^4", default-features = false }
|
clap = { version = "^4", default-features = false }
|
||||||
|
console = { version = "^0.16", default-features = false }
|
||||||
|
dialoguer = { version = "^0.12", default-features = false }
|
||||||
either = { version = "^1", default-features = false }
|
either = { version = "^1", default-features = false }
|
||||||
futures = { version = "^0.3", default-features = false }
|
futures = { version = "^0.3", default-features = false }
|
||||||
governor = { version = "^0.10", default-features = false }
|
governor = { version = "^0.10", default-features = false }
|
||||||
|
indicatif = { version = "^0.18", default-features = false }
|
||||||
itertools = { version = "^0.14", default-features = false }
|
itertools = { version = "^0.14", default-features = false }
|
||||||
nonzero_ext = { version = "^0.3", default-features = false }
|
nonzero_ext = { version = "^0.3", default-features = false }
|
||||||
redb = { version = "^4", default-features = false }
|
redb = { version = "^4", default-features = false }
|
||||||
@@ -45,6 +49,7 @@ tracing = { version = "^0.1", default-features = false }
|
|||||||
tracing-subscriber = { version = "^0.3", default-features = false }
|
tracing-subscriber = { version = "^0.3", default-features = false }
|
||||||
url = { version = "^2", default-features = false }
|
url = { version = "^2", default-features = false }
|
||||||
url-macro = { version = "^0.2", default-features = false }
|
url-macro = { version = "^0.2", default-features = false }
|
||||||
|
walkdir = { version = "^2", default-features = false }
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
arithmetic_side_effects = "forbid"
|
arithmetic_side_effects = "forbid"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Libraries and tools for dealing with media metadata
|
|||||||
- fmt: `cargo fmt --check`
|
- fmt: `cargo fmt --check`
|
||||||
- docs: `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features`
|
- docs: `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features`
|
||||||
- install: `cargo install --path crates/cli`
|
- install: `cargo install --path crates/cli`
|
||||||
|
- install: `cargo install --path crates/cli-mux`
|
||||||
- semver: `cargo semver-checks --all-features`
|
- semver: `cargo semver-checks --all-features`
|
||||||
- publish: `cargo publish --dry-run --workspace`
|
- publish: `cargo publish --dry-run --workspace`
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
[package]
|
||||||
|
name = "flix-mux"
|
||||||
|
version = "0.0.19"
|
||||||
|
license-file.workspace = true
|
||||||
|
|
||||||
|
description = "CLI for bulk media muxing"
|
||||||
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
categories = ["command-line-utilities"]
|
||||||
|
|
||||||
|
edition.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
doc = false
|
||||||
|
name = "flix-mux"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
clap = { workspace = true, features = [
|
||||||
|
"color",
|
||||||
|
"derive",
|
||||||
|
"error-context",
|
||||||
|
"help",
|
||||||
|
"std",
|
||||||
|
"suggestions",
|
||||||
|
"usage",
|
||||||
|
] }
|
||||||
|
console = { workspace = true }
|
||||||
|
dialoguer = { workspace = true }
|
||||||
|
indicatif = { workspace = true }
|
||||||
|
serde = { workspace = true, features = ["derive", "std"] }
|
||||||
|
serde_json = { workspace = true, features = ["alloc"] }
|
||||||
|
walkdir = { workspace = true }
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
arithmetic_side_effects = "deny"
|
||||||
|
as_conversions = "deny"
|
||||||
|
checked_conversions = "deny"
|
||||||
|
default_union_representation = "deny"
|
||||||
|
expect_used = "deny"
|
||||||
|
indexing_slicing = "deny"
|
||||||
|
integer_division = "deny"
|
||||||
|
integer_division_remainder_used = "deny"
|
||||||
|
transmute_undefined_repr = "deny"
|
||||||
|
unchecked_time_subtraction = "deny"
|
||||||
|
unwrap_used = "deny"
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
arithmetic_overflow = "forbid"
|
||||||
|
missing_docs = "forbid"
|
||||||
|
unsafe_code = "forbid"
|
||||||
|
unused_doc_comments = "forbid"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# flix-mux
|
||||||
|
|
||||||
|
[](https://crates.io/crates/flix-mux)
|
||||||
|
|
||||||
|
CLI for bulk media muxing
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo run -- <DIR>
|
||||||
|
```
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::parser::Selector;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(version, about, long_about = None)]
|
||||||
|
pub struct Cli {
|
||||||
|
/// Dry run and print commands
|
||||||
|
#[arg(short, long)]
|
||||||
|
dry_run: bool,
|
||||||
|
|
||||||
|
/// Stream selectors
|
||||||
|
#[arg(
|
||||||
|
short,
|
||||||
|
long,
|
||||||
|
required = true,
|
||||||
|
value_name = "SEL",
|
||||||
|
value_delimiter = ';'
|
||||||
|
)]
|
||||||
|
selectors: Vec<Selector>,
|
||||||
|
|
||||||
|
/// The path to the directory to scan
|
||||||
|
#[arg(value_name = "DIR")]
|
||||||
|
scan_dir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cli {
|
||||||
|
pub fn is_dry(&self) -> bool {
|
||||||
|
self.dry_run
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn selectors(&self) -> &[Selector] {
|
||||||
|
&self.selectors
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scan_dir_path(&self) -> PathBuf {
|
||||||
|
fn expect_home_dir() -> PathBuf {
|
||||||
|
#[allow(clippy::expect_used)]
|
||||||
|
std::env::home_dir().expect("you do not have a home directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.scan_dir.strip_prefix("~/") {
|
||||||
|
Ok(path) => expect_home_dir().join(path),
|
||||||
|
Err(_) => self.scan_dir.to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
//! flix-mux
|
||||||
|
|
||||||
|
use core::time::Duration;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use console::style;
|
||||||
|
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
|
||||||
|
|
||||||
|
use crate::mux::mux_files;
|
||||||
|
use crate::scan::scan_directory;
|
||||||
|
|
||||||
|
mod cli;
|
||||||
|
mod model;
|
||||||
|
mod mux;
|
||||||
|
mod parser;
|
||||||
|
mod probe;
|
||||||
|
mod scan;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let cli = cli::Cli::parse();
|
||||||
|
|
||||||
|
let (files, size) = scan_directory(
|
||||||
|
&cli.scan_dir_path(),
|
||||||
|
|| {
|
||||||
|
let progress = ProgressBar::new_spinner();
|
||||||
|
progress.set_message(format!("Scanning {:?}", &cli.scan_dir_path()));
|
||||||
|
progress.enable_steady_tick(Duration::from_millis(50));
|
||||||
|
progress
|
||||||
|
},
|
||||||
|
|progress| progress.finish(),
|
||||||
|
|len| {
|
||||||
|
let progress = ProgressBar::new(u64::try_from(len).unwrap_or(0));
|
||||||
|
progress.set_style(
|
||||||
|
#[expect(clippy::expect_used)]
|
||||||
|
ProgressStyle::with_template("[{elapsed_precise}] {wide_bar} {pos}/{len} ({msg})")
|
||||||
|
.expect("static template"),
|
||||||
|
);
|
||||||
|
progress
|
||||||
|
},
|
||||||
|
|progress| progress.inc(1),
|
||||||
|
|progress| progress.finish_and_clear(),
|
||||||
|
|progress, msg| {
|
||||||
|
progress.suspend(|| eprintln!("{} {}", style("[WARN]").bold().yellow(), msg))
|
||||||
|
},
|
||||||
|
);
|
||||||
|
println!("Found {} files ({})", files.len(), HumanBytes(size));
|
||||||
|
|
||||||
|
mux_files(
|
||||||
|
cli.is_dry(),
|
||||||
|
&files,
|
||||||
|
cli.selectors(),
|
||||||
|
|len| {
|
||||||
|
let progress = ProgressBar::new(u64::try_from(len).unwrap_or(0));
|
||||||
|
progress.set_style(
|
||||||
|
#[expect(clippy::expect_used)]
|
||||||
|
ProgressStyle::with_template("[{elapsed_precise}] {wide_bar} {pos}/{len} ({msg})")
|
||||||
|
.expect("static template"),
|
||||||
|
);
|
||||||
|
progress.enable_steady_tick(Duration::from_secs(1));
|
||||||
|
progress
|
||||||
|
},
|
||||||
|
|progress| progress.inc(1),
|
||||||
|
|progress| progress.finish_with_message("done"),
|
||||||
|
|progress, msg| progress.suspend(|| eprintln!("{} {}", style("[ERR]").bold().red(), msg)),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct MediaFile {
|
||||||
|
pub path: PathBuf,
|
||||||
|
pub byte_size: u64,
|
||||||
|
pub streams: Streams,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Streams {
|
||||||
|
pub video: Vec<VideoStream>,
|
||||||
|
pub audio: Vec<AudioStream>,
|
||||||
|
pub subtitle: Vec<SubtitleStream>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FFStream: serde::de::DeserializeOwned {
|
||||||
|
const FF_TYPE_NAME: &str;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct VideoStream {
|
||||||
|
codec_name: String,
|
||||||
|
tags: Option<VideoTags>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct VideoTags {
|
||||||
|
language: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VideoStream {
|
||||||
|
pub fn codec(&self) -> &str {
|
||||||
|
&self.codec_name
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn language(&self) -> Option<&str> {
|
||||||
|
self.tags.as_ref()?.language.as_deref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FFStream for VideoStream {
|
||||||
|
const FF_TYPE_NAME: &str = "v";
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct AudioStream {
|
||||||
|
codec_name: String,
|
||||||
|
tags: Option<AudioTags>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct AudioTags {
|
||||||
|
language: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AudioStream {
|
||||||
|
pub fn codec(&self) -> &str {
|
||||||
|
&self.codec_name
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn language(&self) -> Option<&str> {
|
||||||
|
self.tags.as_ref()?.language.as_deref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FFStream for AudioStream {
|
||||||
|
const FF_TYPE_NAME: &str = "a";
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct SubtitleStream {
|
||||||
|
codec_name: String,
|
||||||
|
tags: Option<SubtitleTags>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct SubtitleTags {
|
||||||
|
language: Option<String>,
|
||||||
|
title: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SubtitleStream {
|
||||||
|
pub fn codec(&self) -> &str {
|
||||||
|
&self.codec_name
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn language(&self) -> Option<&str> {
|
||||||
|
self.tags.as_ref()?.language.as_deref()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn title(&self) -> Option<&str> {
|
||||||
|
self.tags.as_ref()?.title.as_deref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FFStream for SubtitleStream {
|
||||||
|
const FF_TYPE_NAME: &str = "s";
|
||||||
|
}
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
use anyhow::{Context as _, Result};
|
||||||
|
|
||||||
|
use crate::model::MediaFile;
|
||||||
|
use crate::parser::{Matcher, Selector, StreamFlag, StreamType};
|
||||||
|
|
||||||
|
pub fn mux_files<T>(
|
||||||
|
dry_run: bool,
|
||||||
|
files: &[MediaFile],
|
||||||
|
selectors: &[Selector],
|
||||||
|
fixed_length_start: impl FnOnce(usize) -> T,
|
||||||
|
fixed_length_update: impl Fn(&mut T),
|
||||||
|
fixed_length_end: impl FnOnce(T),
|
||||||
|
print_fn: impl Fn(&T, &str),
|
||||||
|
) {
|
||||||
|
let mut progress = fixed_length_start(files.len());
|
||||||
|
for file in files {
|
||||||
|
if let Err(err) = mux(dry_run, file, selectors) {
|
||||||
|
print_fn(&progress, &format!("{:?}", err));
|
||||||
|
}
|
||||||
|
fixed_length_update(&mut progress);
|
||||||
|
}
|
||||||
|
fixed_length_end(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[expect(clippy::expect_used)]
|
||||||
|
fn mux(dry_run: bool, file: &MediaFile, selectors: &[Selector]) -> Result<()> {
|
||||||
|
let mut command = Command::new("ffmpeg");
|
||||||
|
let mut command = command.args(["-v", "error"]);
|
||||||
|
|
||||||
|
command = command.arg("-i");
|
||||||
|
command = command.arg(file.path.as_os_str());
|
||||||
|
|
||||||
|
for selector in selectors {
|
||||||
|
command = command.args(
|
||||||
|
make_map_args(file, selector)
|
||||||
|
.with_context(|| format!("Failed to mux {:?}", file.path))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
command = command.args(["-c:v", "copy", "-c:a", "copy", "-c:s", "mov_text"]);
|
||||||
|
command = command.args(["-movflags", "faststart+disable_chpl+write_colr"]);
|
||||||
|
command = command.args(["-map_chapters", "-1"]);
|
||||||
|
command = command.args(["-map_metadata", "-1"]);
|
||||||
|
command = command.args(["-metadata:g", "encoding_tool=Skrundzflix"]);
|
||||||
|
|
||||||
|
for selector in selectors {
|
||||||
|
command = command.args(
|
||||||
|
make_metadata_args(file, selector)
|
||||||
|
.with_context(|| format!("Failed to mux {:?}", file.path))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let temp_path = file.path.with_extension("mp4");
|
||||||
|
command = command.arg(temp_path.file_name().expect("file name exists"));
|
||||||
|
|
||||||
|
if dry_run {
|
||||||
|
print_command(command);
|
||||||
|
} else {
|
||||||
|
let output = command
|
||||||
|
.output()
|
||||||
|
.with_context(|| format!("Failed to mux {:?}", file.path))?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"ffmpeg failed for {:?}:\n\n{}",
|
||||||
|
file.path,
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_map_args(file: &MediaFile, selector: &Selector) -> Result<Vec<String>> {
|
||||||
|
let source_index = 0;
|
||||||
|
let stream_type = selector.stream_type.as_ref();
|
||||||
|
let Some(stream_index) = find_stream_index(file, selector) else {
|
||||||
|
if selector.optional {
|
||||||
|
return Ok(vec![]);
|
||||||
|
} else {
|
||||||
|
anyhow::bail!("unsatisfied stream selection");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(vec![
|
||||||
|
String::from("-map"),
|
||||||
|
format!("{}:{}:{}", source_index, stream_type, stream_index),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_metadata_args(file: &MediaFile, selector: &Selector) -> Result<Vec<String>> {
|
||||||
|
let stream_type = selector.stream_type.as_ref();
|
||||||
|
let Some(stream_index) = find_stream_index(file, selector) else {
|
||||||
|
if selector.optional {
|
||||||
|
return Ok(vec![]);
|
||||||
|
} else {
|
||||||
|
anyhow::bail!("unsatisfied stream selection");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let stream_language = selector.language();
|
||||||
|
|
||||||
|
let mut args = vec![
|
||||||
|
format!("-metadata:s:{}:{}", stream_type, stream_index),
|
||||||
|
format!("language={}", stream_language),
|
||||||
|
];
|
||||||
|
|
||||||
|
if selector.stream_type == StreamType::Subtitle {
|
||||||
|
let sub_title = match selector.flag {
|
||||||
|
Some(StreamFlag::Forced) => "Forced",
|
||||||
|
Some(StreamFlag::Sdh) => "SDH",
|
||||||
|
None => match stream_language {
|
||||||
|
"eng" => "English",
|
||||||
|
"jpn" => "Japanese",
|
||||||
|
_ => anyhow::bail!("Unhandled subtitle language: {}", stream_language),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
args.push(format!("-metadata:s:s:{}", stream_index));
|
||||||
|
args.push(format!("title={}", sub_title));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_stream_index(file: &MediaFile, selector: &Selector) -> Option<usize> {
|
||||||
|
let needs_forced = selector.flag == Some(StreamFlag::Forced);
|
||||||
|
let needs_sdh = selector.flag == Some(StreamFlag::Sdh);
|
||||||
|
|
||||||
|
match selector.stream_type {
|
||||||
|
StreamType::Video => match selector.matcher {
|
||||||
|
Matcher::Index(index) => (file.streams.video.len() > index).then_some(index),
|
||||||
|
Matcher::Language(ref language) => file
|
||||||
|
.streams
|
||||||
|
.video
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, c)| c.language() == Some(language.as_str()))
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.next(),
|
||||||
|
Matcher::Codec(ref codec) => file
|
||||||
|
.streams
|
||||||
|
.video
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, c)| c.codec() == codec)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.next(),
|
||||||
|
},
|
||||||
|
StreamType::Audio => match selector.matcher {
|
||||||
|
Matcher::Index(index) => (file.streams.audio.len() > index).then_some(index),
|
||||||
|
Matcher::Language(ref language) => file
|
||||||
|
.streams
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, c)| c.language() == Some(language.as_str()))
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.next(),
|
||||||
|
Matcher::Codec(ref codec) => file
|
||||||
|
.streams
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, c)| c.codec() == codec)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.next(),
|
||||||
|
},
|
||||||
|
StreamType::Subtitle => match selector.matcher {
|
||||||
|
Matcher::Index(index) => (file.streams.subtitle.len() > index).then_some(index),
|
||||||
|
Matcher::Language(ref language) => {
|
||||||
|
file.streams
|
||||||
|
.subtitle
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, c)| c.language() == Some(language.as_str()))
|
||||||
|
.filter(|(_, c)| {
|
||||||
|
c.title()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_ascii_lowercase()
|
||||||
|
.contains("forced") == needs_forced
|
||||||
|
})
|
||||||
|
.filter(|(_, c)| {
|
||||||
|
c.title()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_ascii_lowercase()
|
||||||
|
.contains("sdh") == needs_sdh
|
||||||
|
})
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.next()
|
||||||
|
}
|
||||||
|
Matcher::Codec(ref codec) => file
|
||||||
|
.streams
|
||||||
|
.subtitle
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, c)| c.codec() == codec)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.next(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_command(cmd: &Command) {
|
||||||
|
let program = cmd.get_program().to_string_lossy();
|
||||||
|
|
||||||
|
let args = cmd
|
||||||
|
.get_args()
|
||||||
|
.map(|a| shell_escape(a.to_string_lossy().as_ref()))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ");
|
||||||
|
|
||||||
|
println!("{} {}", program, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shell_escape(s: &str) -> String {
|
||||||
|
if s.chars()
|
||||||
|
.all(|c| c.is_ascii_alphanumeric() || "-_./".contains(c))
|
||||||
|
{
|
||||||
|
s.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{:?}", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
use core::error::Error;
|
||||||
|
use core::fmt;
|
||||||
|
use core::str::FromStr;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum StreamType {
|
||||||
|
Video,
|
||||||
|
Audio,
|
||||||
|
Subtitle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for StreamType {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
StreamType::Video => "v",
|
||||||
|
StreamType::Audio => "a",
|
||||||
|
StreamType::Subtitle => "s",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for StreamType {
|
||||||
|
type Err = ParseSelectorError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"v" => Ok(StreamType::Video),
|
||||||
|
"a" => Ok(StreamType::Audio),
|
||||||
|
"s" => Ok(StreamType::Subtitle),
|
||||||
|
other => Err(ParseSelectorError::InvalidStreamType(other.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum Matcher {
|
||||||
|
Index(usize),
|
||||||
|
Language(String),
|
||||||
|
Codec(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Matcher {
|
||||||
|
type Err = ParseSelectorError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
if let Ok(idx) = s.parse::<usize>() {
|
||||||
|
return Ok(Matcher::Index(idx));
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.len() == 3 {
|
||||||
|
return Ok(Matcher::Language(s.to_ascii_lowercase()));
|
||||||
|
}
|
||||||
|
Ok(Matcher::Codec(s.to_ascii_lowercase()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum StreamFlag {
|
||||||
|
Forced,
|
||||||
|
Sdh,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for StreamFlag {
|
||||||
|
type Err = ParseSelectorError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s.to_ascii_lowercase().as_str() {
|
||||||
|
"forced" => Ok(StreamFlag::Forced),
|
||||||
|
"sdh" => Ok(StreamFlag::Sdh),
|
||||||
|
other => Err(ParseSelectorError::InvalidFlag(other.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct Selector {
|
||||||
|
pub stream_type: StreamType,
|
||||||
|
pub matcher: Matcher,
|
||||||
|
pub flag: Option<StreamFlag>,
|
||||||
|
pub optional: bool,
|
||||||
|
pub out_lang: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Selector {
|
||||||
|
pub fn language(&self) -> &str {
|
||||||
|
&self.out_lang
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Selector {
|
||||||
|
type Err = ParseSelectorError;
|
||||||
|
|
||||||
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
|
if input.is_empty() {
|
||||||
|
return Err(ParseSelectorError::Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (input, optional) = input
|
||||||
|
.strip_suffix('?')
|
||||||
|
.map_or((input, false), |s| (s, true));
|
||||||
|
|
||||||
|
let (left, out_lang) = input.split_once('>').unwrap_or((input, ""));
|
||||||
|
|
||||||
|
let mut parts = left.splitn(3, ':');
|
||||||
|
|
||||||
|
let stream_type: StreamType = parts
|
||||||
|
.next()
|
||||||
|
.ok_or(ParseSelectorError::InvalidFormat)?
|
||||||
|
.parse()?;
|
||||||
|
|
||||||
|
let matcher: Matcher = parts
|
||||||
|
.next()
|
||||||
|
.ok_or(ParseSelectorError::InvalidFormat)?
|
||||||
|
.parse()?;
|
||||||
|
|
||||||
|
let flag = parts
|
||||||
|
.next()
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(str::parse)
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
|
let out_lang = match (out_lang.is_empty(), &matcher) {
|
||||||
|
(false, _) => out_lang.to_owned(),
|
||||||
|
(true, Matcher::Language(language)) => language.clone(),
|
||||||
|
(true, _) => return Err(ParseSelectorError::UnspecifiedLanguage),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Selector {
|
||||||
|
stream_type,
|
||||||
|
matcher,
|
||||||
|
flag,
|
||||||
|
optional,
|
||||||
|
out_lang,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ParseSelectorError {
|
||||||
|
Empty,
|
||||||
|
InvalidFormat,
|
||||||
|
InvalidStreamType(String),
|
||||||
|
InvalidFlag(String),
|
||||||
|
UnspecifiedLanguage,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for ParseSelectorError {}
|
||||||
|
|
||||||
|
impl fmt::Display for ParseSelectorError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Empty => write!(f, "selector was empty"),
|
||||||
|
Self::InvalidFormat => write!(f, "invalid selector format"),
|
||||||
|
Self::InvalidStreamType(s) => write!(f, "invalid stream type '{}'", s),
|
||||||
|
Self::InvalidFlag(s) => write!(f, "invalid stream flag '{}'", s),
|
||||||
|
Self::UnspecifiedLanguage => write!(f, "unspecified output language"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
use anyhow::{Context as _, Result};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use walkdir::DirEntry;
|
||||||
|
|
||||||
|
use crate::model::{FFStream, MediaFile, Streams};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct FFProbeOutput<S> {
|
||||||
|
streams: Vec<S>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn probe_file_streams<S: FFStream>(entry: &DirEntry) -> Result<Vec<S>> {
|
||||||
|
let output = Command::new("ffprobe")
|
||||||
|
.args([
|
||||||
|
"-v",
|
||||||
|
"error",
|
||||||
|
"-output_format",
|
||||||
|
"json",
|
||||||
|
"-show_streams",
|
||||||
|
"-select_streams",
|
||||||
|
S::FF_TYPE_NAME,
|
||||||
|
#[expect(clippy::expect_used)]
|
||||||
|
entry.path().to_str().expect("path should be utf8"),
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.with_context(|| format!("Failed to run ffprobe on {:?}", entry.path()))?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"ffprobe failed for {:?}:\n\n{}",
|
||||||
|
entry.path(),
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsed: FFProbeOutput<S> = serde_json::from_slice(&output.stdout)?;
|
||||||
|
Ok(parsed.streams)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn probe_file(entry: &DirEntry) -> Result<MediaFile> {
|
||||||
|
Ok(MediaFile {
|
||||||
|
path: entry.path().to_path_buf(),
|
||||||
|
byte_size: entry.metadata()?.size(),
|
||||||
|
streams: Streams {
|
||||||
|
video: probe_file_streams(entry)?,
|
||||||
|
audio: probe_file_streams(entry)?,
|
||||||
|
subtitle: probe_file_streams(entry)?,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
use crate::model::MediaFile;
|
||||||
|
use crate::probe::probe_file;
|
||||||
|
|
||||||
|
pub fn scan_directory<T>(
|
||||||
|
path: &Path,
|
||||||
|
unknown_length_start: impl FnOnce() -> T,
|
||||||
|
unknown_length_end: impl FnOnce(T),
|
||||||
|
fixed_length_start: impl FnOnce(usize) -> T,
|
||||||
|
fixed_length_update: impl Fn(&mut T),
|
||||||
|
fixed_length_end: impl FnOnce(T),
|
||||||
|
print_fn: impl Fn(&T, &str),
|
||||||
|
) -> (Vec<MediaFile>, u64) {
|
||||||
|
let spinner = unknown_length_start();
|
||||||
|
let files: Vec<_> = WalkDir::new(path)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(Result::ok)
|
||||||
|
.filter(|e| e.file_type().is_file())
|
||||||
|
.filter(|e| {
|
||||||
|
let is_mkv = e
|
||||||
|
.path()
|
||||||
|
.extension()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.eq_ignore_ascii_case("mkv");
|
||||||
|
let is_mp4 = e
|
||||||
|
.path()
|
||||||
|
.extension()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.eq_ignore_ascii_case("mp4");
|
||||||
|
is_mkv || is_mp4
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
unknown_length_end(spinner);
|
||||||
|
|
||||||
|
let mut progress = fixed_length_start(files.len());
|
||||||
|
let mut total_byte_size = 0u64;
|
||||||
|
let files: Vec<_> = files
|
||||||
|
.iter()
|
||||||
|
.filter_map(|entry| {
|
||||||
|
let file = match probe_file(entry) {
|
||||||
|
Ok(file) => Some(file),
|
||||||
|
Err(err) => {
|
||||||
|
print_fn(&progress, &format!("{:?}", err));
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let size = file.as_ref().map(|r| r.byte_size).unwrap_or_default();
|
||||||
|
total_byte_size = total_byte_size.saturating_add(size);
|
||||||
|
fixed_length_update(&mut progress);
|
||||||
|
file
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
fixed_length_end(progress);
|
||||||
|
(files, total_byte_size)
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-cli"
|
name = "flix-cli"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
|
|
||||||
description = "CLI for interacting with a flix database"
|
description = "CLI for interacting with a flix database"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
CLI for interacting with a flix database
|
CLI for interacting with a flix database
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -- init
|
cargo run -- init
|
||||||
cargo run -- add tmdb movie <id>
|
cargo run -- add tmdb movie <id>
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ pub mod tmdb;
|
|||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Use a custom config file
|
/// Use a custom config file
|
||||||
#[arg(short, long, value_name = "FILE", default_value = "~/.flix")]
|
#[arg(
|
||||||
|
short,
|
||||||
|
long,
|
||||||
|
value_name = "FILE",
|
||||||
|
default_value = "~/.config/flix/config.toml"
|
||||||
|
)]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
/// Use a custom cache file
|
/// Use a custom cache file
|
||||||
|
|||||||
@@ -30,11 +30,9 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
let database_path = cli.database_path()?;
|
let database_path = cli.database_path()?;
|
||||||
|
|
||||||
let client = Client::new(
|
let config = tmdb::Config::new(config.tmdb().bearer_token().to_owned());
|
||||||
tmdb::Config::new(config.tmdb().bearer_token().to_owned()),
|
let cache = Rc::new(RedbCache::new(cli.cache_path())?);
|
||||||
Rc::new(RedbCache::new(cli.cache_path())?),
|
let client = Client::new(config, cache, CachePolicy::Full);
|
||||||
CachePolicy::Full,
|
|
||||||
);
|
|
||||||
|
|
||||||
if cli.trace {
|
if cli.trace {
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ pub async fn add(
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let flix_id = match result {
|
match result {
|
||||||
Ok(id) => id,
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
println!("Created Collection: {} [{}]", title, flix_id.into_raw());
|
println!("Created Collection: {}", title);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -93,18 +93,12 @@ pub async fn add(
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (flix_show, season_number, episode_number) = match result {
|
match result {
|
||||||
Ok(id) => id,
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
println!(
|
println!("Created Episode: {}", title);
|
||||||
"Created Episode: {} [{} S{} E{}]",
|
|
||||||
title,
|
|
||||||
flix_show.into_raw(),
|
|
||||||
season_number,
|
|
||||||
episode_number
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-42
@@ -83,12 +83,12 @@ pub async fn add(
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let flix_id = match result {
|
match result {
|
||||||
Ok(id) => id,
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
println!("Created Collection: {} [{}]", title, flix_id.into_raw());
|
println!("Created Collection: {}", title);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -151,17 +151,12 @@ pub async fn add(
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let flix_id = match result {
|
match result {
|
||||||
Ok(id) => id,
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
println!(
|
println!("Created Movie: {} ({})", title, year);
|
||||||
"Created Movie: {} ({}) [{}]",
|
|
||||||
title,
|
|
||||||
year,
|
|
||||||
flix_id.into_raw(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -215,18 +210,22 @@ pub async fn add(
|
|||||||
let mut season_episodes = Vec::new();
|
let mut season_episodes = Vec::new();
|
||||||
for episode in 1..=number_of_episodes {
|
for episode in 1..=number_of_episodes {
|
||||||
let episode = EpisodeNumber::new(episode);
|
let episode = EpisodeNumber::new(episode);
|
||||||
let Ok(episode) = client
|
let episode = match client
|
||||||
.episodes()
|
.episodes()
|
||||||
.get_details(id, season.season_number, episode, None)
|
.get_details(id, season.season_number, episode, None)
|
||||||
.await
|
.await
|
||||||
else {
|
{
|
||||||
eprintln!(
|
Ok(value) => value,
|
||||||
"skipping episode ({}, {}, {})",
|
Err(err) => {
|
||||||
id.into_raw(),
|
eprintln!(
|
||||||
season.season_number,
|
"skipping episode ({}, {}, {}) - {}",
|
||||||
episode
|
id.into_raw(),
|
||||||
);
|
season.season_number,
|
||||||
break;
|
episode,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
season_episodes.push(episode);
|
season_episodes.push(episode);
|
||||||
}
|
}
|
||||||
@@ -329,17 +328,12 @@ pub async fn add(
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let flix_id = match result {
|
match result {
|
||||||
Ok(id) => id,
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
println!(
|
println!("Created Show: {} ({})", title, year);
|
||||||
"Created Show: {} ({}) [{}]",
|
|
||||||
title,
|
|
||||||
year,
|
|
||||||
flix_id.into_raw()
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -380,18 +374,22 @@ pub async fn add(
|
|||||||
|
|
||||||
for episode in 1..=number_of_episodes {
|
for episode in 1..=number_of_episodes {
|
||||||
let episode = EpisodeNumber::new(episode);
|
let episode = EpisodeNumber::new(episode);
|
||||||
let Ok(episode) = client
|
let episode = match client
|
||||||
.episodes()
|
.episodes()
|
||||||
.get_details(id, season.season_number, episode, None)
|
.get_details(id, season.season_number, episode, None)
|
||||||
.await
|
.await
|
||||||
else {
|
{
|
||||||
eprintln!(
|
Ok(value) => value,
|
||||||
"skipping episode ({}, {}, {})",
|
Err(err) => {
|
||||||
id.into_raw(),
|
eprintln!(
|
||||||
season.season_number,
|
"skipping episode ({}, {}, {}) - {}",
|
||||||
episode
|
id.into_raw(),
|
||||||
);
|
season.season_number,
|
||||||
break;
|
episode,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
episodes.push(episode);
|
episodes.push(episode);
|
||||||
}
|
}
|
||||||
@@ -451,7 +449,7 @@ pub async fn add(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => (),
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
@@ -541,7 +539,7 @@ pub async fn add(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => (),
|
Ok(_) => {}
|
||||||
Err(TransactionError::Connection(err)) => Err(err)?,
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
Err(TransactionError::Transaction(err)) => Err(err)?,
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
};
|
};
|
||||||
@@ -637,7 +635,7 @@ pub async fn update(client: Client, db: &DatabaseConnection, command: Command) -
|
|||||||
// Err(TransactionError::Connection(err)) => Err(err)?,
|
// Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
// Err(TransactionError::Transaction(err)) => Err(err)?,
|
// Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
// };
|
// };
|
||||||
// println!("Created Collection: {} [{}]", title, flix_id.into_raw());
|
// println!("Created Collection: {}", title, flix_id.into_raw());
|
||||||
|
|
||||||
// Ok(())
|
// Ok(())
|
||||||
// }
|
// }
|
||||||
@@ -706,7 +704,7 @@ pub async fn update(client: Client, db: &DatabaseConnection, command: Command) -
|
|||||||
// Err(TransactionError::Transaction(err)) => Err(err)?,
|
// Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
// };
|
// };
|
||||||
// println!(
|
// println!(
|
||||||
// "Created Movie: {} ({}) [{}]",
|
// "Created Movie: {} ({})",
|
||||||
// title,
|
// title,
|
||||||
// year,
|
// year,
|
||||||
// flix_id.into_raw(),
|
// flix_id.into_raw(),
|
||||||
@@ -884,7 +882,7 @@ pub async fn update(client: Client, db: &DatabaseConnection, command: Command) -
|
|||||||
// Err(TransactionError::Transaction(err)) => Err(err)?,
|
// Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
// };
|
// };
|
||||||
// println!(
|
// println!(
|
||||||
// "Created Show: {} ({}) [{}]",
|
// "Created Show: {} ({})",
|
||||||
// title,
|
// title,
|
||||||
// year,
|
// year,
|
||||||
// flix_id.into_raw()
|
// flix_id.into_raw()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-db"
|
name = "flix-db"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
|
|
||||||
description = "Types for storing persistent data about media"
|
description = "Types for storing persistent data about media"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
pub mod libraries {
|
pub mod libraries {
|
||||||
use flix_model::id::LibraryId;
|
use flix_model::id::LibraryId;
|
||||||
|
|
||||||
|
use seamantic::model::duration::Seconds;
|
||||||
use seamantic::model::path::PathBytes;
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -20,7 +21,9 @@ pub mod libraries {
|
|||||||
/// The library's directory
|
/// The library's directory
|
||||||
pub directory: PathBytes,
|
pub directory: PathBytes,
|
||||||
/// The library's last scan data
|
/// The library's last scan data
|
||||||
pub last_scan: Option<DateTime<Utc>>,
|
pub last_scan_date: Option<DateTime<Utc>>,
|
||||||
|
/// The library's last scan duration
|
||||||
|
pub last_scan_duration: Option<Seconds>,
|
||||||
|
|
||||||
/// Collections that are part of this library
|
/// Collections that are part of this library
|
||||||
#[sea_orm(has_many)]
|
#[sea_orm(has_many)]
|
||||||
@@ -415,7 +418,8 @@ pub mod test {
|
|||||||
$crate::entity::content::libraries::ActiveModel {
|
$crate::entity::content::libraries::ActiveModel {
|
||||||
id: Set(::flix_model::id::LibraryId::from_raw($id)),
|
id: Set(::flix_model::id::LibraryId::from_raw($id)),
|
||||||
directory: Set(::std::path::PathBuf::new().into()),
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
last_scan: Set(None),
|
last_scan_date: Set(None),
|
||||||
|
last_scan_duration: Set(None),
|
||||||
}
|
}
|
||||||
.insert($db)
|
.insert($db)
|
||||||
.await
|
.await
|
||||||
@@ -522,10 +526,13 @@ pub mod test {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use core::time::Duration;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
|
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
|
||||||
|
|
||||||
|
use seamantic::model::duration::Seconds;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
@@ -566,7 +573,8 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(model.id, LibraryId::from_raw($id));
|
assert_eq!(model.id, LibraryId::from_raw($id));
|
||||||
assert_eq!(model.directory, Path::new(concat!("L Directory ", $id)).to_owned().into());
|
assert_eq!(model.directory, Path::new(concat!("L Directory ", $id)).to_owned().into());
|
||||||
assert_eq!(model.last_scan, noneable!(last_scan, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?));
|
assert_eq!(model.last_scan_date, noneable!(last_scan_date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?));
|
||||||
|
assert_eq!(model.last_scan_duration, noneable!(last_scan_duration, Seconds(Duration::from_secs($id)) $(, $($skip),+)?));
|
||||||
};
|
};
|
||||||
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
|
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
@@ -578,7 +586,8 @@ mod tests {
|
|||||||
super::libraries::ActiveModel {
|
super::libraries::ActiveModel {
|
||||||
id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?),
|
id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?),
|
||||||
directory: notsettable!(directory, Path::new(concat!("L Directory ", $id)).to_owned().into() $(, $($skip),+)?),
|
directory: notsettable!(directory, Path::new(concat!("L Directory ", $id)).to_owned().into() $(, $($skip),+)?),
|
||||||
last_scan: notsettable!(last_scan, Some(NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc()) $(, $($skip),+)?),
|
last_scan_date: notsettable!(last_scan_date, Some(NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc()) $(, $($skip),+)?),
|
||||||
|
last_scan_duration: notsettable!(last_scan_duration, Some(Seconds(Duration::from_secs($id))) $(, $($skip),+)?),
|
||||||
}.insert($db).await
|
}.insert($db).await
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -588,7 +597,8 @@ mod tests {
|
|||||||
assert_library!(&db, 2, Success);
|
assert_library!(&db, 2, Success);
|
||||||
assert_library!(&db, 3, Success; id);
|
assert_library!(&db, 3, Success; id);
|
||||||
assert_library!(&db, 4, NotNullViolation; directory);
|
assert_library!(&db, 4, NotNullViolation; directory);
|
||||||
assert_library!(&db, 5, Success; last_scan);
|
assert_library!(&db, 5, Success; last_scan_date);
|
||||||
|
assert_library!(&db, 6, Success; last_scan_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix"
|
name = "flix"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
|
|
||||||
description = "Mechanisms for interacting with flix media"
|
description = "Mechanisms for interacting with flix media"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-fs"
|
name = "flix-fs"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
|
|
||||||
description = "Filesystem scanner for flix media"
|
description = "Filesystem scanner for flix media"
|
||||||
|
|||||||
@@ -72,11 +72,12 @@ impl From<show::Scanner> for Scanner {
|
|||||||
|
|
||||||
impl Scanner {
|
impl Scanner {
|
||||||
/// Helper function for stripping allowed numerical prefixes for sorting ("01 - ")
|
/// Helper function for stripping allowed numerical prefixes for sorting ("01 - ")
|
||||||
fn strip_numeric_prefix(mut s: &str) -> &str {
|
fn strip_numeric_prefix(original: &str) -> &str {
|
||||||
|
let mut s = original;
|
||||||
while let Some('0'..='9') = s.chars().next() {
|
while let Some('0'..='9') = s.chars().next() {
|
||||||
s = &s[1..]
|
s = &s[1..]
|
||||||
}
|
}
|
||||||
s.strip_prefix(" - ").unwrap_or(s)
|
s.strip_prefix(" - ").unwrap_or(original)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Detect the type of a folder and call the correct scanner. Use
|
/// Detect the type of a folder and call the correct scanner. Use
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ pub enum MediaRef<ID> {
|
|||||||
Slug(String),
|
Slug(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<ID> MediaRef<ID> {
|
||||||
|
/// Get the slug if it exists
|
||||||
|
pub fn into_slug(self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
MediaRef::Id(_) => None,
|
||||||
|
MediaRef::Slug(slug) => Some(slug),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A scanned collection
|
/// A scanned collection
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CollectionScan {
|
pub struct CollectionScan {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-model"
|
name = "flix-model"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
|
|
||||||
description = "Core types for flix data"
|
description = "Core types for flix data"
|
||||||
|
|||||||
+18
-15
@@ -12,22 +12,25 @@ fn split_normalized_words(input: &str) -> impl Iterator<Item = String> {
|
|||||||
panic!("Input is not ASCII: {input}");
|
panic!("Input is not ASCII: {input}");
|
||||||
}
|
}
|
||||||
|
|
||||||
input.split_ascii_whitespace().map(|s| {
|
input
|
||||||
let chars = s
|
.split_ascii_whitespace()
|
||||||
.chars()
|
.map(|s| {
|
||||||
.filter(|c| c.is_ascii_alphanumeric() || *c == '-')
|
let chars = s
|
||||||
.map(|c| c.to_ascii_lowercase());
|
.chars()
|
||||||
|
.filter(|c| c.is_ascii_alphanumeric() || *c == '-')
|
||||||
|
.map(|c| c.to_ascii_lowercase());
|
||||||
|
|
||||||
if s.len() > 4
|
if s.len() > 4
|
||||||
&& s.len().is_multiple_of(2)
|
&& s.len().is_multiple_of(2)
|
||||||
&& chars.clone().tuples().all(|(l, r)| l != '.' && r == '.')
|
&& chars.clone().tuples().all(|(l, r)| l != '.' && r == '.')
|
||||||
{
|
{
|
||||||
// Collapse acronym
|
// Collapse acronym
|
||||||
chars.tuples().map(|(l, _)| l).collect()
|
chars.tuples().map(|(l, _)| l).collect()
|
||||||
} else {
|
} else {
|
||||||
chars.collect()
|
chars.collect()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.filter(|part: &String| !part.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_leading_article<I: Iterator<Item = String>>(iter: I) -> (Option<String>, Peekable<I>) {
|
fn split_leading_article<I: Iterator<Item = String>>(iter: I) -> (Option<String>, Peekable<I>) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-tmdb"
|
name = "flix-tmdb"
|
||||||
version = "0.0.18"
|
version = "0.0.19"
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
|
|
||||||
description = "Clients and models for fetching data from TMDB"
|
description = "Clients and models for fetching data from TMDB"
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ use core::time::Duration;
|
|||||||
use flix_model::numbers::EpisodeNumber;
|
use flix_model::numbers::EpisodeNumber;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use super::duration_from_minutes;
|
use super::{duration_from_minutes, still_url_from_path};
|
||||||
|
|
||||||
/// A deserialized Episode from the TMDB API
|
/// A deserialized Episode from the TMDB API
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Deserialize)]
|
||||||
@@ -18,7 +19,10 @@ pub struct Episode {
|
|||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The episode's air date
|
/// The episode's air date
|
||||||
pub air_date: NaiveDate,
|
pub air_date: NaiveDate,
|
||||||
/// The movie's runtime
|
/// The episode's runtime
|
||||||
#[serde(deserialize_with = "duration_from_minutes")]
|
#[serde(deserialize_with = "duration_from_minutes")]
|
||||||
pub runtime: Duration,
|
pub runtime: Duration,
|
||||||
|
/// The episode's still path
|
||||||
|
#[serde(deserialize_with = "still_url_from_path")]
|
||||||
|
pub still_path: Option<Url>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
//! Deserializable types from the TMDB API
|
//! Deserializable types from the TMDB API
|
||||||
|
|
||||||
|
use core::str::FromStr;
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
pub mod id;
|
pub mod id;
|
||||||
|
|
||||||
@@ -22,6 +24,24 @@ fn duration_from_minutes<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let minutes = u64::deserialize(deserializer)?;
|
let minutes = u64::deserialize(deserializer).unwrap_or(0);
|
||||||
Ok(Duration::from_secs(minutes.saturating_mul(60)))
|
Ok(Duration::from_secs(minutes.saturating_mul(60)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn still_url_from_path<'de, D>(deserializer: D) -> Result<Option<Url>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
const TMDB_IMAGE_BASE: &str = "http://image.tmdb.org/t/p/";
|
||||||
|
const TMDB_IMAGE_QUALITY: &str = "original";
|
||||||
|
|
||||||
|
let path = Option::<&str>::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
Ok(path.and_then(|path| {
|
||||||
|
Url::from_str(&format!(
|
||||||
|
"{}{}{}",
|
||||||
|
TMDB_IMAGE_BASE, TMDB_IMAGE_QUALITY, path
|
||||||
|
))
|
||||||
|
.ok()
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,3 +3,9 @@ toml-version = "v1.0.0"
|
|||||||
[format.rules]
|
[format.rules]
|
||||||
indent-style = "tab"
|
indent-style = "tab"
|
||||||
indent-width = 4
|
indent-width = 4
|
||||||
|
|
||||||
|
# Required for rust <1.94
|
||||||
|
[[schemas]]
|
||||||
|
toml-version = "v1.0.0"
|
||||||
|
path = "tombi://www.schemastore.org/cargo.json"
|
||||||
|
include = ["Cargo.toml"]
|
||||||
|
|||||||
Reference in New Issue
Block a user