You've already forked flix
Compare commits
7 Commits
508c4ed32f
...
0.0.17
| Author | SHA1 | Date | |
|---|---|---|---|
|
66168c120f
|
|||
|
0e2a8e425b
|
|||
|
994a80c45c
|
|||
|
dd2cf5c942
|
|||
|
c2fb43de30
|
|||
|
b10cef4f2d
|
|||
|
c5475585d4
|
@@ -5,3 +5,7 @@
|
|||||||
|
|
||||||
# Rust
|
# Rust
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
# Flix
|
||||||
|
flix.db
|
||||||
|
flix.redb
|
||||||
|
|||||||
Vendored
-9
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"vadimcn.vscode-lldb",
|
|
||||||
"barbosshack.crates-io",
|
|
||||||
"usernamehw.errorlens",
|
|
||||||
"tamasfe.even-better-toml",
|
|
||||||
"rust-lang.rust-analyzer",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Vendored
-33
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
// VSCode
|
|
||||||
"editor.detectIndentation": false,
|
|
||||||
"editor.insertSpaces": false,
|
|
||||||
"editor.tabSize": 4,
|
|
||||||
"files.exclude": {
|
|
||||||
"**/target": true,
|
|
||||||
"**/Cargo.lock": true,
|
|
||||||
},
|
|
||||||
"files.insertFinalNewline": true,
|
|
||||||
"files.trimFinalNewlines": true,
|
|
||||||
"files.trimTrailingWhitespace": true,
|
|
||||||
"files.watcherExclude": {
|
|
||||||
"**/.git/**": true,
|
|
||||||
"**/target/**": true,
|
|
||||||
},
|
|
||||||
// Extensions
|
|
||||||
"crates.listPreReleases": true,
|
|
||||||
"evenBetterToml.formatter.alignComments": true,
|
|
||||||
"evenBetterToml.formatter.alignEntries": false,
|
|
||||||
"evenBetterToml.formatter.allowedBlankLines": 1,
|
|
||||||
"evenBetterToml.formatter.arrayAutoExpand": true,
|
|
||||||
"evenBetterToml.formatter.arrayTrailingComma": true,
|
|
||||||
"evenBetterToml.formatter.columnWidth": 80,
|
|
||||||
"evenBetterToml.formatter.reorderKeys": true,
|
|
||||||
"evenBetterToml.formatter.trailingNewline": true,
|
|
||||||
"rust-analyzer.imports.granularity.enforce": true,
|
|
||||||
"rust-analyzer.imports.granularity.group": "module",
|
|
||||||
"rust-analyzer.imports.group.enable": true,
|
|
||||||
"rust-analyzer.imports.merge.glob": false,
|
|
||||||
"rust-analyzer.imports.preferNoStd": true,
|
|
||||||
"rust-analyzer.showUnlinkedFileNotification": false,
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"project_name": null,
|
||||||
|
|
||||||
|
"auto_install_extensions": {
|
||||||
|
"tombi": true,
|
||||||
|
"cargo-appraiser": true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"languages": {
|
||||||
|
"TOML": {
|
||||||
|
"format_on_save": "on",
|
||||||
|
"formatter": { "language_server": { "name": "tombi" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
"lsp": {
|
||||||
|
"rust-analyzer": {
|
||||||
|
"initialization_options": {
|
||||||
|
"imports": {
|
||||||
|
"granularity": { "enforce": true, "group": "module" },
|
||||||
|
"group": { "enable": true },
|
||||||
|
"merge": { "glob": false },
|
||||||
|
"preferNoStd": true,
|
||||||
|
},
|
||||||
|
"server": {
|
||||||
|
"extraEnv": {
|
||||||
|
"RUSTUP_TOOLCHAIN": "stable",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
Generated
+980
-245
File diff suppressed because it is too large
Load Diff
+46
-43
@@ -1,18 +1,46 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["crates/*"]
|
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
authors = []
|
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
rust-version = "1.89.0"
|
||||||
license-file = "LICENSE.md"
|
license-file = "LICENSE.md"
|
||||||
rust-version = "1.85.0"
|
|
||||||
|
|
||||||
[workspace.lints.rust]
|
[workspace.dependencies]
|
||||||
arithmetic_overflow = "forbid"
|
anyhow = { version = "^1", default-features = false }
|
||||||
missing_docs = "forbid"
|
async-stream = { version = "^0.3", default-features = false }
|
||||||
unsafe_code = "forbid"
|
bytes = { version = "^1", default-features = false }
|
||||||
unused_doc_comments = "forbid"
|
chrono = { version = "^0.4", default-features = false }
|
||||||
|
clap = { version = "^4", default-features = false }
|
||||||
|
either = { version = "^1", default-features = false }
|
||||||
|
flix = { path = "crates/flix", version = "=0.0.17", default-features = false }
|
||||||
|
flix-cli = { path = "crates/cli", version = "=0.0.17", default-features = false }
|
||||||
|
flix-db = { path = "crates/db", version = "=0.0.17", default-features = false }
|
||||||
|
flix-fs = { path = "crates/fs", version = "=0.0.17", default-features = false }
|
||||||
|
flix-model = { path = "crates/model", version = "=0.0.17", default-features = false }
|
||||||
|
flix-tmdb = { path = "crates/tmdb", version = "=0.0.17", default-features = false }
|
||||||
|
futures = { version = "^0.3", default-features = false }
|
||||||
|
governor = { version = "^0.10", default-features = false }
|
||||||
|
itertools = { version = "^0.14", default-features = false }
|
||||||
|
nonzero_ext = { version = "^0.3", default-features = false }
|
||||||
|
redb = { version = "^3", default-features = false }
|
||||||
|
regex = { version = "^1", default-features = false }
|
||||||
|
reqwest = { version = "^0.13", default-features = false }
|
||||||
|
sea-orm = { version = "2.0.0-rc.27", default-features = false }
|
||||||
|
sea-orm-migration = { version = "2.0.0-rc.27", default-features = false }
|
||||||
|
seamantic = { version = "^0.0.12", default-features = false }
|
||||||
|
serde = { version = "^1", default-features = false }
|
||||||
|
serde_json = { version = "^1", default-features = false }
|
||||||
|
serde_test = { version = "^1", default-features = false }
|
||||||
|
thiserror = { version = "^2", default-features = false }
|
||||||
|
tokio = { version = "^1", default-features = false }
|
||||||
|
tokio-stream = { version = "^0.1", default-features = false }
|
||||||
|
toml = { version = "^0.9", default-features = false }
|
||||||
|
tracing = { version = "^0.1", default-features = false }
|
||||||
|
tracing-subscriber = { version = "^0.3", default-features = false }
|
||||||
|
url = { version = "^2", default-features = false }
|
||||||
|
url-macro = { version = "^0.2", default-features = false }
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
arithmetic_side_effects = "forbid"
|
arithmetic_side_effects = "forbid"
|
||||||
@@ -24,43 +52,18 @@ indexing_slicing = "forbid"
|
|||||||
integer_division = "forbid"
|
integer_division = "forbid"
|
||||||
integer_division_remainder_used = "forbid"
|
integer_division_remainder_used = "forbid"
|
||||||
transmute_undefined_repr = "forbid"
|
transmute_undefined_repr = "forbid"
|
||||||
unchecked_duration_subtraction = "forbid"
|
unchecked_time_subtraction = "forbid"
|
||||||
unwrap_used = "forbid"
|
unwrap_used = "forbid"
|
||||||
|
|
||||||
|
[workspace.lints.rust]
|
||||||
|
arithmetic_overflow = "forbid"
|
||||||
|
missing_docs = "forbid"
|
||||||
|
unsafe_code = "forbid"
|
||||||
|
unused_doc_comments = "forbid"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
|
||||||
lto = "fat"
|
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
overflow-checks = true
|
|
||||||
strip = "debuginfo"
|
strip = "debuginfo"
|
||||||
|
overflow-checks = true
|
||||||
[workspace.dependencies]
|
lto = "fat"
|
||||||
flix = { path = "crates/flix", version = "=0.0.12", default-features = false }
|
codegen-units = 1
|
||||||
flix-cli = { path = "crates/cli", version = "=0.0.12", default-features = false }
|
|
||||||
flix-db = { path = "crates/db", version = "=0.0.12", default-features = false }
|
|
||||||
flix-fs = { path = "crates/fs", version = "=0.0.12", default-features = false }
|
|
||||||
flix-model = { path = "crates/model", version = "=0.0.12", default-features = false }
|
|
||||||
flix-tmdb = { path = "crates/tmdb", version = "=0.0.12", default-features = false }
|
|
||||||
|
|
||||||
seamantic = { version = "0.0.9", default-features = false }
|
|
||||||
|
|
||||||
sea-orm = { version = "2.0.0-rc.16", default-features = false }
|
|
||||||
sea-orm-migration = { version = "2.0.0-rc.16", default-features = false }
|
|
||||||
|
|
||||||
anyhow = { version = "^1", default-features = false }
|
|
||||||
async-stream = { version = "^0.3", default-features = false }
|
|
||||||
chrono = { version = "^0.4", default-features = false }
|
|
||||||
clap = { version = "^4", default-features = false, features = ["std"] }
|
|
||||||
futures = { version = "^0.3", default-features = false }
|
|
||||||
governor = { version = "^0.10", default-features = false }
|
|
||||||
nonzero_ext = { version = "^0.3", default-features = false }
|
|
||||||
regex = { version = "^1", default-features = false }
|
|
||||||
reqwest = { version = "^0.12", default-features = false }
|
|
||||||
serde = { version = "^1", default-features = false }
|
|
||||||
serde_test = { version = "^1", default-features = false }
|
|
||||||
thiserror = { version = "^2", default-features = false }
|
|
||||||
tokio = { version = "^1", default-features = false }
|
|
||||||
tokio-stream = { version = "^0.1", default-features = false }
|
|
||||||
toml = { version = "^0.9", default-features = false }
|
|
||||||
url = { version = "^2", default-features = false }
|
|
||||||
url-macro = { version = "^0.2", default-features = false }
|
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ Libraries and tools for dealing with media metadata
|
|||||||
- build: `cargo hack --feature-powerset build`
|
- build: `cargo hack --feature-powerset build`
|
||||||
- clippy: `cargo hack --feature-powerset clippy -- -D warnings`
|
- clippy: `cargo hack --feature-powerset clippy -- -D warnings`
|
||||||
- test: `cargo hack --feature-powerset test`
|
- test: `cargo hack --feature-powerset test`
|
||||||
- test old: `cargo +1.85 hack --feature-powerset test`
|
- test old: `cargo +1.89 hack --feature-powerset test`
|
||||||
- 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`
|
||||||
- semver: `cargo semver-checks --all-features`
|
- semver: `cargo semver-checks --all-features`
|
||||||
- publish: `cargo publish --dry-run --workspace`
|
- publish: `cargo publish --dry-run --workspace`
|
||||||
|
|
||||||
|
## Building flix.db
|
||||||
|
|
||||||
|
`./flix.sh`
|
||||||
|
|||||||
+28
-29
@@ -1,15 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-cli"
|
name = "flix-cli"
|
||||||
version = "0.0.12"
|
version = "0.0.17"
|
||||||
|
edition.workspace = true
|
||||||
categories = ["command-line-utilities"]
|
rust-version.workspace = true
|
||||||
description = "CLI for interacting with a flix database"
|
description = "CLI for interacting with a flix database"
|
||||||
repository = "https://github.com/QuantumShade/flix"
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
rust-version.workspace = true
|
categories = ["command-line-utilities"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
@@ -20,9 +17,26 @@ doc = false
|
|||||||
name = "flix"
|
name = "flix"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[lints.rust]
|
[dependencies]
|
||||||
arithmetic_overflow = "forbid"
|
anyhow = { workspace = true }
|
||||||
unsafe_code = "forbid"
|
chrono = { workspace = true, features = ["now"] }
|
||||||
|
clap = { workspace = true, features = [
|
||||||
|
"color",
|
||||||
|
"derive",
|
||||||
|
"error-context",
|
||||||
|
"help",
|
||||||
|
"std",
|
||||||
|
"suggestions",
|
||||||
|
"usage",
|
||||||
|
] }
|
||||||
|
flix = { workspace = true, features = ["tmdb"] }
|
||||||
|
futures = { workspace = true }
|
||||||
|
sea-orm = { workspace = true, features = ["debug-print", "runtime-tokio"] }
|
||||||
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
tokio = { workspace = true, features = ["fs", "macros", "rt"] }
|
||||||
|
toml = { workspace = true, features = ["parse", "serde"] }
|
||||||
|
tracing = { workspace = true }
|
||||||
|
tracing-subscriber = { workspace = true }
|
||||||
|
|
||||||
[lints.clippy]
|
[lints.clippy]
|
||||||
arithmetic_side_effects = "deny"
|
arithmetic_side_effects = "deny"
|
||||||
@@ -34,24 +48,9 @@ indexing_slicing = "deny"
|
|||||||
integer_division = "deny"
|
integer_division = "deny"
|
||||||
integer_division_remainder_used = "deny"
|
integer_division_remainder_used = "deny"
|
||||||
transmute_undefined_repr = "deny"
|
transmute_undefined_repr = "deny"
|
||||||
unchecked_duration_subtraction = "deny"
|
unchecked_time_subtraction = "deny"
|
||||||
unwrap_used = "deny"
|
unwrap_used = "deny"
|
||||||
|
|
||||||
[dependencies]
|
[lints.rust]
|
||||||
flix = { workspace = true, features = ["tmdb"] }
|
arithmetic_overflow = "forbid"
|
||||||
|
unsafe_code = "forbid"
|
||||||
anyhow = { workspace = true }
|
|
||||||
chrono = { workspace = true, features = ["now"] }
|
|
||||||
clap = { workspace = true, features = [
|
|
||||||
"derive",
|
|
||||||
"color",
|
|
||||||
"error-context",
|
|
||||||
"help",
|
|
||||||
"suggestions",
|
|
||||||
"usage",
|
|
||||||
] }
|
|
||||||
futures = { workspace = true }
|
|
||||||
sea-orm = { workspace = true, features = ["runtime-tokio"] }
|
|
||||||
serde = { workspace = true, features = ["derive"] }
|
|
||||||
tokio = { workspace = true, features = ["rt", "fs", "macros"] }
|
|
||||||
toml = { workspace = true, features = ["parse", "serde"] }
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
use flix::model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use clap::Subcommand;
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum AddCommand {
|
||||||
|
/// Add a flix collection
|
||||||
|
Collection {
|
||||||
|
#[arg(value_name = "TITLE")]
|
||||||
|
title: String,
|
||||||
|
#[arg(value_name = "OVERVIEW")]
|
||||||
|
overview: String,
|
||||||
|
},
|
||||||
|
/// Add a flix episode
|
||||||
|
Episode {
|
||||||
|
#[arg(value_name = "SHOW_WEB_SLUG")]
|
||||||
|
show_slug: String,
|
||||||
|
#[arg(value_name = "NUMBER")]
|
||||||
|
season_number: SeasonNumber,
|
||||||
|
#[arg(value_name = "NUMBER")]
|
||||||
|
episode_number: EpisodeNumber,
|
||||||
|
#[arg(value_name = "TITLE")]
|
||||||
|
title: String,
|
||||||
|
#[arg(value_name = "OVERVIEW")]
|
||||||
|
overview: String,
|
||||||
|
#[arg(value_name = "DATE")]
|
||||||
|
air_date: NaiveDate,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
|
|
||||||
|
pub mod flix;
|
||||||
pub mod tmdb;
|
pub mod tmdb;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
@@ -12,10 +13,18 @@ pub struct Cli {
|
|||||||
#[arg(short, long, value_name = "FILE", default_value = "~/.flix")]
|
#[arg(short, long, value_name = "FILE", default_value = "~/.flix")]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
|
/// Use a custom cache file
|
||||||
|
#[arg(short = 'C', long, value_name = "FILE", default_value = "./flix.redb")]
|
||||||
|
cache: PathBuf,
|
||||||
|
|
||||||
/// Use a custom database file
|
/// Use a custom database file
|
||||||
#[arg(short, long, value_name = "DATABASE", default_value = "./flix.db")]
|
#[arg(short, long, value_name = "FILE", default_value = "./flix.db")]
|
||||||
database: PathBuf,
|
database: PathBuf,
|
||||||
|
|
||||||
|
/// Enable tracing
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub trace: bool,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Command,
|
command: Command,
|
||||||
}
|
}
|
||||||
@@ -33,6 +42,10 @@ impl Cli {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cache_path(&self) -> &Path {
|
||||||
|
&self.cache
|
||||||
|
}
|
||||||
|
|
||||||
pub fn database_path(&self) -> Result<String> {
|
pub fn database_path(&self) -> Result<String> {
|
||||||
self.database
|
self.database
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
@@ -46,24 +59,38 @@ impl Cli {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct AddOverrides {
|
||||||
|
#[arg(long)]
|
||||||
|
pub title: Option<String>,
|
||||||
|
#[arg(long)]
|
||||||
|
pub sort_title: Option<String>,
|
||||||
|
#[arg(long)]
|
||||||
|
pub fs_slug: Option<String>,
|
||||||
|
#[arg(long)]
|
||||||
|
pub web_slug: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// Initialize a new database
|
/// Initialize a new database
|
||||||
Init,
|
Init,
|
||||||
/// Add new items to the database
|
/// Add new items to the database
|
||||||
Add {
|
Add {
|
||||||
|
#[command(flatten)]
|
||||||
|
overrides: AddOverrides,
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: BackendCommand,
|
command: AddCommand,
|
||||||
},
|
},
|
||||||
/// Update an existing item in the database
|
/// Update an existing item in the database
|
||||||
Update {
|
Update {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: BackendCommand,
|
command: UpdateCommand,
|
||||||
},
|
},
|
||||||
/// Delete an existing item in the database
|
/// Delete an existing item in the database
|
||||||
Delete {
|
Delete {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: BackendCommand,
|
command: DeleteCommand,
|
||||||
},
|
},
|
||||||
/// Create a toml backup of the database
|
/// Create a toml backup of the database
|
||||||
Backup {
|
Backup {
|
||||||
@@ -80,7 +107,12 @@ pub enum Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum BackendCommand {
|
pub enum AddCommand {
|
||||||
|
/// Use the flix backend
|
||||||
|
Flix {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: flix::AddCommand,
|
||||||
|
},
|
||||||
/// Use the TMDB backend
|
/// Use the TMDB backend
|
||||||
Tmdb {
|
Tmdb {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
@@ -88,7 +120,43 @@ pub enum BackendCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<tmdb::Command> for BackendCommand {
|
impl From<flix::AddCommand> for AddCommand {
|
||||||
|
fn from(value: flix::AddCommand) -> Self {
|
||||||
|
Self::Flix { command: value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<tmdb::Command> for AddCommand {
|
||||||
|
fn from(value: tmdb::Command) -> Self {
|
||||||
|
Self::Tmdb { command: value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum UpdateCommand {
|
||||||
|
/// Use the TMDB backend
|
||||||
|
Tmdb {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: tmdb::Command,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<tmdb::Command> for UpdateCommand {
|
||||||
|
fn from(value: tmdb::Command) -> Self {
|
||||||
|
Self::Tmdb { command: value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum DeleteCommand {
|
||||||
|
/// Use the TMDB backend
|
||||||
|
Tmdb {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: tmdb::Command,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<tmdb::Command> for DeleteCommand {
|
||||||
fn from(value: tmdb::Command) -> Self {
|
fn from(value: tmdb::Command) -> Self {
|
||||||
Self::Tmdb { command: value }
|
Self::Tmdb { command: value }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
//! Placeholder
|
|
||||||
|
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
|
||||||
+38
-19
@@ -1,17 +1,20 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use flix::tmdb::Client;
|
use flix::tmdb::{self, CachePolicy, Client, RedbCache};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
use cli::{BackendCommand, Cli, Command};
|
use cli::{AddCommand, Cli, Command, DeleteCommand, UpdateCommand};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
|
use crate::cli::AddOverrides;
|
||||||
|
|
||||||
mod db;
|
mod db;
|
||||||
mod run;
|
mod run;
|
||||||
|
|
||||||
@@ -26,11 +29,24 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
let database_path = cli.database_path()?;
|
let database_path = cli.database_path()?;
|
||||||
|
|
||||||
let client = Client::new(config.tmdb().bearer_token().to_owned());
|
let client = Client::new(
|
||||||
|
tmdb::Config::new(config.tmdb().bearer_token().to_owned()),
|
||||||
|
Rc::new(RedbCache::new(cli.cache_path())?),
|
||||||
|
CachePolicy::Full,
|
||||||
|
);
|
||||||
|
|
||||||
|
if cli.trace {
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_max_level(tracing::Level::DEBUG)
|
||||||
|
.with_test_writer()
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
match cli.command() {
|
match cli.command() {
|
||||||
Command::Init => exec_init(database_path).await?,
|
Command::Init => exec_init(database_path).await?,
|
||||||
Command::Add { command } => exec_add(client, database_path, command).await?,
|
Command::Add { command, overrides } => {
|
||||||
|
exec_add(client, database_path, command, overrides).await?
|
||||||
|
}
|
||||||
Command::Update { command } => exec_update(client, database_path, command).await?,
|
Command::Update { command } => exec_update(client, database_path, command).await?,
|
||||||
Command::Delete { command } => exec_delete(client, database_path, command).await?,
|
Command::Delete { command } => exec_delete(client, database_path, command).await?,
|
||||||
Command::Backup { output } => exec_backup(database_path, output).await?,
|
Command::Backup { output } => exec_backup(database_path, output).await?,
|
||||||
@@ -46,23 +62,31 @@ async fn exec_init(database_path: String) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn exec_add(client: Client, database_path: String, command: BackendCommand) -> Result<()> {
|
async fn exec_add(
|
||||||
|
client: Client,
|
||||||
|
database_path: String,
|
||||||
|
command: AddCommand,
|
||||||
|
overrides: AddOverrides,
|
||||||
|
) -> Result<()> {
|
||||||
let database = db::open(database_path).await?;
|
let database = db::open(database_path).await?;
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
BackendCommand::Tmdb { command } => {
|
AddCommand::Flix { command } => {
|
||||||
run::tmdb::add(client, database.as_ref(), command).await?;
|
run::flix::add(database.as_ref(), command, overrides).await?;
|
||||||
|
}
|
||||||
|
AddCommand::Tmdb { command } => {
|
||||||
|
run::tmdb::add(client, database.as_ref(), command, overrides).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn exec_update(client: Client, database_path: String, command: BackendCommand) -> Result<()> {
|
async fn exec_update(client: Client, database_path: String, command: UpdateCommand) -> Result<()> {
|
||||||
let database = db::open(database_path).await?;
|
let database = db::open(database_path).await?;
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
BackendCommand::Tmdb { command } => {
|
UpdateCommand::Tmdb { command } => {
|
||||||
run::tmdb::update(client, database.as_ref(), command).await?;
|
run::tmdb::update(client, database.as_ref(), command).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,16 +94,11 @@ async fn exec_update(client: Client, database_path: String, command: BackendComm
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn exec_delete(client: Client, database_path: String, command: BackendCommand) -> Result<()> {
|
async fn exec_delete(client: Client, database_path: String, command: DeleteCommand) -> Result<()> {
|
||||||
let database = db::open(database_path).await?;
|
_ = client;
|
||||||
|
_ = database_path;
|
||||||
match command {
|
_ = command;
|
||||||
BackendCommand::Tmdb { command } => {
|
unimplemented!()
|
||||||
run::tmdb::delete(client, database.as_ref(), command).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn exec_backup(database_path: String, output: PathBuf) -> Result<()> {
|
async fn exec_backup(database_path: String, output: PathBuf) -> Result<()> {
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
use flix::db::entity;
|
||||||
|
use flix::model::id::{CollectionId, ShowId};
|
||||||
|
use flix::model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
use flix::model::text;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::{ActiveModelTrait, DatabaseConnection, DbErr, TransactionError, TransactionTrait};
|
||||||
|
|
||||||
|
use crate::cli::AddOverrides;
|
||||||
|
use crate::cli::flix::AddCommand;
|
||||||
|
|
||||||
|
pub async fn add(
|
||||||
|
db: &DatabaseConnection,
|
||||||
|
command: AddCommand,
|
||||||
|
overrides: AddOverrides,
|
||||||
|
) -> Result<()> {
|
||||||
|
match command {
|
||||||
|
AddCommand::Collection { title, overview } => {
|
||||||
|
let result: Result<CollectionId, TransactionError<DbErr>> = db
|
||||||
|
.transaction(|txn| {
|
||||||
|
let title = overrides.title.unwrap_or_else(|| title.clone());
|
||||||
|
|
||||||
|
let sort_title = overrides
|
||||||
|
.sort_title
|
||||||
|
.unwrap_or_else(|| text::make_sortable_title(&title));
|
||||||
|
let fs_slug = overrides
|
||||||
|
.fs_slug
|
||||||
|
.unwrap_or_else(|| text::make_fs_slug(&title));
|
||||||
|
let web_slug = overrides
|
||||||
|
.web_slug
|
||||||
|
.unwrap_or_else(|| text::make_web_slug(&title));
|
||||||
|
|
||||||
|
Box::pin(async move {
|
||||||
|
let flix = entity::info::collections::ActiveModel {
|
||||||
|
id: NotSet,
|
||||||
|
title: Set(title),
|
||||||
|
overview: Set(overview),
|
||||||
|
sort_title: Set(sort_title),
|
||||||
|
fs_slug: Set(fs_slug),
|
||||||
|
web_slug: Set(web_slug),
|
||||||
|
}
|
||||||
|
.insert(txn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(flix.id)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let flix_id = match result {
|
||||||
|
Ok(id) => id,
|
||||||
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
|
};
|
||||||
|
println!("Created Collection: {} [{}]", title, flix_id.into_raw());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
AddCommand::Episode {
|
||||||
|
show_slug,
|
||||||
|
season_number,
|
||||||
|
episode_number,
|
||||||
|
title,
|
||||||
|
overview,
|
||||||
|
air_date,
|
||||||
|
} => {
|
||||||
|
let result: Result<(ShowId, SeasonNumber, EpisodeNumber), TransactionError<DbErr>> = db
|
||||||
|
.transaction(|txn| {
|
||||||
|
let title = overrides.title.unwrap_or_else(|| title.clone());
|
||||||
|
|
||||||
|
Box::pin(async move {
|
||||||
|
let show = entity::info::shows::Entity::find_by_web_slug(&show_slug)
|
||||||
|
.one(txn)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
DbErr::Custom(format!("show '{}' does not exist", show_slug))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let flix = entity::info::episodes::ActiveModel {
|
||||||
|
show_id: Set(show.id),
|
||||||
|
season_number: Set(season_number),
|
||||||
|
episode_number: Set(episode_number),
|
||||||
|
title: Set(title),
|
||||||
|
overview: Set(overview),
|
||||||
|
date: Set(air_date),
|
||||||
|
}
|
||||||
|
.insert(txn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok((flix.show_id, flix.season_number, flix.episode_number))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let (flix_show, season_number, episode_number) = match result {
|
||||||
|
Ok(id) => id,
|
||||||
|
Err(TransactionError::Connection(err)) => Err(err)?,
|
||||||
|
Err(TransactionError::Transaction(err)) => Err(err)?,
|
||||||
|
};
|
||||||
|
println!(
|
||||||
|
"Created Episode: {} [{} S{} E{}]",
|
||||||
|
title,
|
||||||
|
flix_show.into_raw(),
|
||||||
|
season_number,
|
||||||
|
episode_number
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
|
pub mod flix;
|
||||||
pub mod tmdb;
|
pub mod tmdb;
|
||||||
|
|||||||
+111
-42
@@ -3,21 +3,28 @@ use std::collections::HashMap;
|
|||||||
use flix::db::entity;
|
use flix::db::entity;
|
||||||
use flix::model::id::{CollectionId, MovieId, ShowId};
|
use flix::model::id::{CollectionId, MovieId, ShowId};
|
||||||
use flix::model::numbers::{EpisodeNumber, SeasonNumber};
|
use flix::model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
use flix::model::text;
|
||||||
use flix::tmdb::Client;
|
use flix::tmdb::Client;
|
||||||
use flix::tmdb::model::id::{
|
use flix::tmdb::model::id::{
|
||||||
CollectionId as TmdbCollectionId, MovieId as TmdbMovieId, ShowId as TmdbShowId,
|
CollectionId as TmdbCollectionId, MovieId as TmdbMovieId, ShowId as TmdbShowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use chrono::Utc;
|
use chrono::{Datelike, Utc};
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
ActiveModelTrait, DatabaseConnection, DbErr, EntityTrait, TransactionError, TransactionTrait,
|
ActiveModelTrait, DatabaseConnection, DbErr, EntityTrait, TransactionError, TransactionTrait,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::cli::AddOverrides;
|
||||||
use crate::cli::tmdb::Command;
|
use crate::cli::tmdb::Command;
|
||||||
|
|
||||||
pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> Result<()> {
|
pub async fn add(
|
||||||
|
client: Client,
|
||||||
|
db: &DatabaseConnection,
|
||||||
|
command: Command,
|
||||||
|
overrides: AddOverrides,
|
||||||
|
) -> Result<()> {
|
||||||
match command {
|
match command {
|
||||||
Command::Collection { id } => {
|
Command::Collection { id } => {
|
||||||
let id = TmdbCollectionId::from_raw(id);
|
let id = TmdbCollectionId::from_raw(id);
|
||||||
@@ -35,13 +42,29 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
.await
|
.await
|
||||||
.with_context(|| format!("collections().get_details({})", id.into_raw()))?;
|
.with_context(|| format!("collections().get_details({})", id.into_raw()))?;
|
||||||
|
|
||||||
|
let title = overrides.title.unwrap_or(collection.title);
|
||||||
|
|
||||||
|
let sort_title = overrides
|
||||||
|
.sort_title
|
||||||
|
.unwrap_or_else(|| text::make_sortable_title(&title));
|
||||||
|
let fs_slug = overrides
|
||||||
|
.fs_slug
|
||||||
|
.unwrap_or_else(|| text::make_fs_slug(&title));
|
||||||
|
let web_slug = overrides
|
||||||
|
.web_slug
|
||||||
|
.unwrap_or_else(|| text::make_web_slug(&title));
|
||||||
|
|
||||||
let result: Result<CollectionId, TransactionError<DbErr>> = db
|
let result: Result<CollectionId, TransactionError<DbErr>> = db
|
||||||
.transaction(|txn| {
|
.transaction(|txn| {
|
||||||
|
let title = title.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let flix = entity::info::collections::ActiveModel {
|
let flix = entity::info::collections::ActiveModel {
|
||||||
id: NotSet,
|
id: NotSet,
|
||||||
title: Set(collection.title),
|
title: Set(title),
|
||||||
overview: Set(collection.overview),
|
overview: Set(collection.overview),
|
||||||
|
sort_title: Set(sort_title),
|
||||||
|
fs_slug: Set(fs_slug),
|
||||||
|
web_slug: Set(web_slug),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -49,7 +72,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
entity::tmdb::collections::ActiveModel {
|
entity::tmdb::collections::ActiveModel {
|
||||||
tmdb_id: Set(id),
|
tmdb_id: Set(id),
|
||||||
flix_id: Set(flix.id),
|
flix_id: Set(flix.id),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
movie_count: Set(collection.movies.len().try_into().unwrap_or(0)),
|
movie_count: Set(collection.movies.len().try_into().unwrap_or(0)),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
@@ -65,7 +88,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
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: {}", flix_id.into_raw());
|
println!("Created Collection: {} [{}]", title, flix_id.into_raw());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -83,15 +106,32 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
.await
|
.await
|
||||||
.with_context(|| format!("movies().get_details({})", id.into_raw()))?;
|
.with_context(|| format!("movies().get_details({})", id.into_raw()))?;
|
||||||
|
|
||||||
|
let title = overrides.title.unwrap_or(movie.title);
|
||||||
|
let year = movie.release_date.year();
|
||||||
|
|
||||||
|
let sort_title = overrides
|
||||||
|
.sort_title
|
||||||
|
.unwrap_or_else(|| text::make_sortable_title(&title));
|
||||||
|
let fs_slug = overrides
|
||||||
|
.fs_slug
|
||||||
|
.unwrap_or_else(|| text::make_fs_slug_year(&title, year));
|
||||||
|
let web_slug = overrides
|
||||||
|
.web_slug
|
||||||
|
.unwrap_or_else(|| text::make_web_slug_year(&title, year));
|
||||||
|
|
||||||
let result: Result<MovieId, TransactionError<DbErr>> = db
|
let result: Result<MovieId, TransactionError<DbErr>> = db
|
||||||
.transaction(|txn| {
|
.transaction(|txn| {
|
||||||
|
let title = title.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let flix = entity::info::movies::ActiveModel {
|
let flix = entity::info::movies::ActiveModel {
|
||||||
id: NotSet,
|
id: NotSet,
|
||||||
title: Set(movie.title),
|
title: Set(title),
|
||||||
tagline: Set(movie.tagline),
|
tagline: Set(movie.tagline),
|
||||||
overview: Set(movie.overview),
|
overview: Set(movie.overview),
|
||||||
date: Set(movie.release_date),
|
date: Set(movie.release_date),
|
||||||
|
sort_title: Set(sort_title),
|
||||||
|
fs_slug: Set(fs_slug),
|
||||||
|
web_slug: Set(web_slug),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -99,9 +139,9 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
entity::tmdb::movies::ActiveModel {
|
entity::tmdb::movies::ActiveModel {
|
||||||
tmdb_id: Set(id),
|
tmdb_id: Set(id),
|
||||||
flix_id: Set(flix.id),
|
flix_id: Set(flix.id),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
runtime: Set(movie.runtime.into()),
|
runtime: Set(movie.runtime.into()),
|
||||||
collection: Set(movie.collection.map(|c| c.id)),
|
collection_id: Set(movie.collection.map(|c| c.id)),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -116,7 +156,12 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
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 Movie: {}", flix_id.into_raw());
|
println!(
|
||||||
|
"Created Movie: {} ({}) [{}]",
|
||||||
|
title,
|
||||||
|
year,
|
||||||
|
flix_id.into_raw(),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -137,14 +182,21 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
let mut episodes = HashMap::new();
|
let mut episodes = HashMap::new();
|
||||||
|
|
||||||
for season in 1..=show.number_of_seasons {
|
for season in 1..=show.number_of_seasons {
|
||||||
let season = client
|
let season = SeasonNumber::new(season);
|
||||||
|
let season = match client
|
||||||
.seasons()
|
.seasons()
|
||||||
.get_details(id, season, None)
|
.get_details(id, season, None)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!("seasons().get_details({}, {})", id.into_raw(), season)
|
format!("seasons().get_details({}, {})", id.into_raw(), season)
|
||||||
})?;
|
}) {
|
||||||
if season.air_date > Utc::now().date_naive() {
|
Ok(season) => season,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{err:?}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if season.air_date > Utc::now().naive_utc().date() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"skipping season ({}, {})",
|
"skipping season ({}, {})",
|
||||||
id.into_raw(),
|
id.into_raw(),
|
||||||
@@ -153,7 +205,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Ok(number_of_episodes) = EpisodeNumber::try_from(season.episodes.len()) else {
|
let Ok(number_of_episodes) = u32::try_from(season.episodes.len()) else {
|
||||||
bail!(
|
bail!(
|
||||||
"could not convert {} to an EpisodeNumber",
|
"could not convert {} to an EpisodeNumber",
|
||||||
season.episodes.len()
|
season.episodes.len()
|
||||||
@@ -162,6 +214,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
|
|
||||||
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 Ok(episode) = client
|
let Ok(episode) = client
|
||||||
.episodes()
|
.episodes()
|
||||||
.get_details(id, season.season_number, episode, None)
|
.get_details(id, season.season_number, episode, None)
|
||||||
@@ -182,15 +235,32 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
seasons.push(season);
|
seasons.push(season);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let title = overrides.title.unwrap_or(show.title);
|
||||||
|
let year = show.first_air_date.year();
|
||||||
|
|
||||||
|
let sort_title = overrides
|
||||||
|
.sort_title
|
||||||
|
.unwrap_or_else(|| text::make_sortable_title(&title));
|
||||||
|
let fs_slug = overrides
|
||||||
|
.fs_slug
|
||||||
|
.unwrap_or_else(|| text::make_fs_slug_year(&title, year));
|
||||||
|
let web_slug = overrides
|
||||||
|
.web_slug
|
||||||
|
.unwrap_or_else(|| text::make_web_slug_year(&title, year));
|
||||||
|
|
||||||
let result: Result<ShowId, TransactionError<DbErr>> = db
|
let result: Result<ShowId, TransactionError<DbErr>> = db
|
||||||
.transaction(|txn| {
|
.transaction(|txn| {
|
||||||
|
let title = title.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let flix = entity::info::shows::ActiveModel {
|
let flix = entity::info::shows::ActiveModel {
|
||||||
id: NotSet,
|
id: NotSet,
|
||||||
title: Set(show.title),
|
title: Set(title),
|
||||||
tagline: Set(show.tagline),
|
tagline: Set(show.tagline),
|
||||||
overview: Set(show.overview),
|
overview: Set(show.overview),
|
||||||
date: Set(show.first_air_date),
|
date: Set(show.first_air_date),
|
||||||
|
sort_title: Set(sort_title),
|
||||||
|
fs_slug: Set(fs_slug),
|
||||||
|
web_slug: Set(web_slug),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -198,7 +268,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
entity::tmdb::shows::ActiveModel {
|
entity::tmdb::shows::ActiveModel {
|
||||||
tmdb_id: Set(id),
|
tmdb_id: Set(id),
|
||||||
flix_id: Set(flix.id),
|
flix_id: Set(flix.id),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
number_of_seasons: Set(show.number_of_seasons),
|
number_of_seasons: Set(show.number_of_seasons),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
@@ -206,8 +276,8 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
|
|
||||||
for season in seasons {
|
for season in seasons {
|
||||||
entity::info::seasons::ActiveModel {
|
entity::info::seasons::ActiveModel {
|
||||||
show: Set(flix.id),
|
show_id: Set(flix.id),
|
||||||
season: Set(season.season_number),
|
season_number: Set(season.season_number),
|
||||||
title: Set(season.title),
|
title: Set(season.title),
|
||||||
overview: Set(season.overview),
|
overview: Set(season.overview),
|
||||||
date: Set(season.air_date),
|
date: Set(season.air_date),
|
||||||
@@ -220,7 +290,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
tmdb_season: Set(season.season_number),
|
tmdb_season: Set(season.season_number),
|
||||||
flix_show: Set(flix.id),
|
flix_show: Set(flix.id),
|
||||||
flix_season: Set(season.season_number),
|
flix_season: Set(season.season_number),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -229,9 +299,9 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
for (season, episodes) in episodes {
|
for (season, episodes) in episodes {
|
||||||
for episode in episodes {
|
for episode in episodes {
|
||||||
entity::info::episodes::ActiveModel {
|
entity::info::episodes::ActiveModel {
|
||||||
show: Set(flix.id),
|
show_id: Set(flix.id),
|
||||||
season: Set(season),
|
season_number: Set(season),
|
||||||
episode: Set(episode.episode_number),
|
episode_number: Set(episode.episode_number),
|
||||||
title: Set(episode.title),
|
title: Set(episode.title),
|
||||||
overview: Set(episode.overview),
|
overview: Set(episode.overview),
|
||||||
date: Set(episode.air_date),
|
date: Set(episode.air_date),
|
||||||
@@ -246,7 +316,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
flix_show: Set(flix.id),
|
flix_show: Set(flix.id),
|
||||||
flix_season: Set(season),
|
flix_season: Set(season),
|
||||||
flix_episode: Set(episode.episode_number),
|
flix_episode: Set(episode.episode_number),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
runtime: Set(episode.runtime.into()),
|
runtime: Set(episode.runtime.into()),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
@@ -264,7 +334,12 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
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 Show: {}", flix_id.into_raw());
|
println!(
|
||||||
|
"Created Show: {} ({}) [{}]",
|
||||||
|
title,
|
||||||
|
year,
|
||||||
|
flix_id.into_raw()
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -296,7 +371,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
})?;
|
})?;
|
||||||
let mut episodes = Vec::new();
|
let mut episodes = Vec::new();
|
||||||
|
|
||||||
let Ok(number_of_episodes) = EpisodeNumber::try_from(season.episodes.len()) else {
|
let Ok(number_of_episodes) = u32::try_from(season.episodes.len()) else {
|
||||||
bail!(
|
bail!(
|
||||||
"could not convert {} to an EpisodeNumber",
|
"could not convert {} to an EpisodeNumber",
|
||||||
season.episodes.len()
|
season.episodes.len()
|
||||||
@@ -304,6 +379,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
};
|
};
|
||||||
|
|
||||||
for episode in 1..=number_of_episodes {
|
for episode in 1..=number_of_episodes {
|
||||||
|
let episode = EpisodeNumber::new(episode);
|
||||||
let Ok(episode) = client
|
let Ok(episode) = client
|
||||||
.episodes()
|
.episodes()
|
||||||
.get_details(id, season.season_number, episode, None)
|
.get_details(id, season.season_number, episode, None)
|
||||||
@@ -324,8 +400,8 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
.transaction(|txn| {
|
.transaction(|txn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
entity::info::seasons::ActiveModel {
|
entity::info::seasons::ActiveModel {
|
||||||
show: Set(show.flix_id),
|
show_id: Set(show.flix_id),
|
||||||
season: Set(season_number),
|
season_number: Set(season_number),
|
||||||
title: Set(season.title),
|
title: Set(season.title),
|
||||||
overview: Set(season.overview),
|
overview: Set(season.overview),
|
||||||
date: Set(season.air_date),
|
date: Set(season.air_date),
|
||||||
@@ -338,16 +414,16 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
tmdb_season: Set(season_number),
|
tmdb_season: Set(season_number),
|
||||||
flix_show: Set(show.flix_id),
|
flix_show: Set(show.flix_id),
|
||||||
flix_season: Set(season_number),
|
flix_season: Set(season_number),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for episode in episodes {
|
for episode in episodes {
|
||||||
entity::info::episodes::ActiveModel {
|
entity::info::episodes::ActiveModel {
|
||||||
show: Set(show.flix_id),
|
show_id: Set(show.flix_id),
|
||||||
season: Set(season_number),
|
season_number: Set(season_number),
|
||||||
episode: Set(episode.episode_number),
|
episode_number: Set(episode.episode_number),
|
||||||
title: Set(episode.title),
|
title: Set(episode.title),
|
||||||
overview: Set(episode.overview),
|
overview: Set(episode.overview),
|
||||||
date: Set(episode.air_date),
|
date: Set(episode.air_date),
|
||||||
@@ -362,7 +438,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
flix_show: Set(show.flix_id),
|
flix_show: Set(show.flix_id),
|
||||||
flix_season: Set(season_number),
|
flix_season: Set(season_number),
|
||||||
flix_episode: Set(episode.episode_number),
|
flix_episode: Set(episode.episode_number),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
runtime: Set(episode.runtime.into()),
|
runtime: Set(episode.runtime.into()),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
@@ -436,9 +512,9 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
.transaction(|txn| {
|
.transaction(|txn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
entity::info::episodes::ActiveModel {
|
entity::info::episodes::ActiveModel {
|
||||||
show: Set(flix_id),
|
show_id: Set(flix_id),
|
||||||
season: Set(season),
|
season_number: Set(season),
|
||||||
episode: Set(episode_number),
|
episode_number: Set(episode_number),
|
||||||
title: Set(episode.title),
|
title: Set(episode.title),
|
||||||
overview: Set(episode.overview),
|
overview: Set(episode.overview),
|
||||||
date: Set(episode.air_date),
|
date: Set(episode.air_date),
|
||||||
@@ -453,7 +529,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
|
|||||||
flix_show: Set(flix_id),
|
flix_show: Set(flix_id),
|
||||||
flix_season: Set(season),
|
flix_season: Set(season),
|
||||||
flix_episode: Set(episode_number),
|
flix_episode: Set(episode_number),
|
||||||
last_update: Set(Utc::now().date_naive()),
|
last_update: Set(Utc::now()),
|
||||||
runtime: Set(episode.runtime.into()),
|
runtime: Set(episode.runtime.into()),
|
||||||
}
|
}
|
||||||
.insert(txn)
|
.insert(txn)
|
||||||
@@ -498,10 +574,3 @@ pub async fn update(client: Client, database: &DatabaseConnection, command: Comm
|
|||||||
_ = command;
|
_ = command;
|
||||||
unimplemented!("updates")
|
unimplemented!("updates")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(client: Client, database: &DatabaseConnection, command: Command) -> Result<()> {
|
|
||||||
_ = client;
|
|
||||||
_ = database;
|
|
||||||
_ = command;
|
|
||||||
unimplemented!("deletions")
|
|
||||||
}
|
|
||||||
|
|||||||
+24
-26
@@ -1,41 +1,39 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-db"
|
name = "flix-db"
|
||||||
version = "0.0.12"
|
version = "0.0.17"
|
||||||
|
edition.workspace = true
|
||||||
categories = []
|
rust-version.workspace = true
|
||||||
description = "Types for storing persistent data about media"
|
description = "Types for storing persistent data about media"
|
||||||
repository = "https://github.com/QuantumShade/flix"
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
rust-version.workspace = true
|
categories = []
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[lints]
|
[dependencies]
|
||||||
workspace = true
|
chrono = { workspace = true }
|
||||||
|
flix-model = { workspace = true }
|
||||||
|
flix-tmdb = { workspace = true, features = ["sea-orm"], optional = true }
|
||||||
|
sea-orm = { workspace = true, features = [
|
||||||
|
"entity-registry",
|
||||||
|
"schema-sync",
|
||||||
|
"with-chrono",
|
||||||
|
] }
|
||||||
|
sea-orm-migration = { workspace = true }
|
||||||
|
seamantic = { workspace = true, features = ["sqlite"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
sea-orm-migration = { workspace = true, features = ["runtime-tokio-rustls"] }
|
||||||
|
tokio = { version = "^1", default-features = false, features = [
|
||||||
|
"macros",
|
||||||
|
"rt",
|
||||||
|
] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
tmdb = ["dep:flix-tmdb"]
|
tmdb = ["dep:flix-tmdb"]
|
||||||
|
|
||||||
[dependencies]
|
[lints]
|
||||||
flix-model = { workspace = true }
|
workspace = true
|
||||||
|
|
||||||
flix-tmdb = { workspace = true, optional = true, features = ["sea-orm"] }
|
|
||||||
|
|
||||||
seamantic = { workspace = true, features = ["sqlite"] }
|
|
||||||
|
|
||||||
chrono = { workspace = true }
|
|
||||||
sea-orm = { workspace = true, features = ["with-chrono"] }
|
|
||||||
sea-orm-migration = { workspace = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
sea-orm-migration = { workspace = true, features = ["runtime-tokio-rustls"] }
|
|
||||||
tokio = { version = "^1", default-features = false, features = [
|
|
||||||
"rt",
|
|
||||||
"macros",
|
|
||||||
] }
|
|
||||||
|
|||||||
@@ -9,9 +9,12 @@ pub struct Connection(DatabaseConnection);
|
|||||||
impl Connection {
|
impl Connection {
|
||||||
/// Helper function for applying database migrations while wrapping a
|
/// Helper function for applying database migrations while wrapping a
|
||||||
/// [DatabaseConnection] in a newtype
|
/// [DatabaseConnection] in a newtype
|
||||||
pub async fn try_from(database: DatabaseConnection) -> Result<Self, DbErr> {
|
pub async fn try_from(db: DatabaseConnection) -> Result<Self, DbErr> {
|
||||||
crate::migration::Migrator::up(&database, None).await?;
|
crate::migration::Migrator::down(&db, None).await?;
|
||||||
Ok(Self(database))
|
db.get_schema_registry("flix_db::*").sync(&db).await?;
|
||||||
|
db.get_schema_registry("flix_db::*").sync(&db).await?;
|
||||||
|
crate::migration::Migrator::up(&db, None).await?;
|
||||||
|
Ok(Self(db))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,3 +23,10 @@ impl AsRef<DatabaseConnection> for Connection {
|
|||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl Connection {
|
||||||
|
pub(crate) fn take(self) -> DatabaseConnection {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,882 @@
|
|||||||
|
//! This module contains entities for storing media file information
|
||||||
|
|
||||||
|
/// Library entity
|
||||||
|
pub mod libraries {
|
||||||
|
use flix_model::id::LibraryId;
|
||||||
|
|
||||||
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
/// The database representation of a library media folder
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_libraries")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The library's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: LibraryId,
|
||||||
|
/// The library's directory
|
||||||
|
pub directory: PathBytes,
|
||||||
|
/// The library's last scan data
|
||||||
|
pub last_scan: Option<DateTime<Utc>>,
|
||||||
|
|
||||||
|
/// Collections that are part of this library
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub collections: HasMany<super::collections::Entity>,
|
||||||
|
/// Movies that are part of this library
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub movies: HasMany<super::movies::Entity>,
|
||||||
|
/// Shows that are part of this library
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub shows: HasMany<super::shows::Entity>,
|
||||||
|
/// Seasons that are part of this library
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub seasons: HasMany<super::seasons::Entity>,
|
||||||
|
/// Episodes that are part of this library
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Collection entity
|
||||||
|
pub mod collections {
|
||||||
|
use flix_model::id::{CollectionId, LibraryId};
|
||||||
|
|
||||||
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a collection media folder
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_collections")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The collection's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: CollectionId,
|
||||||
|
/// The collection's parent
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub parent_id: Option<CollectionId>,
|
||||||
|
/// The collection's library ID
|
||||||
|
pub library_id: LibraryId,
|
||||||
|
/// The collection's directory
|
||||||
|
pub directory: PathBytes,
|
||||||
|
/// The collection's poster path
|
||||||
|
pub relative_poster_path: Option<String>,
|
||||||
|
|
||||||
|
/// This collection's parent
|
||||||
|
#[sea_orm(
|
||||||
|
self_ref,
|
||||||
|
relation_enum = "Parent",
|
||||||
|
from = "parent_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub parent: HasOne<Entity>,
|
||||||
|
/// The library this collection belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "library_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub library: HasOne<super::libraries::Entity>,
|
||||||
|
/// The info for this collection
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::collections::Entity>,
|
||||||
|
|
||||||
|
/// The watched info for this collection
|
||||||
|
#[sea_orm(has_many, relation_enum = "Watched", from = "id", to = "id")]
|
||||||
|
pub watched: HasMany<entity::watched::collections::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Movie entity
|
||||||
|
pub mod movies {
|
||||||
|
use flix_model::id::{CollectionId, LibraryId, MovieId};
|
||||||
|
|
||||||
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a movie media folder
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_movies")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The movie's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: MovieId,
|
||||||
|
/// The movie's parent
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub parent_id: Option<CollectionId>,
|
||||||
|
/// The movie's library
|
||||||
|
pub library_id: LibraryId,
|
||||||
|
/// The movie's directory
|
||||||
|
pub directory: PathBytes,
|
||||||
|
/// The movie's media path
|
||||||
|
pub relative_media_path: String,
|
||||||
|
/// The movie's poster path
|
||||||
|
pub relative_poster_path: Option<String>,
|
||||||
|
|
||||||
|
/// This movie's parent
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "parent_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub parent: HasOne<super::collections::Entity>,
|
||||||
|
/// The library this movie belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "library_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub library: HasOne<super::libraries::Entity>,
|
||||||
|
/// The info for this movie
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::movies::Entity>,
|
||||||
|
|
||||||
|
/// The watched info for this movie
|
||||||
|
#[sea_orm(has_many, relation_enum = "Watched", from = "id", to = "id")]
|
||||||
|
pub watched: HasMany<entity::watched::movies::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Show entity
|
||||||
|
pub mod shows {
|
||||||
|
use flix_model::id::{CollectionId, LibraryId, ShowId};
|
||||||
|
|
||||||
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a show media folder
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_shows")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: ShowId,
|
||||||
|
/// The show's parent
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub parent_id: Option<CollectionId>,
|
||||||
|
/// The show's library
|
||||||
|
pub library_id: LibraryId,
|
||||||
|
/// The show's directory
|
||||||
|
pub directory: PathBytes,
|
||||||
|
/// The show's poster path
|
||||||
|
pub relative_poster_path: Option<String>,
|
||||||
|
|
||||||
|
/// This show's parent
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "parent_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub parent: HasOne<super::collections::Entity>,
|
||||||
|
/// The library this show belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "library_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub library: HasOne<super::libraries::Entity>,
|
||||||
|
/// The info for this show
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::shows::Entity>,
|
||||||
|
|
||||||
|
/// Seasons that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub seasons: HasMany<super::seasons::Entity>,
|
||||||
|
/// Episodes that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
/// The watched info for this show
|
||||||
|
#[sea_orm(has_many, relation_enum = "Watched", from = "id", to = "id")]
|
||||||
|
pub watched: HasMany<entity::watched::shows::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Season entity
|
||||||
|
pub mod seasons {
|
||||||
|
use flix_model::id::{LibraryId, ShowId};
|
||||||
|
use flix_model::numbers::SeasonNumber;
|
||||||
|
|
||||||
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a season media folder
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_seasons")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The season's show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub show_id: ShowId,
|
||||||
|
/// The season's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub season_number: SeasonNumber,
|
||||||
|
/// The season's library
|
||||||
|
pub library_id: LibraryId,
|
||||||
|
/// The season's directory
|
||||||
|
pub directory: PathBytes,
|
||||||
|
/// The season's poster path
|
||||||
|
pub relative_poster_path: Option<String>,
|
||||||
|
|
||||||
|
/// This season's show
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "show_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub show: HasOne<super::shows::Entity>,
|
||||||
|
/// The library this season belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "library_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub library: HasOne<super::libraries::Entity>,
|
||||||
|
/// The info for this season
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "(show_id, season_number)",
|
||||||
|
to = "(show_id, season_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::seasons::Entity>,
|
||||||
|
|
||||||
|
/// Episodes that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
/// The watched info for this season
|
||||||
|
#[sea_orm(
|
||||||
|
has_many,
|
||||||
|
relation_enum = "Watched",
|
||||||
|
from = "(show_id, season_number)",
|
||||||
|
to = "(show_id, season_number)"
|
||||||
|
)]
|
||||||
|
pub watched: HasMany<entity::watched::seasons::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Episode entity
|
||||||
|
pub mod episodes {
|
||||||
|
use flix_model::id::{LibraryId, ShowId};
|
||||||
|
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
|
||||||
|
use seamantic::model::path::PathBytes;
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a episode media folder
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_episodes")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The episode's show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub show_id: ShowId,
|
||||||
|
/// The episode's season's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub season_number: SeasonNumber,
|
||||||
|
/// The episode's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub episode_number: EpisodeNumber,
|
||||||
|
/// The number of additional contained episodes
|
||||||
|
pub count: u8,
|
||||||
|
/// The episode's library
|
||||||
|
pub library_id: LibraryId,
|
||||||
|
/// The episode's directory
|
||||||
|
pub directory: PathBytes,
|
||||||
|
/// The episode's media path
|
||||||
|
pub relative_media_path: String,
|
||||||
|
/// The episode's poster path
|
||||||
|
pub relative_poster_path: Option<String>,
|
||||||
|
|
||||||
|
/// This episode's show
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "show_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub show: HasOne<super::shows::Entity>,
|
||||||
|
/// This episode's season
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "(show_id, season_number)",
|
||||||
|
to = "(show_id, season_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub season: HasOne<super::seasons::Entity>,
|
||||||
|
/// The library this episode belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "library_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub library: HasOne<super::libraries::Entity>,
|
||||||
|
/// The info for this episode
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "(show_id, season_number, episode_number)",
|
||||||
|
to = "(show_id, season_number, episode_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::episodes::Entity>,
|
||||||
|
|
||||||
|
/// The watched info for this episode
|
||||||
|
#[sea_orm(
|
||||||
|
has_many,
|
||||||
|
relation_enum = "Watched",
|
||||||
|
from = "(show_id, season_number, episode_number)",
|
||||||
|
to = "(show_id, season_number, episode_number)"
|
||||||
|
)]
|
||||||
|
pub watched: HasMany<entity::watched::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Macros for creating content entities
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod test {
|
||||||
|
macro_rules! make_content_library {
|
||||||
|
($db:expr, $id:expr) => {
|
||||||
|
$crate::entity::content::libraries::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::LibraryId::from_raw($id)),
|
||||||
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
|
last_scan: Set(None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_content_library;
|
||||||
|
|
||||||
|
macro_rules! make_content_collection {
|
||||||
|
($db:expr, $lid:expr, $id:expr, $pid:expr) => {
|
||||||
|
$crate::entity::info::test::make_info_collection!($db, $id);
|
||||||
|
$crate::entity::content::collections::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::CollectionId::from_raw($id)),
|
||||||
|
parent_id: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
|
||||||
|
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
|
||||||
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
|
relative_poster_path: Set(::core::option::Option::None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_content_collection;
|
||||||
|
|
||||||
|
macro_rules! make_content_movie {
|
||||||
|
($db:expr, $lid:expr, $id:expr, $pid:expr) => {
|
||||||
|
$crate::entity::info::test::make_info_movie!($db, $id);
|
||||||
|
$crate::entity::content::movies::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::MovieId::from_raw($id)),
|
||||||
|
parent_id: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
|
||||||
|
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
|
||||||
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
|
relative_media_path: Set(::std::string::String::new()),
|
||||||
|
relative_poster_path: Set(::core::option::Option::None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_content_movie;
|
||||||
|
|
||||||
|
macro_rules! make_content_show {
|
||||||
|
($db:expr, $lid:expr, $id:expr, $pid:expr) => {
|
||||||
|
$crate::entity::info::test::make_info_show!($db, $id);
|
||||||
|
$crate::entity::content::shows::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::ShowId::from_raw($id)),
|
||||||
|
parent_id: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
|
||||||
|
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
|
||||||
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
|
relative_poster_path: Set(::core::option::Option::None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_content_show;
|
||||||
|
|
||||||
|
macro_rules! make_content_season {
|
||||||
|
($db:expr, $lid:expr, $show:expr, $season:expr) => {
|
||||||
|
$crate::entity::info::test::make_info_season!($db, $show, $season);
|
||||||
|
$crate::entity::content::seasons::ActiveModel {
|
||||||
|
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
|
||||||
|
season_number: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
|
||||||
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
|
relative_poster_path: Set(::core::option::Option::None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_content_season;
|
||||||
|
|
||||||
|
macro_rules! make_content_episode {
|
||||||
|
($db:expr, $lid:expr, $show:expr, $season:expr, $episode:expr) => {
|
||||||
|
make_content_episode!(@make, $db, $lid, $show, $season, $episode, 0);
|
||||||
|
};
|
||||||
|
($db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal, >1) => {
|
||||||
|
make_content_episode!(@make, $db, $lid, $show, $season, $episode, 1);
|
||||||
|
};
|
||||||
|
(@make, $db:expr, $lid:expr, $show:expr, $season:expr, $episode:expr, $count:literal) => {
|
||||||
|
$crate::entity::info::test::make_info_episode!($db, $show, $season, $episode);
|
||||||
|
$crate::entity::content::episodes::ActiveModel {
|
||||||
|
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
|
||||||
|
season_number: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
episode_number: Set(::flix_model::numbers::EpisodeNumber::new($episode)),
|
||||||
|
count: Set($count),
|
||||||
|
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
|
||||||
|
directory: Set(::std::path::PathBuf::new().into()),
|
||||||
|
relative_media_path: Set(::std::string::String::new()),
|
||||||
|
relative_poster_path: Set(::core::option::Option::None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_content_episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use sea_orm::sqlx::error::ErrorKind;
|
||||||
|
|
||||||
|
use crate::entity::content::test::{
|
||||||
|
make_content_collection, make_content_episode, make_content_library, make_content_movie,
|
||||||
|
make_content_season, make_content_show,
|
||||||
|
};
|
||||||
|
use crate::entity::info::test::{
|
||||||
|
make_info_collection, make_info_episode, make_info_movie, make_info_season, make_info_show,
|
||||||
|
};
|
||||||
|
use crate::tests::new_initialized_memory_db;
|
||||||
|
|
||||||
|
use super::super::tests::get_error_kind;
|
||||||
|
use super::super::tests::{noneable, notsettable};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn use_test_macros() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
make_content_collection!(&db, 1, 1, None);
|
||||||
|
make_content_movie!(&db, 1, 1, None);
|
||||||
|
make_content_show!(&db, 1, 1, None);
|
||||||
|
make_content_season!(&db, 1, 1, 1);
|
||||||
|
make_content_episode!(&db, 1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_libraries() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_library {
|
||||||
|
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, LibraryId::from_raw($id));
|
||||||
|
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),+)?));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::libraries::ActiveModel {
|
||||||
|
id: notsettable!(id, LibraryId::from_raw($id) $(, $($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),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_library!(&db, 1, Success);
|
||||||
|
assert_library!(&db, 1, UniqueViolation);
|
||||||
|
assert_library!(&db, 2, Success);
|
||||||
|
assert_library!(&db, 3, Success; id);
|
||||||
|
assert_library!(&db, 4, NotNullViolation; directory);
|
||||||
|
assert_library!(&db, 5, Success; last_scan);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_collections() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_collection {
|
||||||
|
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, CollectionId::from_raw($id));
|
||||||
|
assert_eq!(model.parent_id, $pid.map(CollectionId::from_raw));
|
||||||
|
assert_eq!(model.library_id, LibraryId::from_raw($lid));
|
||||||
|
assert_eq!(model.directory, Path::new(concat!("C Directory ", $id)).to_owned().into());
|
||||||
|
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("C Poster ", $id).to_owned() $(, $($skip),+)?));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::collections::ActiveModel {
|
||||||
|
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
parent_id: notsettable!(parent_id, $pid.map(CollectionId::from_raw) $(, $($skip),+)?),
|
||||||
|
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
||||||
|
directory: notsettable!(directory, Path::new(concat!("C Directory ", $id)).to_owned().into() $(, $($skip),+)?),
|
||||||
|
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("C Poster ", $id).to_owned()) $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
assert_collection!(&db, 1, None, 1, ForeignKeyViolation);
|
||||||
|
make_info_collection!(&db, 1);
|
||||||
|
assert_collection!(&db, 1, None, 1, Success);
|
||||||
|
make_info_collection!(&db, 2);
|
||||||
|
assert_collection!(&db, 2, None, 2, ForeignKeyViolation);
|
||||||
|
make_content_library!(&db, 2);
|
||||||
|
assert_collection!(&db, 2, None, 2, Success);
|
||||||
|
|
||||||
|
assert_collection!(&db, 1, None, 1, UniqueViolation);
|
||||||
|
make_info_collection!(&db, 3);
|
||||||
|
make_info_collection!(&db, 4);
|
||||||
|
make_info_collection!(&db, 5);
|
||||||
|
make_info_collection!(&db, 6);
|
||||||
|
make_info_collection!(&db, 7);
|
||||||
|
make_info_collection!(&db, 8);
|
||||||
|
assert_collection!(&db, 3, None, 1, Success; id);
|
||||||
|
assert_collection!(&db, 4, None, 1, Success; parent_id);
|
||||||
|
assert_collection!(&db, 5, None, 1, NotNullViolation; library_id);
|
||||||
|
assert_collection!(&db, 6, None, 1, NotNullViolation; directory);
|
||||||
|
assert_collection!(&db, 7, None, 1, Success; relative_poster_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_movies() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_movie {
|
||||||
|
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, MovieId::from_raw($id));
|
||||||
|
assert_eq!(model.parent_id, $pid.map(CollectionId::from_raw));
|
||||||
|
assert_eq!(model.library_id, LibraryId::from_raw($lid));
|
||||||
|
assert_eq!(model.directory, Path::new(concat!("M Directory ", $id)).to_owned().into());
|
||||||
|
assert_eq!(model.relative_media_path, concat!("M Media ", $id));
|
||||||
|
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("M Poster ", $id).to_owned() $(, $($skip),+)?));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::movies::ActiveModel {
|
||||||
|
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
parent_id: notsettable!(parent_id, $pid.map(CollectionId::from_raw) $(, $($skip),+)?),
|
||||||
|
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
||||||
|
directory: notsettable!(directory, Path::new(concat!("M Directory ", $id)).to_owned().into() $(, $($skip),+)?),
|
||||||
|
relative_media_path: notsettable!(relative_media_path, concat!("M Media ", $id).to_owned() $(, $($skip),+)?),
|
||||||
|
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("M Poster ", $id).to_owned()) $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
assert_movie!(&db, 1, None, 1, ForeignKeyViolation);
|
||||||
|
make_info_movie!(&db, 1);
|
||||||
|
assert_movie!(&db, 1, Some(1), 1, ForeignKeyViolation);
|
||||||
|
make_content_collection!(&db, 1, 1, None);
|
||||||
|
assert_movie!(&db, 1, Some(1), 1, Success);
|
||||||
|
assert_movie!(&db, 2, None, 2, ForeignKeyViolation);
|
||||||
|
make_info_movie!(&db, 2);
|
||||||
|
assert_movie!(&db, 2, None, 2, ForeignKeyViolation);
|
||||||
|
make_content_library!(&db, 2);
|
||||||
|
assert_movie!(&db, 2, None, 2, Success);
|
||||||
|
|
||||||
|
assert_movie!(&db, 1, None, 1, UniqueViolation);
|
||||||
|
make_info_movie!(&db, 3);
|
||||||
|
make_info_movie!(&db, 4);
|
||||||
|
make_info_movie!(&db, 5);
|
||||||
|
make_info_movie!(&db, 6);
|
||||||
|
make_info_movie!(&db, 7);
|
||||||
|
make_info_movie!(&db, 8);
|
||||||
|
make_info_movie!(&db, 9);
|
||||||
|
assert_movie!(&db, 3, None, 1, Success; id);
|
||||||
|
assert_movie!(&db, 4, None, 1, Success; parent_id);
|
||||||
|
assert_movie!(&db, 5, None, 1, NotNullViolation; library_id);
|
||||||
|
assert_movie!(&db, 6, None, 1, NotNullViolation; directory);
|
||||||
|
assert_movie!(&db, 7, None, 1, NotNullViolation; relative_media_path);
|
||||||
|
assert_movie!(&db, 8, None, 1, Success; relative_poster_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_shows() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_show {
|
||||||
|
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, ShowId::from_raw($id));
|
||||||
|
assert_eq!(model.parent_id, $pid.map(CollectionId::from_raw));
|
||||||
|
assert_eq!(model.library_id, LibraryId::from_raw($lid));
|
||||||
|
assert_eq!(model.directory, Path::new(concat!("S Directory ", $id)).to_owned().into());
|
||||||
|
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S Poster ", $id).to_owned() $(, $($skip),+)?));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::shows::ActiveModel {
|
||||||
|
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
parent_id: notsettable!(parent_id, $pid.map(CollectionId::from_raw) $(, $($skip),+)?),
|
||||||
|
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
||||||
|
directory: notsettable!(directory, Path::new(concat!("S Directory ", $id)).to_owned().into() $(, $($skip),+)?),
|
||||||
|
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S Poster ", $id).to_owned()) $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
assert_show!(&db, 1, None, 1, ForeignKeyViolation);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
assert_show!(&db, 1, Some(1), 1, ForeignKeyViolation);
|
||||||
|
make_content_collection!(&db, 1, 1, None);
|
||||||
|
assert_show!(&db, 1, Some(1), 1, Success);
|
||||||
|
assert_show!(&db, 2, None, 2, ForeignKeyViolation);
|
||||||
|
make_info_show!(&db, 2);
|
||||||
|
assert_show!(&db, 2, None, 2, ForeignKeyViolation);
|
||||||
|
make_content_library!(&db, 2);
|
||||||
|
assert_show!(&db, 2, None, 2, Success);
|
||||||
|
|
||||||
|
assert_show!(&db, 1, None, 1, UniqueViolation);
|
||||||
|
make_info_show!(&db, 3);
|
||||||
|
make_info_show!(&db, 4);
|
||||||
|
make_info_show!(&db, 5);
|
||||||
|
make_info_show!(&db, 6);
|
||||||
|
make_info_show!(&db, 7);
|
||||||
|
make_info_show!(&db, 8);
|
||||||
|
assert_show!(&db, 3, None, 1, Success; id);
|
||||||
|
assert_show!(&db, 4, None, 1, Success; parent_id);
|
||||||
|
assert_show!(&db, 5, None, 1, NotNullViolation; library_id);
|
||||||
|
assert_show!(&db, 6, None, 1, NotNullViolation; directory);
|
||||||
|
assert_show!(&db, 7, None, 1, Success; relative_poster_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_seasons() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_season {
|
||||||
|
($db:expr, $id:literal, $season:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.show_id, ShowId::from_raw($id));
|
||||||
|
assert_eq!(model.season_number, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.library_id, LibraryId::from_raw($lid));
|
||||||
|
assert_eq!(model.directory, Path::new(concat!("SS Directory ", $id, ",", $season)).to_owned().into());
|
||||||
|
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("SS Poster ", $id, ",", $season).to_owned() $(, $($skip),+)?));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $season:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $season:literal, $lid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::seasons::ActiveModel {
|
||||||
|
show_id: notsettable!(show_id, ShowId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
season_number: notsettable!(season_number, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
||||||
|
directory: notsettable!(directory, Path::new(concat!("SS Directory ", $id, ",", $season)).to_owned().into() $(, $($skip),+)?),
|
||||||
|
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("SS Poster ", $id, ",", $season).to_owned()) $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
make_content_show!(&db, 1, 1, None);
|
||||||
|
assert_season!(&db, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
assert_season!(&db, 1, 1, 1, Success);
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 1, 1, UniqueViolation);
|
||||||
|
make_info_season!(&db, 1, 3);
|
||||||
|
make_info_season!(&db, 1, 4);
|
||||||
|
make_info_season!(&db, 1, 5);
|
||||||
|
make_info_season!(&db, 1, 6);
|
||||||
|
make_info_season!(&db, 1, 7);
|
||||||
|
make_info_season!(&db, 1, 8);
|
||||||
|
assert_season!(&db, 1, 3, 1, NotNullViolation; show_id);
|
||||||
|
assert_season!(&db, 1, 4, 1, NotNullViolation; season_number);
|
||||||
|
assert_season!(&db, 1, 5, 1, NotNullViolation; library_id);
|
||||||
|
assert_season!(&db, 1, 6, 1, NotNullViolation; directory);
|
||||||
|
assert_season!(&db, 1, 7, 1, Success; relative_poster_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_episodes() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_episode {
|
||||||
|
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.show_id, ShowId::from_raw($id));
|
||||||
|
assert_eq!(model.season_number, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.episode_number, ::flix_model::numbers::EpisodeNumber::new($episode));
|
||||||
|
assert_eq!(model.library_id, LibraryId::from_raw($lid));
|
||||||
|
assert_eq!(model.directory, Path::new(concat!("SS Directory ", $id, ",", $season, $episode)).to_owned().into());
|
||||||
|
assert_eq!(model.relative_media_path, concat!("SS Media ", $id, ",", $season, $episode));
|
||||||
|
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("SS Poster ", $id, ",", $season, $episode).to_owned() $(, $($skip),+)?));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::episodes::ActiveModel {
|
||||||
|
show_id: notsettable!(show_id, ShowId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
season_number: notsettable!(season_number, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
episode_number: notsettable!(episode_number, ::flix_model::numbers::EpisodeNumber::new($episode) $(, $($skip),+)?),
|
||||||
|
count: notsettable!(count, 0 $(, $($skip),+)?),
|
||||||
|
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
||||||
|
directory: notsettable!(directory, Path::new(concat!("SS Directory ", $id, ",", $season, $episode)).to_owned().into() $(, $($skip),+)?),
|
||||||
|
relative_media_path: notsettable!(relative_media_path, concat!("SS Media ", $id, ",", $season, $episode).to_owned() $(, $($skip),+)?),
|
||||||
|
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("SS Poster ", $id, ",", $season, $episode).to_owned()) $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
make_content_show!(&db, 1, 1, None);
|
||||||
|
make_content_season!(&db, 1, 1, 1);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_episode!(&db, 1, 1, 1);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, Success);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
|
||||||
|
make_info_episode!(&db, 1, 1, 3);
|
||||||
|
make_info_episode!(&db, 1, 1, 4);
|
||||||
|
make_info_episode!(&db, 1, 1, 5);
|
||||||
|
make_info_episode!(&db, 1, 1, 6);
|
||||||
|
make_info_episode!(&db, 1, 1, 7);
|
||||||
|
make_info_episode!(&db, 1, 1, 8);
|
||||||
|
make_info_episode!(&db, 1, 1, 9);
|
||||||
|
make_info_episode!(&db, 1, 1, 10);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, NotNullViolation; show_id);
|
||||||
|
assert_episode!(&db, 1, 1, 4, 1, NotNullViolation; season_number);
|
||||||
|
assert_episode!(&db, 1, 1, 5, 1, NotNullViolation; episode_number);
|
||||||
|
assert_episode!(&db, 1, 1, 6, 1, NotNullViolation; library_id);
|
||||||
|
assert_episode!(&db, 1, 1, 7, 1, NotNullViolation; directory);
|
||||||
|
assert_episode!(&db, 1, 1, 8, 1, NotNullViolation; relative_media_path);
|
||||||
|
assert_episode!(&db, 1, 1, 9, 1, Success; relative_poster_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
//! Collection entity
|
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, LibraryId};
|
|
||||||
|
|
||||||
use seamantic::model::path::PathBytes;
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a collection media folder
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_collections")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The collection's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: CollectionId,
|
|
||||||
/// The collection's parent
|
|
||||||
pub parent: Option<CollectionId>,
|
|
||||||
/// The collection's slug
|
|
||||||
pub slug: String,
|
|
||||||
/// The collection's library ID
|
|
||||||
pub library: LibraryId,
|
|
||||||
/// The collection's directory
|
|
||||||
pub directory: PathBytes,
|
|
||||||
/// The collection's poster path
|
|
||||||
pub relative_poster_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The parent collection of this collection
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::collections::Entity",
|
|
||||||
from = "Column::Parent",
|
|
||||||
to = "super::collections::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Parent,
|
|
||||||
/// The library this collection belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::libraries::Entity",
|
|
||||||
from = "Column::Library",
|
|
||||||
to = "super::libraries::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Library,
|
|
||||||
/// The media info for this collection
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::info::collections::Entity",
|
|
||||||
from = "Column::Id",
|
|
||||||
to = "super::super::info::collections::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
MediaInfo,
|
|
||||||
/// The watched info for this collection
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::watched::collections::Entity",
|
|
||||||
from = "Column::Id",
|
|
||||||
to = "super::super::watched::collections::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
WatchInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Parent.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::libraries::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Library.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::info::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::MediaInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::watched::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::WatchInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
//! Episode entity
|
|
||||||
|
|
||||||
use flix_model::id::{LibraryId, ShowId};
|
|
||||||
|
|
||||||
use seamantic::model::path::PathBytes;
|
|
||||||
|
|
||||||
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a episode media folder
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_episodes")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The episode's show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub show: ShowId,
|
|
||||||
/// The episode's season's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub season: SeasonNumber,
|
|
||||||
/// The episode's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub episode: EpisodeNumber,
|
|
||||||
/// The number of additional contained episodes
|
|
||||||
pub count: u8,
|
|
||||||
/// The episode's slug
|
|
||||||
pub slug: String,
|
|
||||||
/// The episode's library
|
|
||||||
pub library: LibraryId,
|
|
||||||
/// The episode's directory
|
|
||||||
pub directory: PathBytes,
|
|
||||||
/// The episode's media path
|
|
||||||
pub relative_media_path: String,
|
|
||||||
/// The episode's poster path
|
|
||||||
pub relative_poster_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The library this episode belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::libraries::Entity",
|
|
||||||
from = "Column::Library",
|
|
||||||
to = "super::libraries::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Library,
|
|
||||||
/// The media info for this episode
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::info::episodes::Entity",
|
|
||||||
from = "(Column::Show, Column::Season, Column::Episode)",
|
|
||||||
to = "(super::super::info::episodes::Column::Show, super::super::info::episodes::Column::Season, super::super::info::episodes::Column::Episode)",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
MediaInfo,
|
|
||||||
/// The watched info for this episode
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::watched::episodes::Entity",
|
|
||||||
from = "(Column::Show, Column::Season, Column::Episode)",
|
|
||||||
to = "(super::super::watched::episodes::Column::Show, super::super::watched::episodes::Column::Season, super::super::watched::episodes::Column::Episode)",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
WatchInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::libraries::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Library.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::info::episodes::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::MediaInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::watched::episodes::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::WatchInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
//! Library entity
|
|
||||||
|
|
||||||
use flix_model::id::LibraryId;
|
|
||||||
|
|
||||||
use seamantic::model::path::PathBytes;
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a library media folder
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_libraries")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The library's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: LibraryId,
|
|
||||||
/// The library's directory
|
|
||||||
pub directory: PathBytes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// All collections in this library
|
|
||||||
#[sea_orm(has_many = "super::collections::Entity")]
|
|
||||||
Collections,
|
|
||||||
#[sea_orm(has_many = "super::movies::Entity")]
|
|
||||||
/// All movies in this library
|
|
||||||
Movies,
|
|
||||||
#[sea_orm(has_many = "super::shows::Entity")]
|
|
||||||
/// All shows in this library
|
|
||||||
Shows,
|
|
||||||
#[sea_orm(has_many = "super::seasons::Entity")]
|
|
||||||
/// All seasons in this library
|
|
||||||
Seasons,
|
|
||||||
#[sea_orm(has_many = "super::episodes::Entity")]
|
|
||||||
/// All episodes in this library
|
|
||||||
Episodes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Collections.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::movies::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Movies.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::shows::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Shows.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::seasons::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Seasons.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::episodes::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Episodes.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,342 +0,0 @@
|
|||||||
//! This module contains entities for storing media file information
|
|
||||||
|
|
||||||
pub mod libraries;
|
|
||||||
|
|
||||||
pub mod collections;
|
|
||||||
|
|
||||||
pub mod movies;
|
|
||||||
|
|
||||||
pub mod episodes;
|
|
||||||
pub mod seasons;
|
|
||||||
pub mod shows;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
|
|
||||||
|
|
||||||
use sea_orm::ActiveModelTrait;
|
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
|
||||||
use sea_orm::sqlx::error::ErrorKind;
|
|
||||||
use sea_orm_migration::MigratorTrait;
|
|
||||||
|
|
||||||
use crate::migration::Migrator;
|
|
||||||
use crate::tests::new_memory_db;
|
|
||||||
|
|
||||||
use super::super::tests::get_error_kind;
|
|
||||||
use super::super::tests::{
|
|
||||||
make_flix_collection, make_flix_episode, make_flix_movie, make_flix_season, make_flix_show,
|
|
||||||
};
|
|
||||||
use super::super::tests::{noneable, notsettable};
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_inserts() {
|
|
||||||
let db = new_memory_db().await;
|
|
||||||
Migrator::up(&db, None).await.expect("up");
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
macro_rules! assert_library {
|
|
||||||
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, LibraryId::from_raw($id));
|
|
||||||
assert_eq!(model.directory, Path::new(concat!("/L/", $id)).to_owned().into());
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::libraries::ActiveModel {
|
|
||||||
id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
directory: notsettable!(directory, Path::new(concat!("/L/", $id)).to_owned().into() $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_library!(&db, 1, Success);
|
|
||||||
assert_library!(&db, 1, UniqueViolation);
|
|
||||||
assert_library!(&db, 2, Success);
|
|
||||||
assert_library!(&db, 3, Success; id);
|
|
||||||
assert_library!(&db, 4, NotNullViolation; directory);
|
|
||||||
|
|
||||||
// Collections
|
|
||||||
macro_rules! assert_collection {
|
|
||||||
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, CollectionId::from_raw($id));
|
|
||||||
assert_eq!(model.parent, $pid);
|
|
||||||
assert_eq!(model.slug, concat!("C/", $id).to_string());
|
|
||||||
assert_eq!(model.library, LibraryId::from_raw($lid));
|
|
||||||
assert_eq!(model.directory, Path::new(concat!("/C/", $id)).to_owned().into());
|
|
||||||
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("C/Poster", $id).to_owned() $(, $($skip),+)?));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::collections::ActiveModel {
|
|
||||||
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
parent: notsettable!(parent, $pid $(, $($skip),+)?),
|
|
||||||
slug: notsettable!(slug, concat!("C/", $id).to_string() $(, $($skip),+)?),
|
|
||||||
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
|
||||||
directory: notsettable!(directory, Path::new(concat!("/C/", $id)).to_owned().into() $(, $($skip),+)?),
|
|
||||||
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("C/Poster", $id).to_owned()) $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_collection!(&db, 1, None, 0, ForeignKeyViolation);
|
|
||||||
assert_collection!(
|
|
||||||
&db,
|
|
||||||
1,
|
|
||||||
Some(CollectionId::from_raw(0)),
|
|
||||||
1,
|
|
||||||
ForeignKeyViolation
|
|
||||||
);
|
|
||||||
assert_collection!(&db, 1, None, 1, ForeignKeyViolation);
|
|
||||||
make_flix_collection!(&db, 1);
|
|
||||||
make_flix_collection!(&db, 2);
|
|
||||||
make_flix_collection!(&db, 3);
|
|
||||||
make_flix_collection!(&db, 4);
|
|
||||||
make_flix_collection!(&db, 8);
|
|
||||||
|
|
||||||
assert_collection!(&db, 1, None, 1, Success);
|
|
||||||
assert_collection!(&db, 1, None, 1, UniqueViolation);
|
|
||||||
assert_collection!(&db, 2, None, 1, Success);
|
|
||||||
assert_collection!(&db, 3, None, 1, Success; id);
|
|
||||||
assert_collection!(&db, 4, None, 1, Success; parent);
|
|
||||||
assert_collection!(&db, 5, None, 1, NotNullViolation; slug);
|
|
||||||
assert_collection!(&db, 6, None, 1, NotNullViolation; library);
|
|
||||||
assert_collection!(&db, 7, None, 1, NotNullViolation; directory);
|
|
||||||
assert_collection!(&db, 8, None, 1, Success; relative_poster_path);
|
|
||||||
|
|
||||||
// Movies
|
|
||||||
macro_rules! assert_movie {
|
|
||||||
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, MovieId::from_raw($id));
|
|
||||||
assert_eq!(model.parent, $pid);
|
|
||||||
assert_eq!(model.slug, concat!("M/", $id).to_string());
|
|
||||||
assert_eq!(model.library, LibraryId::from_raw($lid));
|
|
||||||
assert_eq!(model.directory, Path::new(concat!("/M/", $id)).to_owned().into());
|
|
||||||
assert_eq!(model.relative_media_path, concat!("M/Media", $id));
|
|
||||||
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("M/Poster", $id).to_owned() $(, $($skip),+)?));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::movies::ActiveModel {
|
|
||||||
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
parent: notsettable!(parent, $pid $(, $($skip),+)?),
|
|
||||||
slug: notsettable!(slug, concat!("M/", $id).to_string() $(, $($skip),+)?),
|
|
||||||
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
|
||||||
directory: notsettable!(directory, Path::new(concat!("/M/", $id)).to_owned().into() $(, $($skip),+)?),
|
|
||||||
relative_media_path: notsettable!(relative_media_path, concat!("M/Media", $id).to_owned() $(, $($skip),+)?),
|
|
||||||
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("M/Poster", $id).to_owned()) $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_movie!(&db, 1, None, 0, ForeignKeyViolation);
|
|
||||||
assert_movie!(
|
|
||||||
&db,
|
|
||||||
1,
|
|
||||||
Some(CollectionId::from_raw(0)),
|
|
||||||
1,
|
|
||||||
ForeignKeyViolation
|
|
||||||
);
|
|
||||||
assert_movie!(&db, 1, None, 1, ForeignKeyViolation);
|
|
||||||
make_flix_movie!(&db, 1);
|
|
||||||
make_flix_movie!(&db, 2);
|
|
||||||
make_flix_movie!(&db, 3);
|
|
||||||
make_flix_movie!(&db, 4);
|
|
||||||
make_flix_movie!(&db, 9);
|
|
||||||
|
|
||||||
assert_movie!(&db, 1, None, 1, Success);
|
|
||||||
assert_movie!(&db, 1, None, 1, UniqueViolation);
|
|
||||||
assert_movie!(&db, 2, None, 1, Success);
|
|
||||||
assert_movie!(&db, 3, None, 1, Success; id);
|
|
||||||
assert_movie!(&db, 4, None, 1, Success; parent);
|
|
||||||
assert_movie!(&db, 5, None, 1, NotNullViolation; slug);
|
|
||||||
assert_movie!(&db, 6, None, 1, NotNullViolation; library);
|
|
||||||
assert_movie!(&db, 7, None, 1, NotNullViolation; directory);
|
|
||||||
assert_movie!(&db, 8, None, 1, NotNullViolation; relative_media_path);
|
|
||||||
assert_movie!(&db, 9, None, 1, Success; relative_poster_path);
|
|
||||||
|
|
||||||
// Shows
|
|
||||||
macro_rules! assert_show {
|
|
||||||
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, ShowId::from_raw($id));
|
|
||||||
assert_eq!(model.parent, $pid);
|
|
||||||
assert_eq!(model.slug, concat!("S/", $id).to_string());
|
|
||||||
assert_eq!(model.library, LibraryId::from_raw($lid));
|
|
||||||
assert_eq!(model.directory, Path::new(concat!("/S/", $id)).to_owned().into());
|
|
||||||
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S/Poster", $id).to_owned() $(, $($skip),+)?));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::shows::ActiveModel {
|
|
||||||
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
parent: notsettable!(parent, $pid $(, $($skip),+)?),
|
|
||||||
slug: notsettable!(slug, concat!("S/", $id).to_string() $(, $($skip),+)?),
|
|
||||||
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
|
||||||
directory: notsettable!(directory, Path::new(concat!("/S/", $id)).to_owned().into() $(, $($skip),+)?),
|
|
||||||
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S/Poster", $id).to_owned()) $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_show!(&db, 1, None, 0, ForeignKeyViolation);
|
|
||||||
assert_show!(
|
|
||||||
&db,
|
|
||||||
1,
|
|
||||||
Some(CollectionId::from_raw(0)),
|
|
||||||
1,
|
|
||||||
ForeignKeyViolation
|
|
||||||
);
|
|
||||||
assert_show!(&db, 1, None, 1, ForeignKeyViolation);
|
|
||||||
make_flix_show!(&db, 1);
|
|
||||||
make_flix_show!(&db, 2);
|
|
||||||
make_flix_show!(&db, 3);
|
|
||||||
make_flix_show!(&db, 4);
|
|
||||||
make_flix_show!(&db, 8);
|
|
||||||
|
|
||||||
assert_show!(&db, 1, None, 1, Success);
|
|
||||||
assert_show!(&db, 1, None, 1, UniqueViolation);
|
|
||||||
assert_show!(&db, 2, None, 1, Success);
|
|
||||||
assert_show!(&db, 3, None, 1, Success; id);
|
|
||||||
assert_show!(&db, 4, None, 1, Success; parent);
|
|
||||||
assert_show!(&db, 5, None, 1, NotNullViolation; slug);
|
|
||||||
assert_show!(&db, 6, None, 1, NotNullViolation; library);
|
|
||||||
assert_show!(&db, 7, None, 1, NotNullViolation; directory);
|
|
||||||
assert_show!(&db, 8, None, 1, Success; relative_poster_path);
|
|
||||||
|
|
||||||
// Seasons
|
|
||||||
macro_rules! assert_season {
|
|
||||||
($db:expr, $id:literal, $season:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.show, ShowId::from_raw($id));
|
|
||||||
assert_eq!(model.season, $season);
|
|
||||||
assert_eq!(model.slug, concat!("S/S", $id).to_string());
|
|
||||||
assert_eq!(model.library, LibraryId::from_raw($lid));
|
|
||||||
assert_eq!(model.directory, Path::new(concat!("/S/S", $id)).to_owned().into());
|
|
||||||
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S/S/Poster", $id).to_owned() $(, $($skip),+)?));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $season:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $season:literal, $lid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::seasons::ActiveModel {
|
|
||||||
show: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
season: notsettable!(season, $season $(, $($skip),+)?),
|
|
||||||
slug: notsettable!(slug, concat!("S/S", $id).to_string() $(, $($skip),+)?),
|
|
||||||
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
|
||||||
directory: notsettable!(directory, Path::new(concat!("/S/S", $id)).to_owned().into() $(, $($skip),+)?),
|
|
||||||
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S/S/Poster", $id).to_owned()) $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_season!(&db, 1, 1, 0, ForeignKeyViolation);
|
|
||||||
assert_season!(&db, 1, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_season!(&db, 1, 1);
|
|
||||||
make_flix_season!(&db, 1, 2);
|
|
||||||
make_flix_season!(&db, 2, 1);
|
|
||||||
make_flix_season!(&db, 3, 1);
|
|
||||||
make_flix_season!(&db, 8, 1);
|
|
||||||
|
|
||||||
assert_season!(&db, 1, 1, 1, Success);
|
|
||||||
assert_season!(&db, 1, 2, 1, Success);
|
|
||||||
assert_season!(&db, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_season!(&db, 2, 1, 1, Success);
|
|
||||||
assert_season!(&db, 3, 1, 1, Success; show);
|
|
||||||
assert_season!(&db, 4, 1, 1, NotNullViolation; season);
|
|
||||||
assert_season!(&db, 5, 1, 1, NotNullViolation; slug);
|
|
||||||
assert_season!(&db, 6, 1, 1, NotNullViolation; library);
|
|
||||||
assert_season!(&db, 7, 1, 1, NotNullViolation; directory);
|
|
||||||
assert_season!(&db, 8, 1, 1, Success; relative_poster_path);
|
|
||||||
|
|
||||||
// Episodes
|
|
||||||
macro_rules! assert_episode {
|
|
||||||
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.show, ShowId::from_raw($id));
|
|
||||||
assert_eq!(model.season, $season);
|
|
||||||
assert_eq!(model.episode, $episode);
|
|
||||||
assert_eq!(model.slug, concat!("S/S/E", $id).to_string());
|
|
||||||
assert_eq!(model.library, LibraryId::from_raw($lid));
|
|
||||||
assert_eq!(model.directory, Path::new(concat!("/S/S/E", $id)).to_owned().into());
|
|
||||||
assert_eq!(model.relative_media_path, concat!("E/Media", $id));
|
|
||||||
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S/S/E/Poster", $id).to_owned() $(, $($skip),+)?));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::episodes::ActiveModel {
|
|
||||||
show: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
season: notsettable!(season, $season $(, $($skip),+)?),
|
|
||||||
episode: notsettable!(episode, $episode $(, $($skip),+)?),
|
|
||||||
count: notsettable!(count, 0 $(, $($skip),+)?),
|
|
||||||
slug: notsettable!(slug, concat!("S/S/E", $id).to_string() $(, $($skip),+)?),
|
|
||||||
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
|
|
||||||
directory: notsettable!(directory, Path::new(concat!("/S/S/E", $id)).to_owned().into() $(, $($skip),+)?),
|
|
||||||
relative_media_path: notsettable!(relative_media_path, concat!("E/Media", $id).to_owned() $(, $($skip),+)?),
|
|
||||||
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S/S/E/Poster", $id).to_owned()) $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_episode!(&db, 1, 1, 1, 0, ForeignKeyViolation);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_episode!(&db, 1, 1, 1);
|
|
||||||
make_flix_episode!(&db, 1, 1, 2);
|
|
||||||
make_flix_episode!(&db, 2, 1, 1);
|
|
||||||
make_flix_episode!(&db, 3, 1, 1);
|
|
||||||
make_flix_show!(&db, 11);
|
|
||||||
make_flix_season!(&db, 11, 1);
|
|
||||||
make_flix_episode!(&db, 11, 1, 1);
|
|
||||||
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 2, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 2, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 3, 1, 1, 1, Success; show);
|
|
||||||
assert_episode!(&db, 4, 1, 1, 1, NotNullViolation; season);
|
|
||||||
assert_episode!(&db, 5, 1, 1, 1, NotNullViolation; episode);
|
|
||||||
assert_episode!(&db, 6, 1, 1, 1, NotNullViolation; count);
|
|
||||||
assert_episode!(&db, 7, 1, 1, 1, NotNullViolation; slug);
|
|
||||||
assert_episode!(&db, 8, 1, 1, 1, NotNullViolation; library);
|
|
||||||
assert_episode!(&db, 9, 1, 1, 1, NotNullViolation; directory);
|
|
||||||
assert_episode!(&db, 10, 1, 1, 1, NotNullViolation; relative_media_path);
|
|
||||||
assert_episode!(&db, 11, 1, 1, 1, Success; relative_poster_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
//! Movie entity
|
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, LibraryId, MovieId};
|
|
||||||
|
|
||||||
use seamantic::model::path::PathBytes;
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a movie media folder
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_movies")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The movie's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: MovieId,
|
|
||||||
/// The movie's parent
|
|
||||||
pub parent: Option<CollectionId>,
|
|
||||||
/// The movie's slug
|
|
||||||
pub slug: String,
|
|
||||||
/// The movie's library
|
|
||||||
pub library: LibraryId,
|
|
||||||
/// The movie's directory
|
|
||||||
pub directory: PathBytes,
|
|
||||||
/// The movie's media path
|
|
||||||
pub relative_media_path: String,
|
|
||||||
/// The movie's poster path
|
|
||||||
pub relative_poster_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The parent collection of this collection
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::collections::Entity",
|
|
||||||
from = "Column::Parent",
|
|
||||||
to = "super::collections::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Parent,
|
|
||||||
/// The library this movie belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::libraries::Entity",
|
|
||||||
from = "Column::Library",
|
|
||||||
to = "super::libraries::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Library,
|
|
||||||
/// The media info for this movie
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::info::movies::Entity",
|
|
||||||
from = "Column::Id",
|
|
||||||
to = "super::super::info::movies::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
MediaInfo,
|
|
||||||
/// The watched info for this movie
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::watched::movies::Entity",
|
|
||||||
from = "Column::Id",
|
|
||||||
to = "super::super::watched::movies::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
WatchInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Parent.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::libraries::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Library.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::info::movies::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::MediaInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::watched::movies::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::WatchInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
//! Season entity
|
|
||||||
|
|
||||||
use flix_model::id::{LibraryId, ShowId};
|
|
||||||
|
|
||||||
use seamantic::model::path::PathBytes;
|
|
||||||
|
|
||||||
use flix_model::numbers::SeasonNumber;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a season media folder
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_seasons")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The season's show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub show: ShowId,
|
|
||||||
/// The season's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub season: SeasonNumber,
|
|
||||||
/// The season's slug
|
|
||||||
pub slug: String,
|
|
||||||
/// The season's library
|
|
||||||
pub library: LibraryId,
|
|
||||||
/// The season's directory
|
|
||||||
pub directory: PathBytes,
|
|
||||||
/// The season's poster path
|
|
||||||
pub relative_poster_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The library this season belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::libraries::Entity",
|
|
||||||
from = "Column::Library",
|
|
||||||
to = "super::libraries::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Library,
|
|
||||||
/// The media info for this show
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::info::seasons::Entity",
|
|
||||||
from = "(Column::Show, Column::Season)",
|
|
||||||
to = "(super::super::info::seasons::Column::Show, super::super::info::seasons::Column::Season)",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
MediaInfo,
|
|
||||||
/// The watched info for this show
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::watched::seasons::Entity",
|
|
||||||
from = "(Column::Show, Column::Season)",
|
|
||||||
to = "(super::super::watched::seasons::Column::Show, super::super::watched::seasons::Column::Season)",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
WatchInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::libraries::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Library.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::info::seasons::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::MediaInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::watched::seasons::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::WatchInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
//! Show entity
|
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, LibraryId, ShowId};
|
|
||||||
|
|
||||||
use seamantic::model::path::PathBytes;
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a show media folder
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_shows")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: ShowId,
|
|
||||||
/// The show's parent
|
|
||||||
pub parent: Option<CollectionId>,
|
|
||||||
/// The show's slug
|
|
||||||
pub slug: String,
|
|
||||||
/// The show's library
|
|
||||||
pub library: LibraryId,
|
|
||||||
/// The show's directory
|
|
||||||
pub directory: PathBytes,
|
|
||||||
/// The show's poster path
|
|
||||||
pub relative_poster_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The parent collection of this collection
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::collections::Entity",
|
|
||||||
from = "Column::Parent",
|
|
||||||
to = "super::collections::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Parent,
|
|
||||||
/// The library this show belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::libraries::Entity",
|
|
||||||
from = "Column::Library",
|
|
||||||
to = "super::libraries::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Library,
|
|
||||||
/// The media info for this show
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::info::shows::Entity",
|
|
||||||
from = "Column::Id",
|
|
||||||
to = "super::super::info::shows::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
MediaInfo,
|
|
||||||
/// The watched info for this show
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::super::watched::shows::Entity",
|
|
||||||
from = "Column::Id",
|
|
||||||
to = "super::super::watched::shows::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
WatchInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Parent.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::libraries::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Library.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::info::shows::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::MediaInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::super::watched::shows::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::WatchInfo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,622 @@
|
|||||||
|
//! This module contains entities for storing media information such as
|
||||||
|
//! titles and overviews
|
||||||
|
|
||||||
|
/// Collection entity
|
||||||
|
pub mod collections {
|
||||||
|
use flix_model::id::CollectionId;
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a flix collection
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_info_collections")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The collection's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: CollectionId,
|
||||||
|
/// The collection's title
|
||||||
|
pub title: String,
|
||||||
|
/// The collection's overview
|
||||||
|
pub overview: String,
|
||||||
|
|
||||||
|
/// The sortable title
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub sort_title: String,
|
||||||
|
/// The filesystem-safe slug
|
||||||
|
#[sea_orm(indexed, unique)]
|
||||||
|
pub fs_slug: String,
|
||||||
|
/// The url-safe slug
|
||||||
|
#[sea_orm(indexed, unique)]
|
||||||
|
pub web_slug: String,
|
||||||
|
|
||||||
|
/// Potential content for this collection
|
||||||
|
#[sea_orm(has_one)]
|
||||||
|
pub content: HasOne<entity::content::collections::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Movie entity
|
||||||
|
pub mod movies {
|
||||||
|
use flix_model::id::MovieId;
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a flix movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_info_movies")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The movie's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: MovieId,
|
||||||
|
/// The movie's title
|
||||||
|
pub title: String,
|
||||||
|
/// The movie's tagline
|
||||||
|
pub tagline: String,
|
||||||
|
/// The movie's overview
|
||||||
|
pub overview: String,
|
||||||
|
/// The movie's release date
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub date: NaiveDate,
|
||||||
|
|
||||||
|
/// The sortable title
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub sort_title: String,
|
||||||
|
/// The filesystem-safe slug
|
||||||
|
#[sea_orm(indexed, unique)]
|
||||||
|
pub fs_slug: String,
|
||||||
|
/// The url-safe slug
|
||||||
|
#[sea_orm(indexed, unique)]
|
||||||
|
pub web_slug: String,
|
||||||
|
|
||||||
|
/// Potential content for this movie
|
||||||
|
#[sea_orm(has_one)]
|
||||||
|
pub content: HasOne<entity::content::movies::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Show entity
|
||||||
|
pub mod shows {
|
||||||
|
use flix_model::id::ShowId;
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a flix show
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_info_shows")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: ShowId,
|
||||||
|
/// The show's title
|
||||||
|
pub title: String,
|
||||||
|
/// The show's tagline
|
||||||
|
pub tagline: String,
|
||||||
|
/// The show's overview
|
||||||
|
pub overview: String,
|
||||||
|
/// The show's air date
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub date: NaiveDate,
|
||||||
|
|
||||||
|
/// The sortable title
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub sort_title: String,
|
||||||
|
/// The filesystem-safe slug
|
||||||
|
#[sea_orm(indexed, unique)]
|
||||||
|
pub fs_slug: String,
|
||||||
|
/// The url-safe slug
|
||||||
|
#[sea_orm(indexed, unique)]
|
||||||
|
pub web_slug: String,
|
||||||
|
|
||||||
|
/// Seasons that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub seasons: HasMany<super::seasons::Entity>,
|
||||||
|
/// Episodes that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
|
||||||
|
/// Potential content for this show
|
||||||
|
#[sea_orm(has_one)]
|
||||||
|
pub content: HasOne<entity::content::shows::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Season entity
|
||||||
|
pub mod seasons {
|
||||||
|
use flix_model::id::ShowId;
|
||||||
|
use flix_model::numbers::SeasonNumber;
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a flix season
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_info_seasons")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The season's show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub show_id: ShowId,
|
||||||
|
/// The season's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub season_number: SeasonNumber,
|
||||||
|
/// The season's title
|
||||||
|
pub title: String,
|
||||||
|
/// The season's overview
|
||||||
|
pub overview: String,
|
||||||
|
/// The season's air date
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub date: NaiveDate,
|
||||||
|
|
||||||
|
/// The show this season belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "show_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub show: HasOne<super::shows::Entity>,
|
||||||
|
/// Episodes that are part of this season
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
|
||||||
|
/// Potential content for this season
|
||||||
|
#[sea_orm(has_one)]
|
||||||
|
pub content: HasOne<entity::content::seasons::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Episode entity
|
||||||
|
pub mod episodes {
|
||||||
|
use flix_model::id::ShowId;
|
||||||
|
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a flix episode
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_info_episodes")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The episode's show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub show_id: ShowId,
|
||||||
|
/// The episode's season's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub season_number: SeasonNumber,
|
||||||
|
/// The episode's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub episode_number: EpisodeNumber,
|
||||||
|
/// The episode's title
|
||||||
|
pub title: String,
|
||||||
|
/// The episode's overview
|
||||||
|
pub overview: String,
|
||||||
|
/// The episode's air date
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub date: NaiveDate,
|
||||||
|
|
||||||
|
/// The show this episode belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "show_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub show: HasOne<super::shows::Entity>,
|
||||||
|
/// The season this episode belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "(show_id, season_number)",
|
||||||
|
to = "(show_id, season_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub season: HasOne<super::seasons::Entity>,
|
||||||
|
|
||||||
|
/// Potential content for this episode
|
||||||
|
#[sea_orm(has_one)]
|
||||||
|
pub content: HasOne<entity::content::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Macros for creating info entities
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod test {
|
||||||
|
macro_rules! make_info_collection {
|
||||||
|
($db:expr, $id:expr) => {
|
||||||
|
$crate::entity::info::collections::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::CollectionId::from_raw($id)),
|
||||||
|
title: Set(::std::string::String::new()),
|
||||||
|
overview: Set(::std::string::String::new()),
|
||||||
|
sort_title: Set(::std::string::String::new()),
|
||||||
|
fs_slug: Set(format!("C FS {}", $id)),
|
||||||
|
web_slug: Set(format!("C Web {}", $id)),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_info_collection;
|
||||||
|
|
||||||
|
macro_rules! make_info_movie {
|
||||||
|
($db:expr, $id:expr) => {
|
||||||
|
$crate::entity::info::movies::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::MovieId::from_raw($id)),
|
||||||
|
title: Set(::std::string::String::new()),
|
||||||
|
tagline: Set(::std::string::String::new()),
|
||||||
|
overview: Set(::std::string::String::new()),
|
||||||
|
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
|
||||||
|
sort_title: Set(::std::string::String::new()),
|
||||||
|
fs_slug: Set(format!("M FS {}", $id)),
|
||||||
|
web_slug: Set(format!("M Web {}", $id)),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_info_movie;
|
||||||
|
|
||||||
|
macro_rules! make_info_show {
|
||||||
|
($db:expr, $id:expr) => {
|
||||||
|
$crate::entity::info::shows::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::ShowId::from_raw($id)),
|
||||||
|
title: Set(::std::string::String::new()),
|
||||||
|
tagline: Set(::std::string::String::new()),
|
||||||
|
overview: Set(::std::string::String::new()),
|
||||||
|
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
|
||||||
|
sort_title: Set(::std::string::String::new()),
|
||||||
|
fs_slug: Set(format!("S FS {}", $id)),
|
||||||
|
web_slug: Set(format!("S Web {}", $id)),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_info_show;
|
||||||
|
|
||||||
|
macro_rules! make_info_season {
|
||||||
|
($db:expr, $show:expr, $season:expr) => {
|
||||||
|
$crate::entity::info::seasons::ActiveModel {
|
||||||
|
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
|
||||||
|
season_number: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
title: Set(::std::string::String::new()),
|
||||||
|
overview: Set(::std::string::String::new()),
|
||||||
|
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_info_season;
|
||||||
|
|
||||||
|
macro_rules! make_info_episode {
|
||||||
|
($db:expr, $show:expr, $season:expr, $episode:expr) => {
|
||||||
|
$crate::entity::info::episodes::ActiveModel {
|
||||||
|
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
|
||||||
|
season_number: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
episode_number: Set(::flix_model::numbers::EpisodeNumber::new($episode)),
|
||||||
|
title: Set(::std::string::String::new()),
|
||||||
|
overview: Set(::std::string::String::new()),
|
||||||
|
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_info_episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use flix_model::id::{CollectionId, MovieId, ShowId};
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use sea_orm::sqlx::error::ErrorKind;
|
||||||
|
|
||||||
|
use crate::tests::new_initialized_memory_db;
|
||||||
|
|
||||||
|
use super::super::tests::get_error_kind;
|
||||||
|
use super::super::tests::notsettable;
|
||||||
|
use super::test::{
|
||||||
|
make_info_collection, make_info_episode, make_info_movie, make_info_season, make_info_show,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn use_test_macros() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
make_info_collection!(&db, 1);
|
||||||
|
make_info_movie!(&db, 1);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
make_info_episode!(&db, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_collections() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_collection {
|
||||||
|
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, CollectionId::from_raw($id));
|
||||||
|
assert_eq!(model.title, concat!("C Title ", $id));
|
||||||
|
assert_eq!(model.overview, concat!("C Overview ", $id));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::collections::ActiveModel {
|
||||||
|
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
title: notsettable!(title, concat!("C Title ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
overview: notsettable!(overview, concat!("C Overview ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
sort_title: notsettable!(sort_title, concat!("C Sort Title ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
fs_slug: notsettable!(fs_slug, concat!("C FS Slug ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
web_slug: notsettable!(web_slug, concat!("C Web Slug ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_collection!(&db, 1, Success);
|
||||||
|
assert_collection!(&db, 1, UniqueViolation);
|
||||||
|
assert_collection!(&db, 2, Success);
|
||||||
|
|
||||||
|
assert_collection!(&db, 3, Success; id);
|
||||||
|
assert_collection!(&db, 4, NotNullViolation; title);
|
||||||
|
assert_collection!(&db, 5, NotNullViolation; overview);
|
||||||
|
assert_collection!(&db, 6, NotNullViolation; sort_title);
|
||||||
|
assert_collection!(&db, 7, NotNullViolation; fs_slug);
|
||||||
|
assert_collection!(&db, 8, NotNullViolation; web_slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_movies() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_movie {
|
||||||
|
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, MovieId::from_raw($id));
|
||||||
|
assert_eq!(model.title, concat!("M Title ", $id));
|
||||||
|
assert_eq!(model.tagline, concat!("M Tagline ", $id));
|
||||||
|
assert_eq!(model.overview, concat!("M Overview ", $id));
|
||||||
|
assert_eq!(model.date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::movies::ActiveModel {
|
||||||
|
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
title: notsettable!(title, concat!("M Title ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
tagline: notsettable!(tagline, concat!("M Tagline ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
overview: notsettable!(overview, concat!("M Overview ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
date: notsettable!(date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt") $(, $($skip),+)?),
|
||||||
|
sort_title: notsettable!(sort_title, concat!("M Sort Title ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
fs_slug: notsettable!(fs_slug, concat!("M FS Slug ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
web_slug: notsettable!(web_slug, concat!("M Web Slug ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_movie!(&db, 1, Success);
|
||||||
|
assert_movie!(&db, 1, UniqueViolation);
|
||||||
|
assert_movie!(&db, 2, Success);
|
||||||
|
|
||||||
|
assert_movie!(&db, 3, Success; id);
|
||||||
|
assert_movie!(&db, 4, NotNullViolation; title);
|
||||||
|
assert_movie!(&db, 5, NotNullViolation; tagline);
|
||||||
|
assert_movie!(&db, 6, NotNullViolation; overview);
|
||||||
|
assert_movie!(&db, 7, NotNullViolation; date);
|
||||||
|
assert_movie!(&db, 8, NotNullViolation; sort_title);
|
||||||
|
assert_movie!(&db, 9, NotNullViolation; fs_slug);
|
||||||
|
assert_movie!(&db, 10, NotNullViolation; web_slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_shows() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_show {
|
||||||
|
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, ShowId::from_raw($id));
|
||||||
|
assert_eq!(model.title, concat!("S Title ", $id));
|
||||||
|
assert_eq!(model.tagline, concat!("S Tagline ", $id));
|
||||||
|
assert_eq!(model.overview, concat!("S Overview ", $id));
|
||||||
|
assert_eq!(model.date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_error_kind(model).expect("get_error_kind"),
|
||||||
|
ErrorKind::$error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::shows::ActiveModel {
|
||||||
|
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
title: notsettable!(title, concat!("S Title ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
tagline: notsettable!(tagline, concat!("S Tagline ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
overview: notsettable!(overview, concat!("S Overview ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
date: notsettable!(date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt") $(, $($skip),+)?),
|
||||||
|
sort_title: notsettable!(sort_title, concat!("S Sort Title ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
fs_slug: notsettable!(fs_slug, concat!("S FS Slug ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
web_slug: notsettable!(web_slug, concat!("S Web Slug ", $id).to_string() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_show!(&db, 1, Success);
|
||||||
|
assert_show!(&db, 1, UniqueViolation);
|
||||||
|
assert_show!(&db, 2, Success);
|
||||||
|
|
||||||
|
assert_show!(&db, 3, Success; id);
|
||||||
|
assert_show!(&db, 4, NotNullViolation; title);
|
||||||
|
assert_show!(&db, 5, NotNullViolation; tagline);
|
||||||
|
assert_show!(&db, 6, NotNullViolation; overview);
|
||||||
|
assert_show!(&db, 7, NotNullViolation; date);
|
||||||
|
assert_show!(&db, 8, NotNullViolation; sort_title);
|
||||||
|
assert_show!(&db, 9, NotNullViolation; fs_slug);
|
||||||
|
assert_show!(&db, 10, NotNullViolation; web_slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_seasons() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_season {
|
||||||
|
($db:expr, $show:literal, $season:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.show_id, ShowId::from_raw($show));
|
||||||
|
assert_eq!(model.season_number, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.title, concat!("SS Title ", $show, ",", $season));
|
||||||
|
assert_eq!(model.overview, concat!("SS Overview ", $show, ",", $season));
|
||||||
|
assert_eq!(model.date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt"));
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $season:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_error_kind(model).expect("get_error_kind"),
|
||||||
|
ErrorKind::$error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $show:literal, $season:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::seasons::ActiveModel {
|
||||||
|
show_id: notsettable!(show_id, ShowId::from_raw($show) $(, $($skip),+)?),
|
||||||
|
season_number: notsettable!(season_number, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
title: notsettable!(title, concat!("SS Title ", $show, ",", $season).to_string() $(, $($skip),+)?),
|
||||||
|
overview: notsettable!(overview, concat!("SS Overview ", $show, ",", $season).to_string() $(, $($skip),+)?),
|
||||||
|
date: notsettable!(date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt") $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_show!(&db, 2);
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 1, Success);
|
||||||
|
assert_season!(&db, 1, 1, UniqueViolation);
|
||||||
|
assert_season!(&db, 2, 1, Success);
|
||||||
|
assert_season!(&db, 1, 2, Success);
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 3, NotNullViolation; show_id);
|
||||||
|
assert_season!(&db, 1, 4, NotNullViolation; season_number);
|
||||||
|
assert_season!(&db, 1, 5, NotNullViolation; title);
|
||||||
|
assert_season!(&db, 1, 6, NotNullViolation; overview);
|
||||||
|
assert_season!(&db, 1, 7, NotNullViolation; date);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_episodes() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_episode {
|
||||||
|
($db:expr, $show:literal, $season:literal, $episode:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.show_id, ShowId::from_raw($show));
|
||||||
|
assert_eq!(model.season_number, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.episode_number, ::flix_model::numbers::EpisodeNumber::new($episode));
|
||||||
|
assert_eq!(model.title, concat!("SSE Title ", $show, ",", $season, ",", $episode));
|
||||||
|
assert_eq!(model.overview, concat!("SSE Overview ", $show, ",", $season, ",", $episode));
|
||||||
|
assert_eq!(model.date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt"));
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $season:literal, $episode:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_error_kind(model).expect("get_error_kind"),
|
||||||
|
ErrorKind::$error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::episodes::ActiveModel {
|
||||||
|
show_id: notsettable!(show_id, ShowId::from_raw($show) $(, $($skip),+)?),
|
||||||
|
season_number: notsettable!(season_number, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
episode_number: notsettable!(episode_number, ::flix_model::numbers::EpisodeNumber::new($episode) $(, $($skip),+)?),
|
||||||
|
title: notsettable!(title, concat!("SSE Title ", $show, ",", $season, ",", $episode).to_string() $(, $($skip),+)?),
|
||||||
|
overview: notsettable!(overview, concat!("SSE Overview ", $show, ",", $season, ",", $episode).to_string() $(, $($skip),+)?),
|
||||||
|
date: notsettable!(date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt") $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_show!(&db, 2);
|
||||||
|
assert_episode!(&db, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
make_info_season!(&db, 1, 2);
|
||||||
|
make_info_season!(&db, 2, 1);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, Success);
|
||||||
|
assert_episode!(&db, 1, 1, 1, UniqueViolation);
|
||||||
|
assert_episode!(&db, 2, 1, 1, Success);
|
||||||
|
assert_episode!(&db, 1, 2, 1, Success);
|
||||||
|
assert_episode!(&db, 1, 1, 2, Success);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 3, NotNullViolation; show_id);
|
||||||
|
assert_episode!(&db, 1, 1, 4, NotNullViolation; season_number);
|
||||||
|
assert_episode!(&db, 1, 1, 4, NotNullViolation; episode_number);
|
||||||
|
assert_episode!(&db, 1, 1, 5, NotNullViolation; title);
|
||||||
|
assert_episode!(&db, 1, 1, 6, NotNullViolation; overview);
|
||||||
|
assert_episode!(&db, 1, 1, 7, NotNullViolation; date);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
//! Collection entity
|
|
||||||
|
|
||||||
use flix_model::id::CollectionId;
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a flix collection
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_info_collections")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The collection's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: CollectionId,
|
|
||||||
/// The collection's title
|
|
||||||
pub title: String,
|
|
||||||
/// The collection's overview
|
|
||||||
pub overview: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
//! Episode entity
|
|
||||||
|
|
||||||
use flix_model::id::ShowId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a flix episode
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_info_episodes")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The episode's show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub show: ShowId,
|
|
||||||
/// The episode's season's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub season: SeasonNumber,
|
|
||||||
/// The episode's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub episode: EpisodeNumber,
|
|
||||||
/// The episode's title
|
|
||||||
pub title: String,
|
|
||||||
/// The episode's overview
|
|
||||||
pub overview: String,
|
|
||||||
/// The episode's air date
|
|
||||||
pub date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The show this season belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::shows::Entity",
|
|
||||||
from = "Column::Show",
|
|
||||||
to = "super::shows::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Show,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::shows::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Show.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
//! This module contains entities for storing media information such as
|
|
||||||
//! titles and overviews
|
|
||||||
|
|
||||||
pub mod collections;
|
|
||||||
|
|
||||||
pub mod movies;
|
|
||||||
|
|
||||||
pub mod episodes;
|
|
||||||
pub mod seasons;
|
|
||||||
pub mod shows;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use flix_model::id::{CollectionId, MovieId, ShowId};
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::ActiveModelTrait;
|
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
|
||||||
use sea_orm::sqlx::error::ErrorKind;
|
|
||||||
use sea_orm_migration::MigratorTrait;
|
|
||||||
|
|
||||||
use crate::migration::Migrator;
|
|
||||||
use crate::tests::new_memory_db;
|
|
||||||
|
|
||||||
use super::super::tests::get_error_kind;
|
|
||||||
use super::super::tests::notsettable;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_inserts() {
|
|
||||||
let db = new_memory_db().await;
|
|
||||||
Migrator::up(&db, None).await.expect("up");
|
|
||||||
|
|
||||||
// Collections
|
|
||||||
macro_rules! assert_collection {
|
|
||||||
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, CollectionId::from_raw($id));
|
|
||||||
assert_eq!(model.title, concat!("C", $id));
|
|
||||||
assert_eq!(model.overview, concat!("Collection", " ", $id));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::collections::ActiveModel {
|
|
||||||
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
title: notsettable!(title, concat!("C", $id).to_string() $(, $($skip),+)?),
|
|
||||||
overview: notsettable!(overview, concat!("Collection", " ", $id).to_string() $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_collection!(&db, 1, Success);
|
|
||||||
assert_collection!(&db, 1, UniqueViolation);
|
|
||||||
assert_collection!(&db, 2, Success);
|
|
||||||
assert_collection!(&db, 3, Success; id);
|
|
||||||
assert_collection!(&db, 4, NotNullViolation; title);
|
|
||||||
assert_collection!(&db, 5, NotNullViolation; overview);
|
|
||||||
|
|
||||||
// Movies
|
|
||||||
macro_rules! assert_movie {
|
|
||||||
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, MovieId::from_raw($id));
|
|
||||||
assert_eq!(model.title, concat!("M", $id));
|
|
||||||
assert_eq!(model.tagline, concat!("Watch Movie", " ", $id));
|
|
||||||
assert_eq!(model.overview, concat!("Movie", " ", $id));
|
|
||||||
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::movies::ActiveModel {
|
|
||||||
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
title: notsettable!(title, concat!("M", $id).to_string() $(, $($skip),+)?),
|
|
||||||
tagline: notsettable!(tagline, concat!("Watch Movie", " ", $id).to_string() $(, $($skip),+)?),
|
|
||||||
overview: notsettable!(overview, concat!("Movie", " ", $id).to_string() $(, $($skip),+)?),
|
|
||||||
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_movie!(&db, 1, Success);
|
|
||||||
assert_movie!(&db, 1, UniqueViolation);
|
|
||||||
assert_movie!(&db, 2, Success);
|
|
||||||
assert_movie!(&db, 3, Success; id);
|
|
||||||
assert_movie!(&db, 4, NotNullViolation; title);
|
|
||||||
assert_movie!(&db, 5, NotNullViolation; tagline);
|
|
||||||
assert_movie!(&db, 6, NotNullViolation; overview);
|
|
||||||
assert_movie!(&db, 7, NotNullViolation; date);
|
|
||||||
|
|
||||||
// Shows
|
|
||||||
macro_rules! assert_show {
|
|
||||||
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, ShowId::from_raw($id));
|
|
||||||
assert_eq!(model.title, concat!("S", $id));
|
|
||||||
assert_eq!(model.tagline, concat!("Watch Show", " ", $id));
|
|
||||||
assert_eq!(model.overview, concat!("Show", " ", $id));
|
|
||||||
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
get_error_kind(model).expect("get_error_kind"),
|
|
||||||
ErrorKind::$error
|
|
||||||
);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::shows::ActiveModel {
|
|
||||||
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
title: notsettable!(title, concat!("S", $id).to_string() $(, $($skip),+)?),
|
|
||||||
tagline: notsettable!(tagline, concat!("Watch Show", " ", $id).to_string() $(, $($skip),+)?),
|
|
||||||
overview: notsettable!(overview, concat!("Show", " ", $id).to_string() $(, $($skip),+)?),
|
|
||||||
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_show!(&db, 1, Success);
|
|
||||||
assert_show!(&db, 1, UniqueViolation);
|
|
||||||
assert_show!(&db, 2, Success);
|
|
||||||
assert_show!(&db, 3, Success; id);
|
|
||||||
assert_show!(&db, 4, NotNullViolation; title);
|
|
||||||
assert_show!(&db, 5, NotNullViolation; tagline);
|
|
||||||
assert_show!(&db, 6, NotNullViolation; overview);
|
|
||||||
assert_show!(&db, 7, NotNullViolation; date);
|
|
||||||
|
|
||||||
// Seasons
|
|
||||||
macro_rules! assert_season {
|
|
||||||
($db:expr, $show:literal, $season:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.show, ShowId::from_raw($show));
|
|
||||||
assert_eq!(model.season, $season);
|
|
||||||
assert_eq!(model.title, concat!("S", $show, "S", $season));
|
|
||||||
assert_eq!(model.overview, concat!("Show", " ", $show, " ", "Season", " ", $season));
|
|
||||||
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $show + $season).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $season:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
get_error_kind(model).expect("get_error_kind"),
|
|
||||||
ErrorKind::$error
|
|
||||||
);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $show:literal, $season:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::seasons::ActiveModel {
|
|
||||||
show: notsettable!(show, ShowId::from_raw($show) $(, $($skip),+)?),
|
|
||||||
season: notsettable!(season, $season $(, $($skip),+)?),
|
|
||||||
title: notsettable!(title, concat!("S", $show, "S", $season).to_string() $(, $($skip),+)?),
|
|
||||||
overview: notsettable!(overview, concat!("Show", " ", $show, " ", "Season", " ", $season).to_string() $(, $($skip),+)?),
|
|
||||||
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $show + $season).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_season!(&db, 1, 1, Success);
|
|
||||||
assert_season!(&db, 1, 1, UniqueViolation);
|
|
||||||
assert_season!(&db, 2, 1, Success);
|
|
||||||
assert_season!(&db, 0, 1, ForeignKeyViolation);
|
|
||||||
assert_season!(&db, 1, 2, Success);
|
|
||||||
assert_season!(&db, 1, 3, NotNullViolation; show);
|
|
||||||
assert_season!(&db, 1, 4, NotNullViolation; season);
|
|
||||||
assert_season!(&db, 1, 5, NotNullViolation; title);
|
|
||||||
assert_season!(&db, 1, 6, NotNullViolation; overview);
|
|
||||||
assert_season!(&db, 1, 7, NotNullViolation; date);
|
|
||||||
|
|
||||||
// Episodes
|
|
||||||
macro_rules! assert_episode {
|
|
||||||
($db:expr, $show:literal, $season:literal, $episode:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.show, ShowId::from_raw($show));
|
|
||||||
assert_eq!(model.season, $season);
|
|
||||||
assert_eq!(model.episode, $episode);
|
|
||||||
assert_eq!(model.title, concat!("S", $show, "S", $season, "E", $episode));
|
|
||||||
assert_eq!(model.overview, concat!("Show", " ", $show, " ", "Season", " ", $season, " ", "Episode", " ", $episode));
|
|
||||||
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $show + $season + $episode).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $season:literal, $episode:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
get_error_kind(model).expect("get_error_kind"),
|
|
||||||
ErrorKind::$error
|
|
||||||
);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::episodes::ActiveModel {
|
|
||||||
show: notsettable!(show, ShowId::from_raw($show) $(, $($skip),+)?),
|
|
||||||
season: notsettable!(season, $season $(, $($skip),+)?),
|
|
||||||
episode: notsettable!(episode, $episode $(, $($skip),+)?),
|
|
||||||
title: notsettable!(title, concat!("S", $show, "S", $season, "E", $episode).to_string() $(, $($skip),+)?),
|
|
||||||
overview: notsettable!(overview, concat!("Show", " ", $show, " ", "Season", " ", $season, " ", "Episode", " ", $episode).to_string() $(, $($skip),+)?),
|
|
||||||
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $show + $season + $episode).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_episode!(&db, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 1, 2, 1, Success);
|
|
||||||
assert_episode!(&db, 2, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 0, 1, ForeignKeyViolation);
|
|
||||||
assert_episode!(&db, 0, 1, 1, ForeignKeyViolation);
|
|
||||||
assert_episode!(&db, 1, 1, 2, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 3, NotNullViolation; show);
|
|
||||||
assert_episode!(&db, 1, 1, 4, NotNullViolation; season);
|
|
||||||
assert_episode!(&db, 1, 1, 4, NotNullViolation; episode);
|
|
||||||
assert_episode!(&db, 1, 1, 5, NotNullViolation; title);
|
|
||||||
assert_episode!(&db, 1, 1, 6, NotNullViolation; overview);
|
|
||||||
assert_episode!(&db, 1, 1, 7, NotNullViolation; date);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
//! Movie entity
|
|
||||||
|
|
||||||
use flix_model::id::MovieId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a flix movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_info_movies")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The movie's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: MovieId,
|
|
||||||
/// The movie's title
|
|
||||||
pub title: String,
|
|
||||||
/// The movie's tagline
|
|
||||||
pub tagline: String,
|
|
||||||
/// The movie's overview
|
|
||||||
pub overview: String,
|
|
||||||
/// The movie's release date
|
|
||||||
pub date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
//! Season entity
|
|
||||||
|
|
||||||
use flix_model::id::ShowId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use flix_model::numbers::SeasonNumber;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a flix season
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_info_seasons")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The season's show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub show: ShowId,
|
|
||||||
/// The season's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub season: SeasonNumber,
|
|
||||||
/// The season's title
|
|
||||||
pub title: String,
|
|
||||||
/// The season's overview
|
|
||||||
pub overview: String,
|
|
||||||
/// The season's air date
|
|
||||||
pub date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The show this season belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::shows::Entity",
|
|
||||||
from = "Column::Show",
|
|
||||||
to = "super::shows::Column::Id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Show,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::shows::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Show.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
//! Show entity
|
|
||||||
|
|
||||||
use flix_model::id::ShowId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a flix show
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_info_shows")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: ShowId,
|
|
||||||
/// The show's title
|
|
||||||
pub title: String,
|
|
||||||
/// The show's tagline
|
|
||||||
pub tagline: String,
|
|
||||||
/// The show's overview
|
|
||||||
pub overview: String,
|
|
||||||
/// The show's air date
|
|
||||||
pub date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The seasons that are part of this show
|
|
||||||
#[sea_orm(has_many = "super::seasons::Entity")]
|
|
||||||
Seasons,
|
|
||||||
/// The episodes that are part of this show
|
|
||||||
#[sea_orm(has_many = "super::episodes::Entity")]
|
|
||||||
Episodes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::seasons::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Seasons.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::episodes::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Episodes.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1737
-197
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,677 @@
|
|||||||
|
//! This module contains entities for storing dynamic data from TMDB
|
||||||
|
|
||||||
|
/// Collection entity
|
||||||
|
pub mod collections {
|
||||||
|
use flix_model::id::CollectionId as FlixId;
|
||||||
|
use flix_tmdb::model::id::CollectionId;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a tmdb collection
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_tmdb_collections")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The collection's TMDB ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_id: CollectionId,
|
||||||
|
/// The collection's ID
|
||||||
|
#[sea_orm(unique)]
|
||||||
|
pub flix_id: FlixId,
|
||||||
|
/// The date of the last update
|
||||||
|
pub last_update: DateTime<Utc>,
|
||||||
|
/// The number of movies in the collection
|
||||||
|
pub movie_count: u16,
|
||||||
|
|
||||||
|
/// The info for this collection
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "flix_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::collections::Entity>,
|
||||||
|
|
||||||
|
/// Movies that are in this collection
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub movies: HasMany<super::movies::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Movie entity
|
||||||
|
pub mod movies {
|
||||||
|
use flix_model::id::MovieId as FlixId;
|
||||||
|
use flix_tmdb::model::id::{CollectionId, MovieId};
|
||||||
|
|
||||||
|
use seamantic::model::duration::Seconds;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a tmdb movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_tmdb_movies")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The movie's TMDB ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_id: MovieId,
|
||||||
|
/// The movie's ID
|
||||||
|
#[sea_orm(unique)]
|
||||||
|
pub flix_id: FlixId,
|
||||||
|
/// The date of the last update
|
||||||
|
pub last_update: DateTime<Utc>,
|
||||||
|
/// The movie's runtime in seconds
|
||||||
|
pub runtime: Seconds,
|
||||||
|
/// The TMDB ID of the collection this movie belongs to
|
||||||
|
#[sea_orm(indexed)]
|
||||||
|
pub collection_id: Option<CollectionId>,
|
||||||
|
|
||||||
|
/// The collection this movie belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "collection_id",
|
||||||
|
to = "tmdb_id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub collection: HasOne<super::collections::Entity>,
|
||||||
|
/// The info for this movie
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "flix_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::movies::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Show entity
|
||||||
|
pub mod shows {
|
||||||
|
use flix_model::id::ShowId as FlixId;
|
||||||
|
use flix_tmdb::model::id::ShowId;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a tmdb show
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_tmdb_shows")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The show's TMDB ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_id: ShowId,
|
||||||
|
/// The show's ID
|
||||||
|
#[sea_orm(unique)]
|
||||||
|
pub flix_id: FlixId,
|
||||||
|
/// The movie's runtime in seconds
|
||||||
|
pub last_update: DateTime<Utc>,
|
||||||
|
/// The number of seasons the show has
|
||||||
|
pub number_of_seasons: u32,
|
||||||
|
|
||||||
|
/// The info for this show
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "flix_id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::shows::Entity>,
|
||||||
|
|
||||||
|
/// Seasons that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub seasons: HasMany<super::seasons::Entity>,
|
||||||
|
/// Episodes that are part of this show
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Season entity
|
||||||
|
pub mod seasons {
|
||||||
|
use flix_model::id::ShowId as FlixId;
|
||||||
|
use flix_model::numbers::SeasonNumber;
|
||||||
|
use flix_tmdb::model::id::ShowId;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a tmdb season
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_tmdb_seasons")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The season's show's TMDB ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_show: ShowId,
|
||||||
|
/// The season's TMDB season number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_season: SeasonNumber,
|
||||||
|
/// The season's show's ID
|
||||||
|
#[sea_orm(unique_key = "flix")]
|
||||||
|
pub flix_show: FlixId,
|
||||||
|
/// The season's number
|
||||||
|
#[sea_orm(unique_key = "flix")]
|
||||||
|
pub flix_season: SeasonNumber,
|
||||||
|
/// The date of the last update
|
||||||
|
pub last_update: DateTime<Utc>,
|
||||||
|
|
||||||
|
/// The show this season belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "tmdb_show",
|
||||||
|
to = "tmdb_id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub show: HasOne<super::shows::Entity>,
|
||||||
|
/// The info for this season
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "(flix_show, flix_season)",
|
||||||
|
to = "(show_id, season_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::seasons::Entity>,
|
||||||
|
|
||||||
|
/// Episodes that are part of this season
|
||||||
|
#[sea_orm(has_many)]
|
||||||
|
pub episodes: HasMany<super::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Season entity
|
||||||
|
pub mod episodes {
|
||||||
|
use flix_model::id::ShowId as FlixId;
|
||||||
|
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
use flix_tmdb::model::id::ShowId;
|
||||||
|
use seamantic::model::duration::Seconds;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a tmdb episode
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_tmdb_episodes")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The episode's show's TMDB ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_show: ShowId,
|
||||||
|
/// The episode's season's TMDB season number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_season: SeasonNumber,
|
||||||
|
/// The episode's TMDB episode number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub tmdb_episode: EpisodeNumber,
|
||||||
|
/// The episode's show's ID
|
||||||
|
#[sea_orm(unique_key = "flix")]
|
||||||
|
pub flix_show: FlixId,
|
||||||
|
/// The episode's season's number
|
||||||
|
#[sea_orm(unique_key = "flix")]
|
||||||
|
pub flix_season: SeasonNumber,
|
||||||
|
/// The episode's number
|
||||||
|
#[sea_orm(unique_key = "flix")]
|
||||||
|
pub flix_episode: EpisodeNumber,
|
||||||
|
/// The date of the last update
|
||||||
|
pub last_update: DateTime<Utc>,
|
||||||
|
/// The episode's runtime in seconds
|
||||||
|
pub runtime: Seconds,
|
||||||
|
|
||||||
|
/// The show this episode belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "tmdb_show",
|
||||||
|
to = "tmdb_id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub show: HasOne<super::shows::Entity>,
|
||||||
|
/// The season this episode belongs to
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "(tmdb_show, tmdb_season)",
|
||||||
|
to = "(tmdb_show, tmdb_season)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub season: HasOne<super::seasons::Entity>,
|
||||||
|
/// The info for this episode
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "(flix_show, flix_season, flix_episode)",
|
||||||
|
to = "(show_id, season_number, episode_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Macros for creating tmdb entities
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod test {
|
||||||
|
macro_rules! make_tmdb_collection {
|
||||||
|
($db:expr, $id:expr, $flix_id:expr) => {
|
||||||
|
$crate::entity::tmdb::collections::ActiveModel {
|
||||||
|
tmdb_id: Set(::flix_tmdb::model::id::CollectionId::from_raw($id)),
|
||||||
|
flix_id: Set(::flix_model::id::CollectionId::from_raw($flix_id)),
|
||||||
|
last_update: Set(::chrono::Utc::now()),
|
||||||
|
movie_count: Set(::core::default::Default::default()),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_tmdb_collection;
|
||||||
|
|
||||||
|
macro_rules! make_tmdb_movie {
|
||||||
|
($db:expr, $id:expr, $flix_id:expr) => {
|
||||||
|
$crate::entity::tmdb::movies::ActiveModel {
|
||||||
|
tmdb_id: Set(::flix_tmdb::model::id::MovieId::from_raw($id)),
|
||||||
|
flix_id: Set(::flix_model::id::MovieId::from_raw($flix_id)),
|
||||||
|
last_update: Set(::chrono::Utc::now()),
|
||||||
|
runtime: Set(::core::default::Default::default()),
|
||||||
|
collection_id: Set(None),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_tmdb_movie;
|
||||||
|
|
||||||
|
macro_rules! make_tmdb_show {
|
||||||
|
($db:expr, $id:expr, $flix_id:expr) => {
|
||||||
|
$crate::entity::tmdb::shows::ActiveModel {
|
||||||
|
tmdb_id: Set(::flix_tmdb::model::id::ShowId::from_raw($id)),
|
||||||
|
flix_id: Set(::flix_model::id::ShowId::from_raw($flix_id)),
|
||||||
|
last_update: Set(::chrono::Utc::now()),
|
||||||
|
number_of_seasons: Set(::core::default::Default::default()),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_tmdb_show;
|
||||||
|
|
||||||
|
macro_rules! make_tmdb_season {
|
||||||
|
($db:expr, $show:expr, $season:expr, $flix_show:expr, $flix_season:expr) => {
|
||||||
|
$crate::entity::tmdb::seasons::ActiveModel {
|
||||||
|
tmdb_show: Set(::flix_tmdb::model::id::ShowId::from_raw($show)),
|
||||||
|
tmdb_season: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
flix_show: Set(::flix_model::id::ShowId::from_raw($flix_show)),
|
||||||
|
flix_season: Set(::flix_model::numbers::SeasonNumber::new($flix_season)),
|
||||||
|
last_update: Set(::chrono::Utc::now()),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_tmdb_season;
|
||||||
|
|
||||||
|
macro_rules! make_tmdb_episode {
|
||||||
|
($db:expr, $show:expr, $season:expr, $episode:expr, $flix_show:expr, $flix_season:expr, $flix_episode:expr) => {
|
||||||
|
$crate::entity::tmdb::episodes::ActiveModel {
|
||||||
|
tmdb_show: Set(::flix_tmdb::model::id::ShowId::from_raw($show)),
|
||||||
|
tmdb_season: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
tmdb_episode: Set(::flix_model::numbers::EpisodeNumber::new($episode)),
|
||||||
|
flix_show: Set(::flix_model::id::ShowId::from_raw($flix_show)),
|
||||||
|
flix_season: Set(::flix_model::numbers::SeasonNumber::new($flix_season)),
|
||||||
|
flix_episode: Set(::flix_model::numbers::EpisodeNumber::new($flix_episode)),
|
||||||
|
last_update: Set(::chrono::Utc::now()),
|
||||||
|
runtime: Set(::core::default::Default::default()),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_tmdb_episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use core::time::Duration;
|
||||||
|
|
||||||
|
use flix_model::id::{CollectionId, MovieId, ShowId};
|
||||||
|
use flix_tmdb::model::id::{
|
||||||
|
CollectionId as TmdbCollectionId, MovieId as TmdbMovieId, ShowId as TmdbShowId,
|
||||||
|
};
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use sea_orm::sqlx::error::ErrorKind;
|
||||||
|
|
||||||
|
use crate::entity::info::test::{
|
||||||
|
make_info_collection, make_info_episode, make_info_movie, make_info_season, make_info_show,
|
||||||
|
};
|
||||||
|
use crate::tests::new_initialized_memory_db;
|
||||||
|
|
||||||
|
use super::super::tests::get_error_kind;
|
||||||
|
use super::super::tests::notsettable;
|
||||||
|
use super::test::{
|
||||||
|
make_tmdb_collection, make_tmdb_episode, make_tmdb_movie, make_tmdb_season, make_tmdb_show,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn use_test_macros() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
make_info_collection!(&db, 1);
|
||||||
|
make_info_movie!(&db, 1);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
make_info_episode!(&db, 1, 1, 1);
|
||||||
|
|
||||||
|
make_tmdb_collection!(&db, 1, 1);
|
||||||
|
make_tmdb_movie!(&db, 1, 1);
|
||||||
|
make_tmdb_show!(&db, 1, 1);
|
||||||
|
make_tmdb_season!(&db, 1, 1, 1, 1);
|
||||||
|
make_tmdb_episode!(&db, 1, 1, 1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_collections() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_collection {
|
||||||
|
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.tmdb_id, TmdbCollectionId::from_raw($tid));
|
||||||
|
assert_eq!(model.flix_id, CollectionId::from_raw($id));
|
||||||
|
assert_eq!(model.last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
assert_eq!(model.movie_count, $id);
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::collections::ActiveModel {
|
||||||
|
tmdb_id: notsettable!(tmdb_id, TmdbCollectionId::from_raw($tid) $(, $($skip),+)?),
|
||||||
|
flix_id: notsettable!(flix_id, CollectionId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
movie_count: notsettable!(movie_count, $id $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_collection!(&db, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_collection!(&db, 1);
|
||||||
|
assert_collection!(&db, 1, 1, Success);
|
||||||
|
assert_collection!(&db, 1, 1, UniqueViolation);
|
||||||
|
|
||||||
|
assert_collection!(&db, 1, 2, UniqueViolation);
|
||||||
|
assert_collection!(&db, 2, 1, UniqueViolation);
|
||||||
|
make_info_collection!(&db, 2);
|
||||||
|
assert_collection!(&db, 2, 2, Success);
|
||||||
|
|
||||||
|
make_info_collection!(&db, 3);
|
||||||
|
assert_collection!(&db, 3, 3, Success; tmdb_id);
|
||||||
|
assert_collection!(&db, 4, 4, NotNullViolation; flix_id);
|
||||||
|
assert_collection!(&db, 5, 5, NotNullViolation; last_update);
|
||||||
|
assert_collection!(&db, 6, 6, NotNullViolation; movie_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_movies() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_movie {
|
||||||
|
($db:expr, $id:literal, $tid:literal, $cid:expr, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.tmdb_id, TmdbMovieId::from_raw($tid));
|
||||||
|
assert_eq!(model.flix_id, MovieId::from_raw($id));
|
||||||
|
assert_eq!(model.last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
assert_eq!(model.runtime, Duration::from_secs($tid).into());
|
||||||
|
assert_eq!(model.collection_id, $cid.map(TmdbCollectionId::from_raw));
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $tid:literal, $cid:expr, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $tid:literal, $cid:expr $(; $($skip:ident),+)?) => {
|
||||||
|
super::movies::ActiveModel {
|
||||||
|
tmdb_id: notsettable!(tmdb_id, TmdbMovieId::from_raw($tid) $(, $($skip),+)?),
|
||||||
|
flix_id: notsettable!(flix_id, MovieId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
runtime: notsettable!(runtime, Duration::from_secs($tid).into() $(, $($skip),+)?),
|
||||||
|
collection_id: notsettable!(collection_id, $cid.map(TmdbCollectionId::from_raw) $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_movie!(&db, 1, 1, None, ForeignKeyViolation);
|
||||||
|
make_info_movie!(&db, 1);
|
||||||
|
assert_movie!(&db, 1, 1, None, Success);
|
||||||
|
assert_movie!(&db, 1, 1, None, UniqueViolation);
|
||||||
|
|
||||||
|
make_info_movie!(&db, 2);
|
||||||
|
assert_movie!(&db, 2, 2, Some(2), ForeignKeyViolation);
|
||||||
|
make_info_collection!(&db, 2);
|
||||||
|
make_tmdb_collection!(&db, 2, 2);
|
||||||
|
assert_movie!(&db, 2, 2, Some(2), Success);
|
||||||
|
assert_movie!(&db, 1, 2, None, UniqueViolation);
|
||||||
|
assert_movie!(&db, 2, 1, None, UniqueViolation);
|
||||||
|
|
||||||
|
make_info_movie!(&db, 3);
|
||||||
|
assert_movie!(&db, 3, 3, None, Success; tmdb_id);
|
||||||
|
assert_movie!(&db, 4, 4, None, NotNullViolation; flix_id);
|
||||||
|
assert_movie!(&db, 5, 5, None, NotNullViolation; last_update);
|
||||||
|
assert_movie!(&db, 6, 6, None, NotNullViolation; runtime);
|
||||||
|
assert_movie!(&db, 7, 7, None, ForeignKeyViolation; collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_shows() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_show {
|
||||||
|
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.tmdb_id, TmdbShowId::from_raw($tid));
|
||||||
|
assert_eq!(model.flix_id, ShowId::from_raw($id));
|
||||||
|
assert_eq!(model.last_update, NaiveDate::from_yo_opt($tid, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
assert_eq!(model.number_of_seasons, $id);
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_error_kind(model).expect("get_error_kind"),
|
||||||
|
ErrorKind::$error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::shows::ActiveModel {
|
||||||
|
tmdb_id: notsettable!(tmdb_id, TmdbShowId::from_raw($tid) $(, $($skip),+)?),
|
||||||
|
flix_id: notsettable!(flix_id, ShowId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($tid, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
number_of_seasons: notsettable!(number_of_seasons, $id $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_show!(&db, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
assert_show!(&db, 1, 1, Success);
|
||||||
|
assert_show!(&db, 1, 1, UniqueViolation);
|
||||||
|
|
||||||
|
assert_show!(&db, 1, 2, UniqueViolation);
|
||||||
|
assert_show!(&db, 2, 1, UniqueViolation);
|
||||||
|
make_info_show!(&db, 2);
|
||||||
|
assert_show!(&db, 2, 2, Success);
|
||||||
|
|
||||||
|
make_info_show!(&db, 3);
|
||||||
|
assert_show!(&db, 3, 3, Success; tmdb_id);
|
||||||
|
assert_show!(&db, 4, 4, NotNullViolation; flix_id);
|
||||||
|
assert_show!(&db, 5, 5, NotNullViolation; last_update);
|
||||||
|
assert_show!(&db, 6, 6, NotNullViolation; number_of_seasons);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_seasons() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_season {
|
||||||
|
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
|
||||||
|
assert_eq!(model.tmdb_season, ::flix_model::numbers::SeasonNumber::new($tseason));
|
||||||
|
assert_eq!(model.flix_show, ShowId::from_raw($show));
|
||||||
|
assert_eq!(model.flix_season, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.last_update, NaiveDate::from_yo_opt($tshow, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_error_kind(model).expect("get_error_kind"),
|
||||||
|
ErrorKind::$error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::seasons::ActiveModel {
|
||||||
|
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
|
||||||
|
tmdb_season: notsettable!(tmdb_season, ::flix_model::numbers::SeasonNumber::new($tseason) $(, $($skip),+)?),
|
||||||
|
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
|
||||||
|
flix_season: notsettable!(flix_season, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($tshow, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_tmdb_show!(&db, 1, 1);
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
assert_season!(&db, 1, 1, 1, 1, Success);
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 1, 1, 1, UniqueViolation);
|
||||||
|
assert_season!(&db, 1, 1, 2, 1, UniqueViolation);
|
||||||
|
assert_season!(&db, 2, 1, 1, 1, UniqueViolation);
|
||||||
|
make_info_season!(&db, 1, 2);
|
||||||
|
assert_season!(&db, 1, 2, 1, 2, Success);
|
||||||
|
|
||||||
|
assert_season!(&db, 1, 3, 1, 3, NotNullViolation; tmdb_show);
|
||||||
|
assert_season!(&db, 1, 4, 1, 4, NotNullViolation; tmdb_season);
|
||||||
|
assert_season!(&db, 1, 5, 1, 5, NotNullViolation; flix_show);
|
||||||
|
assert_season!(&db, 1, 6, 1, 6, NotNullViolation; flix_season);
|
||||||
|
assert_season!(&db, 1, 7, 1, 7, NotNullViolation; last_update);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_episodes() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_episode {
|
||||||
|
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
|
||||||
|
assert_eq!(model.tmdb_season, ::flix_model::numbers::SeasonNumber::new($tseason));
|
||||||
|
assert_eq!(model.tmdb_episode, ::flix_model::numbers::EpisodeNumber::new($tepisode));
|
||||||
|
assert_eq!(model.flix_show, ShowId::from_raw($show));
|
||||||
|
assert_eq!(model.flix_season, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.flix_episode, ::flix_model::numbers::EpisodeNumber::new($episode));
|
||||||
|
assert_eq!(model.last_update, NaiveDate::from_yo_opt($tshow, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
assert_eq!(model.runtime, Duration::from_secs($tshow).into());
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_error_kind(model).expect("get_error_kind"),
|
||||||
|
ErrorKind::$error
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::episodes::ActiveModel {
|
||||||
|
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
|
||||||
|
tmdb_season: notsettable!(tmdb_season, ::flix_model::numbers::SeasonNumber::new($tseason) $(, $($skip),+)?),
|
||||||
|
tmdb_episode: notsettable!(tmdb_episode, ::flix_model::numbers::EpisodeNumber::new($tepisode) $(, $($skip),+)?),
|
||||||
|
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
|
||||||
|
flix_season: notsettable!(flix_season, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
flix_episode: notsettable!(flix_episode, ::flix_model::numbers::EpisodeNumber::new($episode) $(, $($skip),+)?),
|
||||||
|
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($tshow, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
runtime: notsettable!(runtime, Duration::from_secs($tshow).into() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
make_tmdb_show!(&db, 1, 1);
|
||||||
|
make_tmdb_season!(&db, 1, 1, 1, 1);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_episode!(&db, 1, 1, 1);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, 1, 1, Success);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, 1, 1, UniqueViolation);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, 2, 1, UniqueViolation);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 2, 1, 1, UniqueViolation);
|
||||||
|
assert_episode!(&db, 1, 2, 1, 1, 1, 1, UniqueViolation);
|
||||||
|
assert_episode!(&db, 2, 1, 1, 1, 1, 1, UniqueViolation);
|
||||||
|
make_info_episode!(&db, 1, 1, 2);
|
||||||
|
assert_episode!(&db, 1, 1, 2, 1, 1, 2, Success);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 3, NotNullViolation; tmdb_show);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 4, NotNullViolation; tmdb_season);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 5, NotNullViolation; tmdb_episode);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 6, NotNullViolation; flix_show);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 7, NotNullViolation; flix_season);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 8, NotNullViolation; flix_episode);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 9, NotNullViolation; last_update);
|
||||||
|
assert_episode!(&db, 1, 1, 3, 1, 1, 10, NotNullViolation; runtime);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
//! Collection entity
|
|
||||||
|
|
||||||
use flix_model::id::CollectionId as FlixId;
|
|
||||||
use flix_tmdb::model::id::CollectionId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a tmdb collection
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_tmdb_collections")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The collection's TMDB ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_id: CollectionId,
|
|
||||||
/// The collection's ID
|
|
||||||
pub flix_id: FlixId,
|
|
||||||
/// The date of the last update
|
|
||||||
pub last_update: NaiveDate,
|
|
||||||
/// The number of movies in the collection
|
|
||||||
pub movie_count: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The movies that are part of this collection
|
|
||||||
#[sea_orm(has_many = "super::movies::Entity")]
|
|
||||||
Movies,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::movies::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Movies.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
//! Season entity
|
|
||||||
|
|
||||||
use flix_model::id::ShowId as FlixId;
|
|
||||||
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
|
||||||
use flix_tmdb::model::id::ShowId;
|
|
||||||
use seamantic::model::duration::Seconds;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a tmdb episode
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_tmdb_episodes")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The episode's show's TMDB ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_show: ShowId,
|
|
||||||
/// The episode's season's TMDB season number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_season: SeasonNumber,
|
|
||||||
/// The episode's TMDB episode number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_episode: EpisodeNumber,
|
|
||||||
/// The episode's show's ID
|
|
||||||
pub flix_show: FlixId,
|
|
||||||
/// The episode's season's number
|
|
||||||
pub flix_season: SeasonNumber,
|
|
||||||
/// The episode's number
|
|
||||||
pub flix_episode: EpisodeNumber,
|
|
||||||
/// The date of the last update
|
|
||||||
pub last_update: NaiveDate,
|
|
||||||
/// The episode's runtime in seconds
|
|
||||||
pub runtime: Seconds,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,278 +0,0 @@
|
|||||||
//! This module contains entities for storing dynamic data from TMDB
|
|
||||||
|
|
||||||
pub mod collections;
|
|
||||||
|
|
||||||
pub mod movies;
|
|
||||||
|
|
||||||
pub mod episodes;
|
|
||||||
pub mod seasons;
|
|
||||||
pub mod shows;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use core::time::Duration;
|
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, MovieId, ShowId};
|
|
||||||
use flix_tmdb::model::id::{
|
|
||||||
CollectionId as TmdbCollectionId, MovieId as TmdbMovieId, ShowId as TmdbShowId,
|
|
||||||
};
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::ActiveModelTrait;
|
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
|
||||||
use sea_orm::sqlx::error::ErrorKind;
|
|
||||||
use sea_orm_migration::MigratorTrait;
|
|
||||||
|
|
||||||
use crate::migration::Migrator;
|
|
||||||
use crate::tests::new_memory_db;
|
|
||||||
|
|
||||||
use super::super::tests::get_error_kind;
|
|
||||||
use super::super::tests::notsettable;
|
|
||||||
use super::super::tests::{
|
|
||||||
make_flix_collection, make_flix_episode, make_flix_movie, make_flix_season, make_flix_show,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_inserts() {
|
|
||||||
let db = new_memory_db().await;
|
|
||||||
Migrator::up(&db, None).await.expect("up");
|
|
||||||
|
|
||||||
// Collections
|
|
||||||
macro_rules! assert_collection {
|
|
||||||
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.tmdb_id, TmdbCollectionId::from_raw($tid));
|
|
||||||
assert_eq!(model.flix_id, CollectionId::from_raw($id));
|
|
||||||
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
|
|
||||||
assert_eq!(model.movie_count, $id);
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::collections::ActiveModel {
|
|
||||||
tmdb_id: notsettable!(tmdb_id, TmdbCollectionId::from_raw($tid) $(, $($skip),+)?),
|
|
||||||
flix_id: notsettable!(flix_id, CollectionId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
movie_count: notsettable!(movie_count, $id $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_collection!(&db, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_collection!(&db, 1);
|
|
||||||
make_flix_collection!(&db, 2);
|
|
||||||
make_flix_collection!(&db, 3);
|
|
||||||
|
|
||||||
assert_collection!(&db, 1, 1, Success);
|
|
||||||
assert_collection!(&db, 1, 1, UniqueViolation);
|
|
||||||
assert_collection!(&db, 1, 2, UniqueViolation);
|
|
||||||
assert_collection!(&db, 2, 1, UniqueViolation);
|
|
||||||
assert_collection!(&db, 2, 2, Success);
|
|
||||||
assert_collection!(&db, 3, 3, Success; tmdb_id);
|
|
||||||
assert_collection!(&db, 4, 4, NotNullViolation; flix_id);
|
|
||||||
assert_collection!(&db, 5, 5, NotNullViolation; last_update);
|
|
||||||
assert_collection!(&db, 6, 6, NotNullViolation; movie_count);
|
|
||||||
|
|
||||||
// Movies
|
|
||||||
macro_rules! assert_movie {
|
|
||||||
($db:expr, $id:literal, $tid:literal, $cid:expr, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.tmdb_id, TmdbMovieId::from_raw($tid));
|
|
||||||
assert_eq!(model.flix_id, MovieId::from_raw($id));
|
|
||||||
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
|
|
||||||
assert_eq!(model.runtime, Duration::from_secs($tid).into());
|
|
||||||
assert_eq!(model.collection, $cid);
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $tid:literal, $cid:expr, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $tid:literal, $cid:expr $(; $($skip:ident),+)?) => {
|
|
||||||
super::movies::ActiveModel {
|
|
||||||
tmdb_id: notsettable!(tmdb_id, TmdbMovieId::from_raw($tid) $(, $($skip),+)?),
|
|
||||||
flix_id: notsettable!(flix_id, MovieId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
runtime: notsettable!(runtime, Duration::from_secs($tid).into() $(, $($skip),+)?),
|
|
||||||
collection: notsettable!(collection, $cid $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_movie!(
|
|
||||||
&db,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
Some(TmdbCollectionId::from_raw(1)),
|
|
||||||
ForeignKeyViolation
|
|
||||||
);
|
|
||||||
make_flix_movie!(&db, 1);
|
|
||||||
make_flix_movie!(&db, 2);
|
|
||||||
make_flix_movie!(&db, 3);
|
|
||||||
|
|
||||||
assert_movie!(&db, 1, 1, Some(TmdbCollectionId::from_raw(1)), Success);
|
|
||||||
assert_movie!(&db, 1, 1, None, UniqueViolation);
|
|
||||||
assert_movie!(&db, 1, 2, None, UniqueViolation);
|
|
||||||
assert_movie!(&db, 2, 1, None, UniqueViolation);
|
|
||||||
assert_movie!(&db, 2, 2, Some(TmdbCollectionId::from_raw(1)), Success);
|
|
||||||
assert_movie!(&db, 3, 3, None, Success; tmdb_id);
|
|
||||||
assert_movie!(&db, 4, 4, None, NotNullViolation; flix_id);
|
|
||||||
assert_movie!(&db, 5, 5, None, NotNullViolation; last_update);
|
|
||||||
assert_movie!(&db, 6, 6, None, NotNullViolation; runtime);
|
|
||||||
assert_movie!(&db, 7, 7, None, ForeignKeyViolation; collection); // Must be `Set(None)`
|
|
||||||
|
|
||||||
// Shows
|
|
||||||
macro_rules! assert_show {
|
|
||||||
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.tmdb_id, TmdbShowId::from_raw($tid));
|
|
||||||
assert_eq!(model.flix_id, ShowId::from_raw($id));
|
|
||||||
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
|
|
||||||
assert_eq!(model.number_of_seasons, $id);
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
get_error_kind(model).expect("get_error_kind"),
|
|
||||||
ErrorKind::$error
|
|
||||||
);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::shows::ActiveModel {
|
|
||||||
tmdb_id: notsettable!(tmdb_id, TmdbShowId::from_raw($tid) $(, $($skip),+)?),
|
|
||||||
flix_id: notsettable!(flix_id, ShowId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
number_of_seasons: notsettable!(number_of_seasons, $id $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_show!(&db, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_show!(&db, 1);
|
|
||||||
make_flix_show!(&db, 2);
|
|
||||||
make_flix_show!(&db, 3);
|
|
||||||
|
|
||||||
assert_show!(&db, 1, 1, Success);
|
|
||||||
assert_show!(&db, 1, 1, UniqueViolation);
|
|
||||||
assert_show!(&db, 1, 2, UniqueViolation);
|
|
||||||
assert_show!(&db, 2, 1, UniqueViolation);
|
|
||||||
assert_show!(&db, 2, 2, Success);
|
|
||||||
assert_show!(&db, 3, 3, Success; tmdb_id);
|
|
||||||
assert_show!(&db, 4, 4, NotNullViolation; flix_id);
|
|
||||||
assert_show!(&db, 5, 5, NotNullViolation; last_update);
|
|
||||||
assert_show!(&db, 6, 6, NotNullViolation; number_of_seasons);
|
|
||||||
|
|
||||||
// Seasons
|
|
||||||
macro_rules! assert_season {
|
|
||||||
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
|
|
||||||
assert_eq!(model.tmdb_season, $tseason);
|
|
||||||
assert_eq!(model.flix_show, ShowId::from_raw($show));
|
|
||||||
assert_eq!(model.flix_season, $season);
|
|
||||||
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
get_error_kind(model).expect("get_error_kind"),
|
|
||||||
ErrorKind::$error
|
|
||||||
);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::seasons::ActiveModel {
|
|
||||||
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
|
|
||||||
tmdb_season: notsettable!(tmdb_season, $tseason $(, $($skip),+)?),
|
|
||||||
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
|
|
||||||
flix_season: notsettable!(flix_season, $season $(, $($skip),+)?),
|
|
||||||
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_season!(&db, 1, 1, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_season!(&db, 1, 1);
|
|
||||||
make_flix_season!(&db, 1, 2);
|
|
||||||
|
|
||||||
assert_season!(&db, 1, 1, 1, 1, Success);
|
|
||||||
assert_season!(&db, 1, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_season!(&db, 1, 1, 2, 1, UniqueViolation);
|
|
||||||
assert_season!(&db, 2, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_season!(&db, 1, 2, 1, 2, Success);
|
|
||||||
assert_season!(&db, 1, 3, 1, 3, NotNullViolation; tmdb_show);
|
|
||||||
assert_season!(&db, 1, 4, 1, 4, NotNullViolation; tmdb_season);
|
|
||||||
assert_season!(&db, 1, 5, 1, 5, NotNullViolation; flix_show);
|
|
||||||
assert_season!(&db, 1, 6, 1, 6, NotNullViolation; flix_season);
|
|
||||||
assert_season!(&db, 1, 7, 1, 7, NotNullViolation; last_update);
|
|
||||||
|
|
||||||
// Episodes
|
|
||||||
macro_rules! assert_episode {
|
|
||||||
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
|
|
||||||
assert_eq!(model.tmdb_season, $tseason);
|
|
||||||
assert_eq!(model.tmdb_episode, $tepisode);
|
|
||||||
assert_eq!(model.flix_show, ShowId::from_raw($show));
|
|
||||||
assert_eq!(model.flix_season, $season);
|
|
||||||
assert_eq!(model.flix_episode, $episode);
|
|
||||||
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt"));
|
|
||||||
assert_eq!(model.runtime, Duration::from_secs($tshow).into());
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
get_error_kind(model).expect("get_error_kind"),
|
|
||||||
ErrorKind::$error
|
|
||||||
);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::episodes::ActiveModel {
|
|
||||||
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
|
|
||||||
tmdb_season: notsettable!(tmdb_season, $tseason $(, $($skip),+)?),
|
|
||||||
tmdb_episode: notsettable!(tmdb_episode, $tepisode $(, $($skip),+)?),
|
|
||||||
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
|
|
||||||
flix_season: notsettable!(flix_season, $season $(, $($skip),+)?),
|
|
||||||
flix_episode: notsettable!(flix_episode, $episode $(, $($skip),+)?),
|
|
||||||
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
runtime: notsettable!(runtime, Duration::from_secs($tshow).into() $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_episode!(&db, 1, 1, 1);
|
|
||||||
make_flix_episode!(&db, 1, 1, 2);
|
|
||||||
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, 2, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 2, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 1, 2, 1, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 2, 1, 1, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 1, 1, 2, 1, 1, 2, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 3, NotNullViolation; tmdb_show);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 4, NotNullViolation; tmdb_season);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 5, NotNullViolation; tmdb_episode);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 6, NotNullViolation; flix_show);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 7, NotNullViolation; flix_season);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 8, NotNullViolation; flix_episode);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 9, NotNullViolation; last_update);
|
|
||||||
assert_episode!(&db, 1, 1, 3, 1, 1, 10, NotNullViolation; runtime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
//! Movie entity
|
|
||||||
|
|
||||||
use flix_model::id::MovieId as FlixId;
|
|
||||||
use flix_tmdb::model::id::{CollectionId, MovieId};
|
|
||||||
|
|
||||||
use seamantic::model::duration::Seconds;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a tmdb movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_tmdb_movies")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The movie's TMDB ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_id: MovieId,
|
|
||||||
/// The movie's ID
|
|
||||||
pub flix_id: FlixId,
|
|
||||||
/// The date of the last update
|
|
||||||
pub last_update: NaiveDate,
|
|
||||||
/// The movie's runtime in seconds
|
|
||||||
pub runtime: Seconds,
|
|
||||||
/// The TMDB ID of the collection this movie belongs to
|
|
||||||
pub collection: Option<CollectionId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The collection this movie belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::collections::Entity",
|
|
||||||
from = "Column::Collection",
|
|
||||||
to = "super::collections::Column::TmdbId",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Collection,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::collections::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Collection.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
//! Season entity
|
|
||||||
|
|
||||||
use flix_model::id::ShowId as FlixId;
|
|
||||||
use flix_model::numbers::SeasonNumber;
|
|
||||||
use flix_tmdb::model::id::ShowId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a tmdb season
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_tmdb_seasons")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The season's show's TMDB ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_show: ShowId,
|
|
||||||
/// The season's TMDB season number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_season: SeasonNumber,
|
|
||||||
/// The season's show's ID
|
|
||||||
pub flix_show: FlixId,
|
|
||||||
/// The season's number
|
|
||||||
pub flix_season: SeasonNumber,
|
|
||||||
/// The date of the last update
|
|
||||||
pub last_update: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The show this season belongs to
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::shows::Entity",
|
|
||||||
from = "Column::TmdbShow",
|
|
||||||
to = "super::shows::Column::TmdbId",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Show,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::shows::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Show.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
//! Show entity
|
|
||||||
|
|
||||||
use flix_model::id::ShowId as FlixId;
|
|
||||||
use flix_tmdb::model::id::ShowId;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a tmdb show
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_tmdb_shows")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The show's TMDB ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub tmdb_id: ShowId,
|
|
||||||
/// The show's ID
|
|
||||||
pub flix_id: FlixId,
|
|
||||||
/// The movie's runtime in seconds
|
|
||||||
pub last_update: NaiveDate,
|
|
||||||
/// The number of seasons the show has
|
|
||||||
pub number_of_seasons: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
/// The seasons that are part of this show
|
|
||||||
#[sea_orm(has_many = "super::seasons::Entity")]
|
|
||||||
Seasons,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::seasons::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Seasons.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,579 @@
|
|||||||
|
//! This module contains entities for storing watched information
|
||||||
|
|
||||||
|
/// Collection entity
|
||||||
|
pub mod collections {
|
||||||
|
use flix_model::id::{CollectionId, RawId};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a watched movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_watched_collections")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The collection's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: CollectionId,
|
||||||
|
/// The user's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub user_id: RawId,
|
||||||
|
/// The date this collection was watched
|
||||||
|
pub watched_date: DateTime<Utc>,
|
||||||
|
|
||||||
|
/// The info for this collection
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::collections::Entity>,
|
||||||
|
/// The content for this collection
|
||||||
|
#[sea_orm(belongs_to, relation_enum = "Content", from = "id", to = "id", skip_fk)]
|
||||||
|
pub content: HasOne<entity::content::collections::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Movie entity
|
||||||
|
pub mod movies {
|
||||||
|
use flix_model::id::{MovieId, RawId};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a watched movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_watched_movies")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The movie's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: MovieId,
|
||||||
|
/// The user's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub user_id: RawId,
|
||||||
|
/// The date this movie was watched
|
||||||
|
pub watched_date: DateTime<Utc>,
|
||||||
|
|
||||||
|
/// The info for this movie
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
from = "id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::movies::Entity>,
|
||||||
|
/// The content for this movie
|
||||||
|
#[sea_orm(belongs_to, relation_enum = "Content", from = "id", to = "id", skip_fk)]
|
||||||
|
pub content: HasOne<entity::content::movies::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Show entity
|
||||||
|
pub mod shows {
|
||||||
|
use flix_model::id::{RawId, ShowId};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a watched movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_watched_shows")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: ShowId,
|
||||||
|
/// The user's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub user_id: RawId,
|
||||||
|
/// The date this show was watched
|
||||||
|
pub watched_date: DateTime<Utc>,
|
||||||
|
|
||||||
|
/// The info for this show
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "id",
|
||||||
|
to = "id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::shows::Entity>,
|
||||||
|
/// The content for this show
|
||||||
|
#[sea_orm(belongs_to, relation_enum = "Content", from = "id", to = "id", skip_fk)]
|
||||||
|
pub content: HasOne<entity::content::shows::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Season entity
|
||||||
|
pub mod seasons {
|
||||||
|
use flix_model::id::{RawId, ShowId};
|
||||||
|
use flix_model::numbers::SeasonNumber;
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a watched movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_watched_seasons")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The season's show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub show_id: ShowId,
|
||||||
|
/// The season's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub season_number: SeasonNumber,
|
||||||
|
/// The user's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub user_id: RawId,
|
||||||
|
/// The date this season was watched
|
||||||
|
pub watched_date: DateTime<Utc>,
|
||||||
|
|
||||||
|
/// The info for this season
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "(show_id, season_number)",
|
||||||
|
to = "(show_id, season_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::seasons::Entity>,
|
||||||
|
/// The content for this season
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Content",
|
||||||
|
from = "(show_id, season_number)",
|
||||||
|
to = "(show_id, season_number)",
|
||||||
|
skip_fk
|
||||||
|
)]
|
||||||
|
pub content: HasOne<entity::content::seasons::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Episode entity
|
||||||
|
pub mod episodes {
|
||||||
|
use flix_model::id::{RawId, ShowId};
|
||||||
|
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity;
|
||||||
|
|
||||||
|
/// The database representation of a watched movie
|
||||||
|
#[sea_orm::model]
|
||||||
|
#[derive(Debug, Clone, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "flix_watched_episodes")]
|
||||||
|
pub struct Model {
|
||||||
|
/// The episode's show's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub show_id: ShowId,
|
||||||
|
/// The episode's season's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub season_number: SeasonNumber,
|
||||||
|
/// The episode's number
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub episode_number: EpisodeNumber,
|
||||||
|
/// The user's ID
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub user_id: RawId,
|
||||||
|
/// The date this episode was watched
|
||||||
|
pub watched_date: DateTime<Utc>,
|
||||||
|
|
||||||
|
/// The info for this episode
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Info",
|
||||||
|
from = "(show_id, season_number, episode_number)",
|
||||||
|
to = "(show_id, season_number, episode_number)",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
pub info: HasOne<entity::info::episodes::Entity>,
|
||||||
|
/// The content for this episode
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to,
|
||||||
|
relation_enum = "Content",
|
||||||
|
from = "(show_id, season_number, episode_number)",
|
||||||
|
to = "(show_id, season_number, episode_number)",
|
||||||
|
skip_fk
|
||||||
|
)]
|
||||||
|
pub content: HasOne<entity::content::episodes::Entity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Macros for creating watched entities
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod test {
|
||||||
|
macro_rules! make_watched_movie {
|
||||||
|
($db:expr, $id:expr, $user:expr) => {
|
||||||
|
$crate::entity::watched::movies::ActiveModel {
|
||||||
|
id: Set(::flix_model::id::MovieId::from_raw($id)),
|
||||||
|
user_id: Set($user),
|
||||||
|
watched_date: Set(::chrono::Utc::now()),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_watched_movie;
|
||||||
|
|
||||||
|
macro_rules! make_watched_episode {
|
||||||
|
($db:expr, $show:expr, $season:expr, $episode:expr, $user:expr) => {
|
||||||
|
$crate::entity::watched::episodes::ActiveModel {
|
||||||
|
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
|
||||||
|
season_number: Set(::flix_model::numbers::SeasonNumber::new($season)),
|
||||||
|
episode_number: Set(::flix_model::numbers::EpisodeNumber::new($episode)),
|
||||||
|
user_id: Set($user),
|
||||||
|
watched_date: Set(::chrono::Utc::now()),
|
||||||
|
}
|
||||||
|
.insert($db)
|
||||||
|
.await
|
||||||
|
.expect("insert");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use make_watched_episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use flix_model::id::{MovieId, ShowId};
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::Condition;
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use sea_orm::sqlx::error::ErrorKind;
|
||||||
|
|
||||||
|
use crate::entity::content::test::{
|
||||||
|
make_content_collection, make_content_episode, make_content_library, make_content_movie,
|
||||||
|
make_content_season, make_content_show,
|
||||||
|
};
|
||||||
|
use crate::entity::info::test::{
|
||||||
|
make_info_episode, make_info_movie, make_info_season, make_info_show,
|
||||||
|
};
|
||||||
|
use crate::tests::new_initialized_memory_db;
|
||||||
|
|
||||||
|
use super::super::tests::get_error_kind;
|
||||||
|
use super::super::tests::notsettable;
|
||||||
|
use super::test::{make_watched_episode, make_watched_movie};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn use_test_macros() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
make_info_movie!(&db, 1);
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
make_info_episode!(&db, 1, 1, 1);
|
||||||
|
|
||||||
|
make_watched_movie!(&db, 1, 1);
|
||||||
|
make_watched_episode!(&db, 1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_movies() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_movie {
|
||||||
|
($db:expr, $id:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.id, MovieId::from_raw($id));
|
||||||
|
assert_eq!(model.user_id, $uid);
|
||||||
|
assert_eq!(model.watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $id:literal, $uid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::movies::ActiveModel {
|
||||||
|
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
|
||||||
|
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
|
||||||
|
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_movie!(&db, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_movie!(&db, 1);
|
||||||
|
assert_movie!(&db, 1, 1, Success);
|
||||||
|
assert_movie!(&db, 1, 2, Success);
|
||||||
|
|
||||||
|
assert_movie!(&db, 1, 1, UniqueViolation);
|
||||||
|
make_info_movie!(&db, 2);
|
||||||
|
assert_movie!(&db, 2, 1, Success);
|
||||||
|
assert_movie!(&db, 2, 2, Success);
|
||||||
|
|
||||||
|
assert_movie!(&db, 3, 1, NotNullViolation; id);
|
||||||
|
assert_movie!(&db, 4, 1, NotNullViolation; user_id);
|
||||||
|
assert_movie!(&db, 5, 1, NotNullViolation; watched_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_round_trip_episodes() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_episode {
|
||||||
|
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
|
||||||
|
.expect("insert");
|
||||||
|
|
||||||
|
assert_eq!(model.show_id, ShowId::from_raw($show));
|
||||||
|
assert_eq!(model.season_number, ::flix_model::numbers::SeasonNumber::new($season));
|
||||||
|
assert_eq!(model.episode_number, ::flix_model::numbers::EpisodeNumber::new($episode));
|
||||||
|
assert_eq!(model.user_id, $uid);
|
||||||
|
assert_eq!(model.watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc());
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
||||||
|
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
|
||||||
|
.expect_err("insert");
|
||||||
|
|
||||||
|
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
||||||
|
};
|
||||||
|
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal $(; $($skip:ident),+)?) => {
|
||||||
|
super::episodes::ActiveModel {
|
||||||
|
show_id: notsettable!(show_id, ShowId::from_raw($show) $(, $($skip),+)?),
|
||||||
|
season_number: notsettable!(season_number, ::flix_model::numbers::SeasonNumber::new($season) $(, $($skip),+)?),
|
||||||
|
episode_number: notsettable!(episode_number, ::flix_model::numbers::EpisodeNumber::new($episode) $(, $($skip),+)?),
|
||||||
|
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
|
||||||
|
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt").and_hms_opt(0, 0, 0).expect("and_hms_opt").and_utc() $(, $($skip),+)?),
|
||||||
|
}.insert($db).await
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_info_show!(&db, 1);
|
||||||
|
make_info_season!(&db, 1, 1);
|
||||||
|
make_info_show!(&db, 2);
|
||||||
|
make_info_season!(&db, 2, 1);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
assert_episode!(&db, 2, 1, 1, 1, ForeignKeyViolation);
|
||||||
|
make_info_episode!(&db, 1, 1, 1);
|
||||||
|
make_info_episode!(&db, 2, 1, 1);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, Success);
|
||||||
|
assert_episode!(&db, 1, 1, 1, 2, Success);
|
||||||
|
assert_episode!(&db, 2, 1, 1, 1, Success);
|
||||||
|
|
||||||
|
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
|
||||||
|
|
||||||
|
assert_episode!(&db, 3, 1, 1, 1, NotNullViolation; show_id);
|
||||||
|
assert_episode!(&db, 4, 1, 1, 1, NotNullViolation; season_number);
|
||||||
|
assert_episode!(&db, 5, 1, 1, 1, NotNullViolation; episode_number);
|
||||||
|
assert_episode!(&db, 6, 1, 1, 1, NotNullViolation; user_id);
|
||||||
|
assert_episode!(&db, 7, 1, 1, 1, NotNullViolation; watched_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_query_seasons() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_season {
|
||||||
|
($db:expr, $show:literal, $season:literal, $uid:literal, Watched) => {
|
||||||
|
assert_season!(@find, $db, $show, $season, $uid)
|
||||||
|
.ok_or(())
|
||||||
|
.expect("is none");
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $season:literal, $uid:literal, Unwatched) => {
|
||||||
|
assert_season!(@find, $db, $show, $season, $uid)
|
||||||
|
.ok_or(())
|
||||||
|
.expect_err("is some");
|
||||||
|
};
|
||||||
|
(@find, $db:expr, $show:literal, $season:literal, $uid:literal) => {
|
||||||
|
super::seasons::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(super::seasons::Column::ShowId.eq($show))
|
||||||
|
.add(super::seasons::Column::SeasonNumber.eq($season))
|
||||||
|
.add(super::seasons::Column::UserId.eq($uid)),
|
||||||
|
)
|
||||||
|
.one(&db)
|
||||||
|
.await
|
||||||
|
.expect("find.filter.one")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
make_content_show!(&db, 1, 1, None);
|
||||||
|
|
||||||
|
make_content_season!(&db, 1, 1, 1);
|
||||||
|
assert_season!(&db, 1, 1, 1, Unwatched);
|
||||||
|
make_content_episode!(&db, 1, 1, 1, 1);
|
||||||
|
assert_season!(&db, 1, 1, 1, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 1, 1, 1);
|
||||||
|
assert_season!(&db, 1, 1, 1, Watched);
|
||||||
|
assert_season!(&db, 1, 1, 2, Unwatched);
|
||||||
|
make_content_episode!(&db, 1, 1, 1, 2);
|
||||||
|
assert_season!(&db, 1, 1, 1, Unwatched);
|
||||||
|
|
||||||
|
make_content_season!(&db, 1, 1, 2);
|
||||||
|
make_content_episode!(&db, 1, 1, 2, 1);
|
||||||
|
make_content_episode!(&db, 1, 1, 2, 2, >1);
|
||||||
|
make_info_episode!(&db, 1, 2, 3);
|
||||||
|
make_content_episode!(&db, 1, 1, 2, 4);
|
||||||
|
assert_season!(&db, 1, 2, 1, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 2, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 3, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 2, 1, 1);
|
||||||
|
make_watched_episode!(&db, 1, 2, 1, 2);
|
||||||
|
make_watched_episode!(&db, 1, 2, 2, 3);
|
||||||
|
assert_season!(&db, 1, 2, 1, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 2, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 3, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 2, 2, 1);
|
||||||
|
make_watched_episode!(&db, 1, 2, 2, 2);
|
||||||
|
make_watched_episode!(&db, 1, 2, 1, 3);
|
||||||
|
assert_season!(&db, 1, 2, 1, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 2, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 3, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 2, 4, 1);
|
||||||
|
assert_season!(&db, 1, 2, 1, Watched);
|
||||||
|
assert_season!(&db, 1, 2, 2, Unwatched);
|
||||||
|
assert_season!(&db, 1, 2, 3, Unwatched);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_query_shows() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_show {
|
||||||
|
($db:expr, $show:literal, $uid:literal, Watched) => {
|
||||||
|
assert_show!(@find, $db, $show, $uid)
|
||||||
|
.ok_or(())
|
||||||
|
.expect("is none");
|
||||||
|
};
|
||||||
|
($db:expr, $show:literal, $uid:literal, Unwatched) => {
|
||||||
|
assert_show!(@find, $db, $show, $uid)
|
||||||
|
.ok_or(())
|
||||||
|
.expect_err("is some");
|
||||||
|
};
|
||||||
|
(@find, $db:expr, $show:literal, $uid:literal) => {
|
||||||
|
super::shows::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(super::shows::Column::Id.eq($show))
|
||||||
|
.add(super::shows::Column::UserId.eq($uid)),
|
||||||
|
)
|
||||||
|
.one(&db)
|
||||||
|
.await
|
||||||
|
.expect("find.filter.one")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
make_content_show!(&db, 1, 1, None);
|
||||||
|
|
||||||
|
assert_show!(&db, 1, 1, Unwatched);
|
||||||
|
make_content_season!(&db, 1, 1, 1);
|
||||||
|
assert_show!(&db, 1, 1, Unwatched);
|
||||||
|
make_content_episode!(&db, 1, 1, 1, 1);
|
||||||
|
assert_show!(&db, 1, 1, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 1, 1, 1);
|
||||||
|
assert_show!(&db, 1, 1, Watched);
|
||||||
|
assert_show!(&db, 1, 2, Unwatched);
|
||||||
|
make_content_episode!(&db, 1, 1, 1, 2);
|
||||||
|
assert_show!(&db, 1, 1, Unwatched);
|
||||||
|
assert_show!(&db, 1, 2, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 1, 2, 1);
|
||||||
|
|
||||||
|
make_content_season!(&db, 1, 1, 2);
|
||||||
|
assert_show!(&db, 1, 1, Unwatched);
|
||||||
|
assert_show!(&db, 1, 2, Unwatched);
|
||||||
|
make_content_episode!(&db, 1, 1, 2, 1);
|
||||||
|
assert_show!(&db, 1, 1, Unwatched);
|
||||||
|
assert_show!(&db, 1, 2, Unwatched);
|
||||||
|
make_watched_episode!(&db, 1, 2, 1, 1);
|
||||||
|
assert_show!(&db, 1, 1, Watched);
|
||||||
|
assert_show!(&db, 1, 2, Unwatched);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_query_collections() {
|
||||||
|
let db = new_initialized_memory_db().await;
|
||||||
|
|
||||||
|
macro_rules! assert_collection {
|
||||||
|
($db:expr, $id:literal, $uid:literal, Watched) => {
|
||||||
|
assert_collection!(@find, $db, $id, $uid)
|
||||||
|
.ok_or(())
|
||||||
|
.expect("is none");
|
||||||
|
};
|
||||||
|
($db:expr, $id:literal, $uid:literal, Unwatched) => {
|
||||||
|
assert_collection!(@find, $db, $id, $uid)
|
||||||
|
.ok_or(())
|
||||||
|
.expect_err("is some");
|
||||||
|
};
|
||||||
|
(@find, $db:expr, $id:literal, $uid:literal) => {
|
||||||
|
super::collections::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(super::collections::Column::Id.eq($id))
|
||||||
|
.add(super::collections::Column::UserId.eq($uid)),
|
||||||
|
)
|
||||||
|
.one(&db)
|
||||||
|
.await
|
||||||
|
.expect("find.filter.one")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
make_content_library!(&db, 1);
|
||||||
|
make_content_collection!(&db, 1, 1, None);
|
||||||
|
assert_collection!(&db, 1, 1, Unwatched);
|
||||||
|
|
||||||
|
make_content_movie!(&db, 1, 1, Some(1));
|
||||||
|
assert_collection!(&db, 1, 1, Unwatched);
|
||||||
|
make_info_movie!(&db, 9999);
|
||||||
|
make_watched_movie!(&db, 9999, 1);
|
||||||
|
assert_collection!(&db, 1, 1, Unwatched);
|
||||||
|
make_watched_movie!(&db, 1, 1);
|
||||||
|
assert_collection!(&db, 1, 1, Watched);
|
||||||
|
|
||||||
|
make_content_collection!(&db, 1, 2, Some(1));
|
||||||
|
assert_collection!(&db, 1, 1, Watched);
|
||||||
|
assert_collection!(&db, 2, 1, Unwatched);
|
||||||
|
make_content_movie!(&db, 1, 2, Some(2));
|
||||||
|
assert_collection!(&db, 1, 1, Unwatched);
|
||||||
|
assert_collection!(&db, 2, 1, Unwatched);
|
||||||
|
make_watched_movie!(&db, 2, 1);
|
||||||
|
assert_collection!(&db, 1, 1, Watched);
|
||||||
|
assert_collection!(&db, 2, 1, Watched);
|
||||||
|
|
||||||
|
make_content_show!(&db, 1, 1, Some(2));
|
||||||
|
assert_collection!(&db, 1, 1, Unwatched);
|
||||||
|
assert_collection!(&db, 2, 1, Unwatched);
|
||||||
|
make_content_season!(&db, 1, 1, 1);
|
||||||
|
make_content_episode!(&db, 1, 1, 1, 1);
|
||||||
|
make_watched_episode!(&db, 1, 1, 1, 1);
|
||||||
|
assert_collection!(&db, 1, 1, Watched);
|
||||||
|
assert_collection!(&db, 2, 1, Watched);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
//! Collection entity
|
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, RawId};
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a watched movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_watched_collections")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The collection's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: CollectionId,
|
|
||||||
/// The user's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub user_id: RawId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
//! Episode entity
|
|
||||||
|
|
||||||
use flix_model::id::{RawId, ShowId};
|
|
||||||
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a watched movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_watched_episodes")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The episode's show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub show: ShowId,
|
|
||||||
/// The episode's season's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub season: SeasonNumber,
|
|
||||||
/// The episode's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub episode: EpisodeNumber,
|
|
||||||
/// The user's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub user_id: RawId,
|
|
||||||
/// The date this episode was watched
|
|
||||||
pub watched_date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,289 +0,0 @@
|
|||||||
//! This module contains entities for storing watched information
|
|
||||||
|
|
||||||
pub mod collections;
|
|
||||||
|
|
||||||
pub mod movies;
|
|
||||||
|
|
||||||
pub mod episodes;
|
|
||||||
pub mod seasons;
|
|
||||||
pub mod shows;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
use flix_model::id::{MovieId, ShowId};
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
|
||||||
use sea_orm::sqlx::error::ErrorKind;
|
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, Condition, EntityTrait, QueryFilter};
|
|
||||||
use sea_orm_migration::MigratorTrait;
|
|
||||||
|
|
||||||
use crate::entity::tests::{have_collection, have_library, have_movie, have_season, have_show};
|
|
||||||
use crate::migration::Migrator;
|
|
||||||
use crate::tests::new_memory_db;
|
|
||||||
|
|
||||||
use super::super::tests::get_error_kind;
|
|
||||||
use super::super::tests::notsettable;
|
|
||||||
use super::super::tests::{
|
|
||||||
have_episode, make_flix_episode, make_flix_movie, make_flix_season, make_flix_show,
|
|
||||||
};
|
|
||||||
|
|
||||||
macro_rules! assert_movie {
|
|
||||||
($db:expr, $id:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.id, MovieId::from_raw($id));
|
|
||||||
assert_eq!(model.user_id, $uid);
|
|
||||||
assert_eq!(model.watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $id:literal, $uid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::movies::ActiveModel {
|
|
||||||
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
|
|
||||||
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
|
|
||||||
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_episode {
|
|
||||||
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
|
|
||||||
.expect("insert");
|
|
||||||
|
|
||||||
assert_eq!(model.show, ShowId::from_raw($show));
|
|
||||||
assert_eq!(model.season, $season);
|
|
||||||
assert_eq!(model.episode, $episode);
|
|
||||||
assert_eq!(model.user_id, $uid);
|
|
||||||
assert_eq!(model.watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt"));
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
|
|
||||||
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
|
|
||||||
.expect_err("insert");
|
|
||||||
|
|
||||||
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
|
|
||||||
};
|
|
||||||
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal $(; $($skip:ident),+)?) => {
|
|
||||||
super::episodes::ActiveModel {
|
|
||||||
show: notsettable!(show, ShowId::from_raw($show) $(, $($skip),+)?),
|
|
||||||
season: notsettable!(season, $season $(, $($skip),+)?),
|
|
||||||
episode: notsettable!(episode, $episode $(, $($skip),+)?),
|
|
||||||
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
|
|
||||||
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
|
|
||||||
}.insert($db).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_inserts() {
|
|
||||||
let db = new_memory_db().await;
|
|
||||||
Migrator::up(&db, None).await.expect("up");
|
|
||||||
|
|
||||||
// Movies
|
|
||||||
assert_movie!(&db, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_movie!(&db, 1);
|
|
||||||
make_flix_movie!(&db, 2);
|
|
||||||
|
|
||||||
assert_movie!(&db, 1, 1, Success);
|
|
||||||
assert_movie!(&db, 1, 1, UniqueViolation);
|
|
||||||
assert_movie!(&db, 2, 1, Success);
|
|
||||||
assert_movie!(&db, 3, 1, NotNullViolation; id);
|
|
||||||
assert_movie!(&db, 4, 1, NotNullViolation; user_id);
|
|
||||||
assert_movie!(&db, 5, 1, NotNullViolation; watched_date);
|
|
||||||
|
|
||||||
// Episodes
|
|
||||||
make_flix_show!(&db, 1);
|
|
||||||
make_flix_season!(&db, 1, 1);
|
|
||||||
make_flix_show!(&db, 2);
|
|
||||||
make_flix_season!(&db, 2, 1);
|
|
||||||
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
|
|
||||||
make_flix_episode!(&db, 1, 1, 1);
|
|
||||||
make_flix_episode!(&db, 1, 1, 2);
|
|
||||||
make_flix_episode!(&db, 2, 1, 1);
|
|
||||||
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
|
|
||||||
assert_episode!(&db, 1, 1, 2, 1, Success);
|
|
||||||
assert_episode!(&db, 2, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 3, 1, 1, 1, NotNullViolation; show);
|
|
||||||
assert_episode!(&db, 4, 1, 1, 1, NotNullViolation; season);
|
|
||||||
assert_episode!(&db, 5, 1, 1, 1, NotNullViolation; episode);
|
|
||||||
assert_episode!(&db, 6, 1, 1, 1, NotNullViolation; user_id);
|
|
||||||
assert_episode!(&db, 7, 1, 1, 1, NotNullViolation; watched_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_queries() {
|
|
||||||
let db = new_memory_db().await;
|
|
||||||
Migrator::up(&db, None).await.expect("up");
|
|
||||||
|
|
||||||
have_library!(&db, 1);
|
|
||||||
|
|
||||||
// Season + Show
|
|
||||||
macro_rules! assert_season {
|
|
||||||
($db:expr, $show:literal, $season:literal, $uid:literal, Watched) => {
|
|
||||||
assert_season!(@find, $db, $show, $season, $uid)
|
|
||||||
.ok_or(())
|
|
||||||
.expect("is none");
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $season:literal, $uid:literal, Unwatched) => {
|
|
||||||
assert_season!(@find, $db, $show, $season, $uid)
|
|
||||||
.ok_or(())
|
|
||||||
.expect_err("is some");
|
|
||||||
};
|
|
||||||
(@find, $db:expr, $show:literal, $season:literal, $uid:literal) => {
|
|
||||||
super::seasons::Entity::find()
|
|
||||||
.filter(
|
|
||||||
Condition::all()
|
|
||||||
.add(super::seasons::Column::Show.eq($show))
|
|
||||||
.add(super::seasons::Column::Season.eq($season))
|
|
||||||
.add(super::seasons::Column::UserId.eq($uid)),
|
|
||||||
)
|
|
||||||
.one(&db)
|
|
||||||
.await
|
|
||||||
.expect("find.filter.one")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
macro_rules! assert_show {
|
|
||||||
($db:expr, $show:literal, $uid:literal, Watched) => {
|
|
||||||
assert_show!(@find, $db, $show, $uid)
|
|
||||||
.ok_or(())
|
|
||||||
.expect("is none");
|
|
||||||
};
|
|
||||||
($db:expr, $show:literal, $uid:literal, Unwatched) => {
|
|
||||||
assert_show!(@find, $db, $show, $uid)
|
|
||||||
.ok_or(())
|
|
||||||
.expect_err("is some");
|
|
||||||
};
|
|
||||||
(@find, $db:expr, $show:literal, $uid:literal) => {
|
|
||||||
super::shows::Entity::find()
|
|
||||||
.filter(
|
|
||||||
Condition::all()
|
|
||||||
.add(super::shows::Column::Id.eq($show))
|
|
||||||
.add(super::shows::Column::UserId.eq($uid)),
|
|
||||||
)
|
|
||||||
.one(&db)
|
|
||||||
.await
|
|
||||||
.expect("find.filter.one")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
have_show!(&db, 1, 1, None);
|
|
||||||
have_season!(&db, 1, 1, 1);
|
|
||||||
have_episode!(&db, 1, 1, 1, 1);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 1, 2, Success);
|
|
||||||
have_episode!(&db, 1, 1, 1, 2, >1); // Covers 2 and 3
|
|
||||||
make_flix_episode!(&db, 1, 1, 3);
|
|
||||||
assert_episode!(&db, 1, 1, 2, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 1, 2, 2, Success);
|
|
||||||
have_season!(&db, 1, 1, 2);
|
|
||||||
have_episode!(&db, 1, 1, 2, 1);
|
|
||||||
assert_episode!(&db, 1, 2, 1, 1, Success);
|
|
||||||
assert_episode!(&db, 1, 2, 1, 2, Success);
|
|
||||||
have_episode!(&db, 1, 1, 2, 2);
|
|
||||||
assert_episode!(&db, 1, 2, 2, 1, Success);
|
|
||||||
have_episode!(&db, 1, 1, 2, 3);
|
|
||||||
assert_episode!(&db, 1, 2, 3, 1, Success);
|
|
||||||
|
|
||||||
// Add watched episodes that we do not have
|
|
||||||
make_flix_episode!(&db, 1, 1, 4);
|
|
||||||
assert_episode!(&db, 1, 1, 4, 1, Success);
|
|
||||||
make_flix_episode!(&db, 1, 2, 4);
|
|
||||||
assert_episode!(&db, 1, 2, 4, 2, Success);
|
|
||||||
make_flix_episode!(&db, 1, 2, 5);
|
|
||||||
assert_episode!(&db, 1, 2, 5, 2, Success);
|
|
||||||
|
|
||||||
assert_season!(&db, 1, 1, 1, Watched);
|
|
||||||
assert_season!(&db, 1, 1, 2, Watched);
|
|
||||||
assert_season!(&db, 1, 1, 3, Unwatched);
|
|
||||||
assert_season!(&db, 1, 2, 1, Watched);
|
|
||||||
assert_season!(&db, 1, 2, 2, Unwatched);
|
|
||||||
assert_season!(&db, 1, 2, 3, Unwatched);
|
|
||||||
assert_season!(&db, 1, 3, 1, Unwatched);
|
|
||||||
assert_season!(&db, 1, 3, 2, Unwatched);
|
|
||||||
assert_season!(&db, 1, 3, 3, Unwatched);
|
|
||||||
|
|
||||||
assert_show!(&db, 1, 1, Watched);
|
|
||||||
assert_show!(&db, 1, 2, Unwatched);
|
|
||||||
assert_show!(&db, 1, 3, Unwatched);
|
|
||||||
assert_show!(&db, 2, 1, Unwatched);
|
|
||||||
assert_show!(&db, 2, 2, Unwatched);
|
|
||||||
assert_show!(&db, 2, 3, Unwatched);
|
|
||||||
|
|
||||||
// Collection
|
|
||||||
macro_rules! assert_collection {
|
|
||||||
($db:expr, $id:literal, $uid:literal, Watched) => {
|
|
||||||
assert_collection!(@find, $db, $id, $uid)
|
|
||||||
.ok_or(())
|
|
||||||
.expect("is none");
|
|
||||||
};
|
|
||||||
($db:expr, $id:literal, $uid:literal, Unwatched) => {
|
|
||||||
assert_collection!(@find, $db, $id, $uid)
|
|
||||||
.ok_or(())
|
|
||||||
.expect_err("is some");
|
|
||||||
};
|
|
||||||
(@find, $db:expr, $id:literal, $uid:literal) => {
|
|
||||||
super::collections::Entity::find()
|
|
||||||
.filter(
|
|
||||||
Condition::all()
|
|
||||||
.add(super::collections::Column::Id.eq($id))
|
|
||||||
.add(super::collections::Column::UserId.eq($uid)),
|
|
||||||
)
|
|
||||||
.one(&db)
|
|
||||||
.await
|
|
||||||
.expect("find.filter.one")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
have_collection!(&db, 1, 1, None);
|
|
||||||
have_movie!(&db, 1, 1, Some(1));
|
|
||||||
assert_movie!(&db, 1, 1, Success);
|
|
||||||
assert_movie!(&db, 1, 2, Success);
|
|
||||||
have_movie!(&db, 1, 2, Some(1));
|
|
||||||
assert_movie!(&db, 2, 1, Success);
|
|
||||||
assert_movie!(&db, 2, 2, Success);
|
|
||||||
|
|
||||||
have_collection!(&db, 1, 2, Some(1));
|
|
||||||
have_movie!(&db, 1, 3, Some(2));
|
|
||||||
have_show!(&db, 1, 2, Some(2));
|
|
||||||
have_season!(&db, 1, 2, 1);
|
|
||||||
have_episode!(&db, 1, 2, 1, 1);
|
|
||||||
assert_episode!(&db, 2, 1, 1, 1, Success);
|
|
||||||
assert_movie!(&db, 3, 1, Success);
|
|
||||||
have_movie!(&db, 1, 4, Some(2));
|
|
||||||
assert_movie!(&db, 4, 1, Success);
|
|
||||||
|
|
||||||
have_collection!(&db, 1, 3, Some(2));
|
|
||||||
have_movie!(&db, 1, 5, Some(3));
|
|
||||||
assert_movie!(&db, 5, 1, Success);
|
|
||||||
have_movie!(&db, 1, 6, Some(3));
|
|
||||||
assert_movie!(&db, 6, 1, Success);
|
|
||||||
assert_movie!(&db, 6, 2, Success);
|
|
||||||
|
|
||||||
have_collection!(&db, 1, 4, Some(3));
|
|
||||||
have_movie!(&db, 1, 7, Some(4));
|
|
||||||
assert_movie!(&db, 7, 1, Success);
|
|
||||||
assert_movie!(&db, 7, 2, Success);
|
|
||||||
have_movie!(&db, 1, 8, Some(4));
|
|
||||||
assert_movie!(&db, 8, 1, Success);
|
|
||||||
assert_movie!(&db, 8, 2, Success);
|
|
||||||
|
|
||||||
assert_collection!(&db, 1, 1, Watched);
|
|
||||||
assert_collection!(&db, 1, 2, Unwatched);
|
|
||||||
assert_collection!(&db, 2, 1, Watched);
|
|
||||||
assert_collection!(&db, 2, 2, Unwatched);
|
|
||||||
assert_collection!(&db, 3, 1, Watched);
|
|
||||||
assert_collection!(&db, 3, 2, Unwatched);
|
|
||||||
assert_collection!(&db, 4, 1, Watched);
|
|
||||||
assert_collection!(&db, 4, 2, Watched);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
//! Movie entity
|
|
||||||
|
|
||||||
use flix_model::id::{MovieId, RawId};
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a watched movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_watched_movies")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The movie's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: MovieId,
|
|
||||||
/// The user's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub user_id: RawId,
|
|
||||||
/// The date this movie was watched
|
|
||||||
pub watched_date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
//! Episode entity
|
|
||||||
|
|
||||||
use flix_model::id::{RawId, ShowId};
|
|
||||||
use flix_model::numbers::SeasonNumber;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a watched movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_watched_seasons")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The season's show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub show: ShowId,
|
|
||||||
/// The season's number
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub season: SeasonNumber,
|
|
||||||
/// The user's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub user_id: RawId,
|
|
||||||
/// The date this season was watched
|
|
||||||
pub watched_date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
//! Show entity
|
|
||||||
|
|
||||||
use flix_model::id::{RawId, ShowId};
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
|
|
||||||
EnumIter, PrimaryKeyTrait,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The database representation of a watched movie
|
|
||||||
#[derive(Debug, Clone, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "flix_watched_shows")]
|
|
||||||
pub struct Model {
|
|
||||||
/// The show's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: ShowId,
|
|
||||||
/// The user's ID
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub user_id: RawId,
|
|
||||||
/// The date this show was watched
|
|
||||||
pub watched_date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
/// Relation
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
+12
-3
@@ -10,8 +10,17 @@ pub mod migration;
|
|||||||
mod tests {
|
mod tests {
|
||||||
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
|
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
|
||||||
|
|
||||||
pub async fn new_memory_db() -> DatabaseConnection {
|
use crate::connection::Connection;
|
||||||
let options = ConnectOptions::new("sqlite:/tmp/db?mode=memory");
|
|
||||||
Database::connect(options).await.expect("Database::connect")
|
pub async fn new_initialized_memory_db() -> DatabaseConnection {
|
||||||
|
let options = ConnectOptions::new("sqlite::memory:");
|
||||||
|
|
||||||
|
let db = Database::connect(options)
|
||||||
|
.await
|
||||||
|
.expect("Database::connect()");
|
||||||
|
let connection = Connection::try_from(db)
|
||||||
|
.await
|
||||||
|
.expect("Connection::try_from");
|
||||||
|
connection.take()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,33 @@
|
|||||||
//! Adds entity/info tables:
|
//! Adds watched views:
|
||||||
//! - Collections
|
//! - Collections
|
||||||
//! - Movies
|
|
||||||
//! - Shows
|
//! - Shows
|
||||||
//! - Seasons
|
//! - Seasons
|
||||||
//! - Episodes
|
|
||||||
|
|
||||||
use sea_orm::{DbErr, DeriveMigrationName};
|
use sea_orm::{DbErr, DeriveMigrationName};
|
||||||
use sea_orm_migration::async_trait;
|
use sea_orm_migration::async_trait;
|
||||||
use sea_orm_migration::{MigrationTrait, SchemaManager};
|
use sea_orm_migration::{MigrationTrait, SchemaManager};
|
||||||
|
|
||||||
mod collections;
|
mod collections;
|
||||||
mod episodes;
|
|
||||||
mod movies;
|
|
||||||
mod seasons;
|
mod seasons;
|
||||||
mod shows;
|
mod shows;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use collections::FlixInfoCollections;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use episodes::FlixInfoEpisodes;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use movies::FlixInfoMovies;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use seasons::FlixInfoSeasons;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use shows::FlixInfoShows;
|
|
||||||
|
|
||||||
#[derive(DeriveMigrationName)]
|
#[derive(DeriveMigrationName)]
|
||||||
pub(super) struct Migration;
|
pub(super) struct Migration;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
collections::up(manager).await?;
|
|
||||||
movies::up(manager).await?;
|
|
||||||
shows::up(manager).await?;
|
|
||||||
seasons::up(manager).await?;
|
seasons::up(manager).await?;
|
||||||
episodes::up(manager).await?;
|
shows::up(manager).await?;
|
||||||
|
collections::up(manager).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
episodes::down(manager).await?;
|
|
||||||
seasons::down(manager).await?;
|
|
||||||
shows::down(manager).await?;
|
|
||||||
movies::down(manager).await?;
|
|
||||||
collections::down(manager).await?;
|
collections::down(manager).await?;
|
||||||
|
shows::down(manager).await?;
|
||||||
|
seasons::down(manager).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,88 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
use sea_orm::prelude::*;
|
||||||
|
use sea_orm::sea_query::Table;
|
||||||
use sea_orm::sea_query;
|
use sea_orm::{ConnectionTrait, DbBackend, Statement};
|
||||||
use sea_orm::sea_query::{Index, Table};
|
use sea_orm_migration::prelude::*;
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::string;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixInfoCollections {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Title,
|
|
||||||
Overview,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.create_table(
|
.drop_table(Table::drop().table("flix_watched_collections").to_owned())
|
||||||
Table::create()
|
|
||||||
.table(FlixInfoCollections::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixInfoCollections::Id))
|
|
||||||
.col(string(FlixInfoCollections::Title))
|
|
||||||
.col(string(FlixInfoCollections::Overview))
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
manager
|
manager
|
||||||
.create_index(
|
.get_connection()
|
||||||
Index::create()
|
.execute_raw(Statement::from_string(
|
||||||
.name("idx-flix_info_collections-title")
|
DbBackend::Sqlite,
|
||||||
.table(FlixInfoCollections::Table)
|
r#"
|
||||||
.col(FlixInfoCollections::Title)
|
CREATE VIEW flix_watched_collections AS
|
||||||
.to_owned(),
|
WITH RECURSIVE
|
||||||
)
|
watched_items AS (
|
||||||
|
SELECT
|
||||||
|
w.id,
|
||||||
|
w.user_id,
|
||||||
|
w.watched_date,
|
||||||
|
'movie' AS type
|
||||||
|
FROM flix_watched_movies w
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
w.id,
|
||||||
|
w.user_id,
|
||||||
|
w.watched_date,
|
||||||
|
'show' AS type
|
||||||
|
FROM flix_watched_shows w
|
||||||
|
),
|
||||||
|
collection_items AS (
|
||||||
|
SELECT
|
||||||
|
m.parent_id,
|
||||||
|
m.id,
|
||||||
|
'movie' AS type
|
||||||
|
FROM flix_movies m
|
||||||
|
WHERE m.parent_id IS NOT NULL
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
s.parent_id,
|
||||||
|
s.id,
|
||||||
|
'show' AS type
|
||||||
|
FROM flix_shows s
|
||||||
|
WHERE s.parent_id IS NOT NULL
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
c.parent_id,
|
||||||
|
ci.id,
|
||||||
|
ci.type
|
||||||
|
FROM collection_items ci
|
||||||
|
JOIN flix_collections c
|
||||||
|
ON c.id = ci.parent_id
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
ci.parent_id AS id,
|
||||||
|
wi.user_id,
|
||||||
|
MAX(wi.watched_date) AS watched_date
|
||||||
|
FROM collection_items ci
|
||||||
|
JOIN watched_items wi
|
||||||
|
ON wi.id = ci.id
|
||||||
|
AND wi.type = ci.type
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM collection_items ci2
|
||||||
|
WHERE ci2.parent_id = ci.parent_id
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM watched_items wi2
|
||||||
|
WHERE wi2.id = ci2.id
|
||||||
|
AND wi2.type = ci2.type
|
||||||
|
AND wi2.user_id = wi.user_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
GROUP BY ci.parent_id, wi.user_id
|
||||||
|
;
|
||||||
|
"#,
|
||||||
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -41,6 +90,15 @@ pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.drop_table(Table::drop().table(FlixInfoCollections::Table).to_owned())
|
.get_connection()
|
||||||
.await
|
.execute_raw(Statement::from_string(
|
||||||
|
DbBackend::Sqlite,
|
||||||
|
r#"
|
||||||
|
DROP VIEW flix_watched_collections
|
||||||
|
;
|
||||||
|
"#,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer, string};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoShows;
|
|
||||||
|
|
||||||
use super::FlixInfoSeasons;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixInfoEpisodes {
|
|
||||||
Table,
|
|
||||||
Show,
|
|
||||||
Season,
|
|
||||||
Episode,
|
|
||||||
Title,
|
|
||||||
Overview,
|
|
||||||
Date,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixInfoEpisodes::Table)
|
|
||||||
.col(integer(FlixInfoEpisodes::Show))
|
|
||||||
.col(integer(FlixInfoEpisodes::Season))
|
|
||||||
.col(integer(FlixInfoEpisodes::Episode))
|
|
||||||
.col(string(FlixInfoEpisodes::Title))
|
|
||||||
.col(string(FlixInfoEpisodes::Overview))
|
|
||||||
.col(date(FlixInfoEpisodes::Date))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixInfoEpisodes::Show)
|
|
||||||
.col(FlixInfoEpisodes::Season)
|
|
||||||
.col(FlixInfoEpisodes::Episode),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_info_episodes-show")
|
|
||||||
.from_tbl(FlixInfoEpisodes::Table)
|
|
||||||
.from_col(FlixInfoEpisodes::Show)
|
|
||||||
.to_tbl(FlixInfoShows::Table)
|
|
||||||
.to_col(FlixInfoShows::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_info_episodes-show_season")
|
|
||||||
.from_tbl(FlixInfoEpisodes::Table)
|
|
||||||
.from_col(FlixInfoEpisodes::Show)
|
|
||||||
.from_col(FlixInfoEpisodes::Season)
|
|
||||||
.to_tbl(FlixInfoSeasons::Table)
|
|
||||||
.to_col(FlixInfoSeasons::Show)
|
|
||||||
.to_col(FlixInfoSeasons::Season),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixInfoEpisodes::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, string};
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixInfoMovies {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Title,
|
|
||||||
Tagline,
|
|
||||||
Overview,
|
|
||||||
Date,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixInfoMovies::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixInfoMovies::Id))
|
|
||||||
.col(string(FlixInfoMovies::Title))
|
|
||||||
.col(string(FlixInfoMovies::Tagline))
|
|
||||||
.col(string(FlixInfoMovies::Overview))
|
|
||||||
.col(date(FlixInfoMovies::Date))
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
manager
|
|
||||||
.create_index(
|
|
||||||
Index::create()
|
|
||||||
.name("idx-flix_info_movies-title")
|
|
||||||
.table(FlixInfoMovies::Table)
|
|
||||||
.col(FlixInfoMovies::Title)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
manager
|
|
||||||
.create_index(
|
|
||||||
Index::create()
|
|
||||||
.name("idx-flix_info_movies-date")
|
|
||||||
.table(FlixInfoMovies::Table)
|
|
||||||
.col(FlixInfoMovies::Date)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixInfoMovies::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,46 +1,43 @@
|
|||||||
use sea_orm::sea_query;
|
use sea_orm::prelude::*;
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
use sea_orm::sea_query::Table;
|
||||||
use sea_orm::{DbErr, Iden};
|
use sea_orm::{ConnectionTrait, DbBackend, Statement};
|
||||||
use sea_orm_migration::SchemaManager;
|
use sea_orm_migration::prelude::*;
|
||||||
use sea_orm_migration::schema::{date, integer, string};
|
|
||||||
|
|
||||||
use super::FlixInfoShows;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixInfoSeasons {
|
|
||||||
Table,
|
|
||||||
Show,
|
|
||||||
Season,
|
|
||||||
Title,
|
|
||||||
Overview,
|
|
||||||
Date,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.create_table(
|
.drop_table(Table::drop().table("flix_watched_seasons").to_owned())
|
||||||
Table::create()
|
.await?;
|
||||||
.table(FlixInfoSeasons::Table)
|
|
||||||
.col(integer(FlixInfoSeasons::Show))
|
manager
|
||||||
.col(integer(FlixInfoSeasons::Season))
|
.get_connection()
|
||||||
.col(string(FlixInfoSeasons::Title))
|
.execute_raw(Statement::from_string(
|
||||||
.col(string(FlixInfoSeasons::Overview))
|
DbBackend::Sqlite,
|
||||||
.col(date(FlixInfoSeasons::Date))
|
r#"
|
||||||
.primary_key(
|
CREATE VIEW flix_watched_seasons AS
|
||||||
Index::create()
|
SELECT
|
||||||
.col(FlixInfoSeasons::Show)
|
w.show_id,
|
||||||
.col(FlixInfoSeasons::Season),
|
w.season_number,
|
||||||
|
w.user_id,
|
||||||
|
MAX(w.watched_date) AS watched_date
|
||||||
|
FROM flix_watched_episodes w
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM flix_episodes e
|
||||||
|
WHERE e.show_id = w.show_id
|
||||||
|
AND e.season_number = w.season_number
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM flix_watched_episodes wc
|
||||||
|
WHERE wc.show_id = e.show_id
|
||||||
|
AND wc.season_number = e.season_number
|
||||||
|
AND wc.episode_number = e.episode_number
|
||||||
|
AND wc.user_id = w.user_id
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.foreign_key(
|
GROUP BY w.show_id, w.season_number, w.user_id
|
||||||
ForeignKeyCreateStatement::new()
|
;
|
||||||
.name("fk-flix_info_seasons-show")
|
"#,
|
||||||
.from_tbl(FlixInfoSeasons::Table)
|
))
|
||||||
.from_col(FlixInfoSeasons::Show)
|
|
||||||
.to_tbl(FlixInfoShows::Table)
|
|
||||||
.to_col(FlixInfoShows::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -48,6 +45,15 @@ pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.drop_table(Table::drop().table(FlixInfoSeasons::Table).to_owned())
|
.get_connection()
|
||||||
.await
|
.execute_raw(Statement::from_string(
|
||||||
|
DbBackend::Sqlite,
|
||||||
|
r#"
|
||||||
|
DROP VIEW flix_watched_seasons
|
||||||
|
;
|
||||||
|
"#,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,40 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
use sea_orm::prelude::*;
|
||||||
|
use sea_orm::sea_query::Table;
|
||||||
use sea_orm::sea_query;
|
use sea_orm::{ConnectionTrait, DbBackend, Statement};
|
||||||
use sea_orm::sea_query::{Index, Table};
|
use sea_orm_migration::prelude::*;
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, string};
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixInfoShows {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Title,
|
|
||||||
Tagline,
|
|
||||||
Overview,
|
|
||||||
Date,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.create_table(
|
.drop_table(Table::drop().table("flix_watched_shows").to_owned())
|
||||||
Table::create()
|
|
||||||
.table(FlixInfoShows::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixInfoShows::Id))
|
|
||||||
.col(string(FlixInfoShows::Title))
|
|
||||||
.col(string(FlixInfoShows::Tagline))
|
|
||||||
.col(string(FlixInfoShows::Overview))
|
|
||||||
.col(date(FlixInfoShows::Date))
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
manager
|
manager
|
||||||
.create_index(
|
.get_connection()
|
||||||
Index::create()
|
.execute_raw(Statement::from_string(
|
||||||
.name("idx-flix_info_shows-title")
|
DbBackend::Sqlite,
|
||||||
.table(FlixInfoShows::Table)
|
r#"
|
||||||
.col(FlixInfoShows::Title)
|
CREATE VIEW flix_watched_shows AS
|
||||||
.to_owned(),
|
SELECT
|
||||||
)
|
w.show_id as id,
|
||||||
.await?;
|
w.user_id,
|
||||||
|
MAX(w.watched_date) AS watched_date
|
||||||
manager
|
FROM flix_watched_seasons w
|
||||||
.create_index(
|
WHERE NOT EXISTS (
|
||||||
Index::create()
|
SELECT 1
|
||||||
.name("idx-flix_info_shows-date")
|
FROM flix_seasons s
|
||||||
.table(FlixInfoShows::Table)
|
WHERE s.show_id = w.show_id
|
||||||
.col(FlixInfoShows::Date)
|
AND NOT EXISTS (
|
||||||
.to_owned(),
|
SELECT 1
|
||||||
)
|
FROM flix_watched_seasons wc
|
||||||
|
WHERE wc.show_id = s.show_id
|
||||||
|
AND wc.season_number = s.season_number
|
||||||
|
AND wc.user_id = w.user_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
GROUP BY w.show_id, w.user_id
|
||||||
|
;
|
||||||
|
"#,
|
||||||
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -55,6 +42,15 @@ pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.drop_table(Table::drop().table(FlixInfoShows::Table).to_owned())
|
.get_connection()
|
||||||
.await
|
.execute_raw(Statement::from_string(
|
||||||
|
DbBackend::Sqlite,
|
||||||
|
r#"
|
||||||
|
DROP VIEW flix_watched_shows
|
||||||
|
;
|
||||||
|
"#,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
//! Adds entity/tmdb tables:
|
|
||||||
//! - Collections
|
|
||||||
//! - Movies
|
|
||||||
//! - Shows
|
|
||||||
//! - Seasons
|
|
||||||
//! - Episodes
|
|
||||||
|
|
||||||
use sea_orm::{DbErr, DeriveMigrationName};
|
|
||||||
use sea_orm_migration::async_trait;
|
|
||||||
use sea_orm_migration::{MigrationTrait, SchemaManager};
|
|
||||||
|
|
||||||
mod collections;
|
|
||||||
mod episodes;
|
|
||||||
mod movies;
|
|
||||||
mod seasons;
|
|
||||||
mod shows;
|
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use collections::FlixTmdbCollections;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use episodes::FlixTmdbEpisodes;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use movies::FlixTmdbMovies;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use seasons::FlixTmdbSeasons;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use shows::FlixTmdbShows;
|
|
||||||
|
|
||||||
#[derive(DeriveMigrationName)]
|
|
||||||
pub(super) struct Migration;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigrationTrait for Migration {
|
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
collections::up(manager).await?;
|
|
||||||
movies::up(manager).await?;
|
|
||||||
shows::up(manager).await?;
|
|
||||||
seasons::up(manager).await?;
|
|
||||||
episodes::up(manager).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
episodes::down(manager).await?;
|
|
||||||
seasons::down(manager).await?;
|
|
||||||
shows::down(manager).await?;
|
|
||||||
movies::down(manager).await?;
|
|
||||||
collections::down(manager).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer};
|
|
||||||
|
|
||||||
use super::super::m_000001::FlixInfoCollections;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixTmdbCollections {
|
|
||||||
Table,
|
|
||||||
TmdbId,
|
|
||||||
FlixId,
|
|
||||||
LastUpdate,
|
|
||||||
MovieCount,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixTmdbCollections::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixTmdbCollections::TmdbId))
|
|
||||||
.col(integer(FlixTmdbCollections::FlixId).unique_key())
|
|
||||||
.col(date(FlixTmdbCollections::LastUpdate))
|
|
||||||
.col(integer(FlixTmdbCollections::MovieCount))
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_collections-flixid")
|
|
||||||
.from_tbl(FlixTmdbCollections::Table)
|
|
||||||
.from_col(FlixTmdbCollections::FlixId)
|
|
||||||
.to_tbl(FlixInfoCollections::Table)
|
|
||||||
.to_col(FlixInfoCollections::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
manager
|
|
||||||
.create_index(
|
|
||||||
Index::create()
|
|
||||||
.name("idx-flix_tmdb_collections-flixid")
|
|
||||||
.table(FlixTmdbCollections::Table)
|
|
||||||
.col(FlixTmdbCollections::FlixId)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixTmdbCollections::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer};
|
|
||||||
|
|
||||||
use super::super::m_000001::{FlixInfoEpisodes, FlixInfoSeasons};
|
|
||||||
|
|
||||||
use super::FlixTmdbSeasons;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixTmdbEpisodes {
|
|
||||||
Table,
|
|
||||||
TmdbShow,
|
|
||||||
TmdbSeason,
|
|
||||||
TmdbEpisode,
|
|
||||||
FlixShow,
|
|
||||||
FlixSeason,
|
|
||||||
FlixEpisode,
|
|
||||||
LastUpdate,
|
|
||||||
Runtime,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixTmdbEpisodes::Table)
|
|
||||||
.col(integer(FlixTmdbEpisodes::TmdbShow))
|
|
||||||
.col(integer(FlixTmdbEpisodes::TmdbSeason))
|
|
||||||
.col(integer(FlixTmdbEpisodes::TmdbEpisode))
|
|
||||||
.col(integer(FlixTmdbEpisodes::FlixShow))
|
|
||||||
.col(integer(FlixTmdbEpisodes::FlixSeason))
|
|
||||||
.col(integer(FlixTmdbEpisodes::FlixEpisode))
|
|
||||||
.col(date(FlixTmdbEpisodes::LastUpdate))
|
|
||||||
.col(integer(FlixTmdbEpisodes::Runtime))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixTmdbEpisodes::TmdbShow)
|
|
||||||
.col(FlixTmdbEpisodes::TmdbSeason)
|
|
||||||
.col(FlixTmdbEpisodes::TmdbEpisode),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_episodes-tmdb_show_season")
|
|
||||||
.from_tbl(FlixTmdbEpisodes::Table)
|
|
||||||
.from_col(FlixTmdbEpisodes::TmdbShow)
|
|
||||||
.from_col(FlixTmdbEpisodes::TmdbSeason)
|
|
||||||
.to_tbl(FlixTmdbSeasons::Table)
|
|
||||||
.to_col(FlixTmdbSeasons::TmdbShow)
|
|
||||||
.to_col(FlixTmdbSeasons::TmdbSeason),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_episodes-flix_show_season")
|
|
||||||
.from_tbl(FlixTmdbEpisodes::Table)
|
|
||||||
.from_col(FlixTmdbEpisodes::FlixShow)
|
|
||||||
.from_col(FlixTmdbEpisodes::FlixSeason)
|
|
||||||
.to_tbl(FlixInfoSeasons::Table)
|
|
||||||
.to_col(FlixInfoSeasons::Show)
|
|
||||||
.to_col(FlixInfoSeasons::Season),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_episodes-flix_show_season_episode")
|
|
||||||
.from_tbl(FlixTmdbEpisodes::Table)
|
|
||||||
.from_col(FlixTmdbEpisodes::FlixShow)
|
|
||||||
.from_col(FlixTmdbEpisodes::FlixSeason)
|
|
||||||
.from_col(FlixTmdbEpisodes::FlixEpisode)
|
|
||||||
.to_tbl(FlixInfoEpisodes::Table)
|
|
||||||
.to_col(FlixInfoEpisodes::Show)
|
|
||||||
.to_col(FlixInfoEpisodes::Season)
|
|
||||||
.to_col(FlixInfoEpisodes::Episode),
|
|
||||||
)
|
|
||||||
.index(
|
|
||||||
Index::create()
|
|
||||||
.unique()
|
|
||||||
.name("idx-flix_tmdb_episodes-flix_show_season_episode")
|
|
||||||
.col(FlixTmdbEpisodes::FlixShow)
|
|
||||||
.col(FlixTmdbEpisodes::FlixSeason)
|
|
||||||
.col(FlixTmdbEpisodes::FlixEpisode),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixTmdbEpisodes::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer, integer_null};
|
|
||||||
|
|
||||||
use crate::migration::m_000002::FlixTmdbCollections;
|
|
||||||
|
|
||||||
use super::super::m_000001::FlixInfoMovies;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixTmdbMovies {
|
|
||||||
Table,
|
|
||||||
TmdbId,
|
|
||||||
FlixId,
|
|
||||||
LastUpdate,
|
|
||||||
Runtime,
|
|
||||||
Collection,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixTmdbMovies::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixTmdbMovies::TmdbId))
|
|
||||||
.col(integer(FlixTmdbMovies::FlixId).unique_key())
|
|
||||||
.col(date(FlixTmdbMovies::LastUpdate))
|
|
||||||
.col(integer(FlixTmdbMovies::Runtime))
|
|
||||||
.col(integer_null(FlixTmdbMovies::Collection))
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_movies-flixid")
|
|
||||||
.from_tbl(FlixTmdbMovies::Table)
|
|
||||||
.from_col(FlixTmdbMovies::FlixId)
|
|
||||||
.to_tbl(FlixInfoMovies::Table)
|
|
||||||
.to_col(FlixInfoMovies::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_movies-collectionid")
|
|
||||||
.from_tbl(FlixTmdbMovies::Table)
|
|
||||||
.from_col(FlixTmdbMovies::Collection)
|
|
||||||
.to_tbl(FlixTmdbCollections::Table)
|
|
||||||
.to_col(FlixTmdbCollections::TmdbId),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
manager
|
|
||||||
.create_index(
|
|
||||||
Index::create()
|
|
||||||
.name("idx-flix_tmdb_movies-flixid")
|
|
||||||
.table(FlixTmdbMovies::Table)
|
|
||||||
.col(FlixTmdbMovies::FlixId)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixTmdbMovies::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoShows;
|
|
||||||
|
|
||||||
use super::super::m_000001::FlixInfoSeasons;
|
|
||||||
|
|
||||||
use super::FlixTmdbShows;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixTmdbSeasons {
|
|
||||||
Table,
|
|
||||||
TmdbShow,
|
|
||||||
TmdbSeason,
|
|
||||||
FlixShow,
|
|
||||||
FlixSeason,
|
|
||||||
LastUpdate,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixTmdbSeasons::Table)
|
|
||||||
.col(integer(FlixTmdbSeasons::TmdbShow))
|
|
||||||
.col(integer(FlixTmdbSeasons::TmdbSeason))
|
|
||||||
.col(integer(FlixTmdbSeasons::FlixShow))
|
|
||||||
.col(integer(FlixTmdbSeasons::FlixSeason))
|
|
||||||
.col(date(FlixTmdbSeasons::LastUpdate))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixTmdbSeasons::TmdbShow)
|
|
||||||
.col(FlixTmdbSeasons::TmdbSeason),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_seasons-tmdb_show")
|
|
||||||
.from_tbl(FlixTmdbSeasons::Table)
|
|
||||||
.from_col(FlixTmdbSeasons::FlixShow)
|
|
||||||
.to_tbl(FlixTmdbShows::Table)
|
|
||||||
.to_col(FlixTmdbShows::FlixId),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_seasons-flix_show")
|
|
||||||
.from_tbl(FlixTmdbSeasons::Table)
|
|
||||||
.from_col(FlixTmdbSeasons::FlixShow)
|
|
||||||
.to_tbl(FlixInfoShows::Table)
|
|
||||||
.to_col(FlixInfoShows::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_seasons-flix_show_season")
|
|
||||||
.from_tbl(FlixTmdbSeasons::Table)
|
|
||||||
.from_col(FlixTmdbSeasons::FlixShow)
|
|
||||||
.from_col(FlixTmdbSeasons::FlixSeason)
|
|
||||||
.to_tbl(FlixInfoSeasons::Table)
|
|
||||||
.to_col(FlixInfoSeasons::Show)
|
|
||||||
.to_col(FlixInfoSeasons::Season),
|
|
||||||
)
|
|
||||||
.index(
|
|
||||||
Index::create()
|
|
||||||
.unique()
|
|
||||||
.name("idx-flix_tmdb_seasons-flix_show_season")
|
|
||||||
.col(FlixTmdbSeasons::FlixShow)
|
|
||||||
.col(FlixTmdbSeasons::FlixSeason),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixTmdbSeasons::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer};
|
|
||||||
|
|
||||||
use super::super::m_000001::FlixInfoShows;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixTmdbShows {
|
|
||||||
Table,
|
|
||||||
TmdbId,
|
|
||||||
FlixId,
|
|
||||||
LastUpdate,
|
|
||||||
NumberOfSeasons,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixTmdbShows::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixTmdbShows::TmdbId))
|
|
||||||
.col(integer(FlixTmdbShows::FlixId).unique_key())
|
|
||||||
.col(date(FlixTmdbShows::LastUpdate))
|
|
||||||
.col(integer(FlixTmdbShows::NumberOfSeasons))
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_tmdb_shows-flixid")
|
|
||||||
.from_tbl(FlixTmdbShows::Table)
|
|
||||||
.from_col(FlixTmdbShows::FlixId)
|
|
||||||
.to_tbl(FlixInfoShows::Table)
|
|
||||||
.to_col(FlixInfoShows::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
manager
|
|
||||||
.create_index(
|
|
||||||
Index::create()
|
|
||||||
.name("idx-flix_tmdb_shows-flixid")
|
|
||||||
.table(FlixTmdbShows::Table)
|
|
||||||
.col(FlixTmdbShows::FlixId)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixTmdbShows::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
//! Adds entity/content tables:
|
|
||||||
//! - Libraries
|
|
||||||
//! - Collections
|
|
||||||
//! - Movies
|
|
||||||
//! - Shows
|
|
||||||
//! - Seasons
|
|
||||||
//! - Episodes
|
|
||||||
|
|
||||||
use sea_orm::{DbErr, DeriveMigrationName};
|
|
||||||
use sea_orm_migration::async_trait;
|
|
||||||
use sea_orm_migration::{MigrationTrait, SchemaManager};
|
|
||||||
|
|
||||||
mod collections;
|
|
||||||
mod episodes;
|
|
||||||
mod libraries;
|
|
||||||
mod movies;
|
|
||||||
mod seasons;
|
|
||||||
mod shows;
|
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use collections::FlixCollections;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use episodes::FlixEpisodes;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use libraries::FlixLibraries;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use movies::FlixMovies;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use seasons::FlixSeasons;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use shows::FlixShows;
|
|
||||||
|
|
||||||
#[derive(DeriveMigrationName)]
|
|
||||||
pub(super) struct Migration;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigrationTrait for Migration {
|
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
libraries::up(manager).await?;
|
|
||||||
collections::up(manager).await?;
|
|
||||||
movies::up(manager).await?;
|
|
||||||
shows::up(manager).await?;
|
|
||||||
seasons::up(manager).await?;
|
|
||||||
episodes::up(manager).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
episodes::down(manager).await?;
|
|
||||||
seasons::down(manager).await?;
|
|
||||||
shows::down(manager).await?;
|
|
||||||
movies::down(manager).await?;
|
|
||||||
collections::down(manager).await?;
|
|
||||||
libraries::down(manager).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{binary, integer, integer_null, string, string_null};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoCollections;
|
|
||||||
use crate::migration::m_000003::FlixLibraries;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixCollections {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Parent,
|
|
||||||
Slug,
|
|
||||||
Library,
|
|
||||||
Directory,
|
|
||||||
RelativePosterPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixCollections::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixCollections::Id))
|
|
||||||
.col(integer_null(FlixCollections::Parent))
|
|
||||||
.col(string(FlixCollections::Slug))
|
|
||||||
.col(integer(FlixCollections::Library))
|
|
||||||
.col(binary(FlixCollections::Directory))
|
|
||||||
.col(string_null(FlixCollections::RelativePosterPath))
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_collections-id")
|
|
||||||
.from_tbl(FlixCollections::Table)
|
|
||||||
.from_col(FlixCollections::Id)
|
|
||||||
.to_tbl(FlixInfoCollections::Table)
|
|
||||||
.to_col(FlixInfoCollections::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_collections-parent")
|
|
||||||
.from_tbl(FlixCollections::Table)
|
|
||||||
.from_col(FlixCollections::Parent)
|
|
||||||
.to_tbl(FlixCollections::Table)
|
|
||||||
.to_col(FlixCollections::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_collections-library")
|
|
||||||
.from_tbl(FlixCollections::Table)
|
|
||||||
.from_col(FlixCollections::Library)
|
|
||||||
.to_tbl(FlixLibraries::Table)
|
|
||||||
.to_col(FlixLibraries::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixCollections::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{binary, integer, string, string_null};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoEpisodes;
|
|
||||||
use crate::migration::m_000003::FlixLibraries;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixEpisodes {
|
|
||||||
Table,
|
|
||||||
Show,
|
|
||||||
Season,
|
|
||||||
Episode,
|
|
||||||
Count,
|
|
||||||
Slug,
|
|
||||||
Library,
|
|
||||||
Directory,
|
|
||||||
RelativeMediaPath,
|
|
||||||
RelativePosterPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixEpisodes::Table)
|
|
||||||
.col(integer(FlixEpisodes::Show))
|
|
||||||
.col(integer(FlixEpisodes::Season))
|
|
||||||
.col(integer(FlixEpisodes::Episode))
|
|
||||||
.col(integer(FlixEpisodes::Count))
|
|
||||||
.col(string(FlixEpisodes::Slug))
|
|
||||||
.col(integer(FlixEpisodes::Library))
|
|
||||||
.col(binary(FlixEpisodes::Directory))
|
|
||||||
.col(string(FlixEpisodes::RelativeMediaPath))
|
|
||||||
.col(string_null(FlixEpisodes::RelativePosterPath))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixEpisodes::Show)
|
|
||||||
.col(FlixEpisodes::Season)
|
|
||||||
.col(FlixEpisodes::Episode),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_episodes-show_season_episode")
|
|
||||||
.from_tbl(FlixEpisodes::Table)
|
|
||||||
.from_col(FlixEpisodes::Show)
|
|
||||||
.from_col(FlixEpisodes::Season)
|
|
||||||
.from_col(FlixEpisodes::Episode)
|
|
||||||
.to_tbl(FlixInfoEpisodes::Table)
|
|
||||||
.to_col(FlixInfoEpisodes::Show)
|
|
||||||
.to_col(FlixInfoEpisodes::Season)
|
|
||||||
.to_col(FlixInfoEpisodes::Episode),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_episodes-library")
|
|
||||||
.from_tbl(FlixEpisodes::Table)
|
|
||||||
.from_col(FlixEpisodes::Library)
|
|
||||||
.to_tbl(FlixLibraries::Table)
|
|
||||||
.to_col(FlixLibraries::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixEpisodes::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::Table;
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::binary;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixLibraries {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Directory,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixLibraries::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixLibraries::Id))
|
|
||||||
.col(binary(FlixLibraries::Directory))
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixLibraries::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{binary, integer, integer_null, string, string_null};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoMovies;
|
|
||||||
use crate::migration::m_000003::{FlixCollections, FlixLibraries};
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixMovies {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Parent,
|
|
||||||
Slug,
|
|
||||||
Library,
|
|
||||||
Directory,
|
|
||||||
RelativeMediaPath,
|
|
||||||
RelativePosterPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixMovies::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixMovies::Id))
|
|
||||||
.col(integer_null(FlixMovies::Parent))
|
|
||||||
.col(string(FlixMovies::Slug))
|
|
||||||
.col(integer(FlixMovies::Library))
|
|
||||||
.col(binary(FlixMovies::Directory))
|
|
||||||
.col(string(FlixMovies::RelativeMediaPath))
|
|
||||||
.col(string_null(FlixMovies::RelativePosterPath))
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_movies-id")
|
|
||||||
.from_tbl(FlixMovies::Table)
|
|
||||||
.from_col(FlixMovies::Id)
|
|
||||||
.to_tbl(FlixInfoMovies::Table)
|
|
||||||
.to_col(FlixInfoMovies::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_movies-parent")
|
|
||||||
.from_tbl(FlixMovies::Table)
|
|
||||||
.from_col(FlixMovies::Parent)
|
|
||||||
.to_tbl(FlixCollections::Table)
|
|
||||||
.to_col(FlixCollections::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_movies-library")
|
|
||||||
.from_tbl(FlixMovies::Table)
|
|
||||||
.from_col(FlixMovies::Library)
|
|
||||||
.to_tbl(FlixLibraries::Table)
|
|
||||||
.to_col(FlixLibraries::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixMovies::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{binary, integer, string, string_null};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoSeasons;
|
|
||||||
use crate::migration::m_000003::FlixLibraries;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixSeasons {
|
|
||||||
Table,
|
|
||||||
Show,
|
|
||||||
Season,
|
|
||||||
Slug,
|
|
||||||
Library,
|
|
||||||
Directory,
|
|
||||||
RelativePosterPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixSeasons::Table)
|
|
||||||
.col(integer(FlixSeasons::Show))
|
|
||||||
.col(integer(FlixSeasons::Season))
|
|
||||||
.col(string(FlixSeasons::Slug))
|
|
||||||
.col(integer(FlixSeasons::Library))
|
|
||||||
.col(binary(FlixSeasons::Directory))
|
|
||||||
.col(string_null(FlixSeasons::RelativePosterPath))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixSeasons::Show)
|
|
||||||
.col(FlixSeasons::Season),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_seasons-show_season")
|
|
||||||
.from_tbl(FlixSeasons::Table)
|
|
||||||
.from_col(FlixSeasons::Show)
|
|
||||||
.from_col(FlixSeasons::Season)
|
|
||||||
.to_tbl(FlixInfoSeasons::Table)
|
|
||||||
.to_col(FlixInfoSeasons::Show)
|
|
||||||
.to_col(FlixInfoSeasons::Season),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_seasons-library")
|
|
||||||
.from_tbl(FlixSeasons::Table)
|
|
||||||
.from_col(FlixSeasons::Library)
|
|
||||||
.to_tbl(FlixLibraries::Table)
|
|
||||||
.to_col(FlixLibraries::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixSeasons::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
use seamantic::schema::sqlite_rowid_alias;
|
|
||||||
|
|
||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{binary, integer, integer_null, string, string_null};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoShows;
|
|
||||||
use crate::migration::m_000003::{FlixCollections, FlixLibraries};
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixShows {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Parent,
|
|
||||||
Slug,
|
|
||||||
Library,
|
|
||||||
Directory,
|
|
||||||
RelativePosterPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixShows::Table)
|
|
||||||
.col(sqlite_rowid_alias(FlixShows::Id))
|
|
||||||
.col(integer_null(FlixShows::Parent))
|
|
||||||
.col(string(FlixShows::Slug))
|
|
||||||
.col(integer(FlixShows::Library))
|
|
||||||
.col(binary(FlixShows::Directory))
|
|
||||||
.col(string_null(FlixShows::RelativePosterPath))
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_shows-id")
|
|
||||||
.from_tbl(FlixShows::Table)
|
|
||||||
.from_col(FlixShows::Id)
|
|
||||||
.to_tbl(FlixInfoShows::Table)
|
|
||||||
.to_col(FlixInfoShows::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_shows-parent")
|
|
||||||
.from_tbl(FlixShows::Table)
|
|
||||||
.from_col(FlixShows::Parent)
|
|
||||||
.to_tbl(FlixCollections::Table)
|
|
||||||
.to_col(FlixCollections::Id),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_shows-library")
|
|
||||||
.from_tbl(FlixShows::Table)
|
|
||||||
.from_col(FlixShows::Library)
|
|
||||||
.to_tbl(FlixLibraries::Table)
|
|
||||||
.to_col(FlixLibraries::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixShows::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
//! Adds entity/watched tables:
|
|
||||||
//! - Collections
|
|
||||||
//! - Movies
|
|
||||||
//! - Shows
|
|
||||||
//! - Seasons
|
|
||||||
//! - Episodes
|
|
||||||
|
|
||||||
use sea_orm::{DbErr, DeriveMigrationName};
|
|
||||||
use sea_orm_migration::async_trait;
|
|
||||||
use sea_orm_migration::{MigrationTrait, SchemaManager};
|
|
||||||
|
|
||||||
mod collections;
|
|
||||||
mod episodes;
|
|
||||||
mod movies;
|
|
||||||
mod seasons;
|
|
||||||
mod shows;
|
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use episodes::FlixWatchedEpisodes;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use movies::FlixWatchedMovies;
|
|
||||||
|
|
||||||
#[derive(DeriveMigrationName)]
|
|
||||||
pub(super) struct Migration;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigrationTrait for Migration {
|
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
episodes::up(manager).await?;
|
|
||||||
seasons::up(manager).await?;
|
|
||||||
shows::up(manager).await?;
|
|
||||||
movies::up(manager).await?;
|
|
||||||
collections::up(manager).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
collections::down(manager).await?;
|
|
||||||
movies::down(manager).await?;
|
|
||||||
shows::down(manager).await?;
|
|
||||||
seasons::down(manager).await?;
|
|
||||||
episodes::down(manager).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
use sea_orm::DbErr;
|
|
||||||
use sea_orm::{ConnectionTrait, DbBackend, Statement};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.get_connection()
|
|
||||||
.execute_raw(Statement::from_string(
|
|
||||||
DbBackend::Sqlite,
|
|
||||||
r#"
|
|
||||||
CREATE VIEW flix_watched_collections AS
|
|
||||||
WITH RECURSIVE
|
|
||||||
watched_items AS (
|
|
||||||
SELECT
|
|
||||||
w.id,
|
|
||||||
w.user_id,
|
|
||||||
w.watched_date,
|
|
||||||
'movie' AS type
|
|
||||||
FROM flix_watched_movies w
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
w.id,
|
|
||||||
w.user_id,
|
|
||||||
w.watched_date,
|
|
||||||
'show' AS type
|
|
||||||
FROM flix_watched_shows w
|
|
||||||
),
|
|
||||||
collection_items AS (
|
|
||||||
SELECT
|
|
||||||
m.parent,
|
|
||||||
m.id,
|
|
||||||
'movie' AS type
|
|
||||||
FROM flix_movies m
|
|
||||||
WHERE m.parent IS NOT NULL
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
s.parent,
|
|
||||||
s.id,
|
|
||||||
'show' AS type
|
|
||||||
FROM flix_shows s
|
|
||||||
WHERE s.parent IS NOT NULL
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
c.parent,
|
|
||||||
ci.id,
|
|
||||||
ci.type
|
|
||||||
FROM collection_items ci
|
|
||||||
JOIN flix_collections c
|
|
||||||
ON c.id = ci.parent
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
ci.parent AS id,
|
|
||||||
wi.user_id,
|
|
||||||
MAX(wi.watched_date) AS watched_date
|
|
||||||
FROM collection_items ci
|
|
||||||
JOIN watched_items wi
|
|
||||||
ON wi.id = ci.id
|
|
||||||
AND wi.type = ci.type
|
|
||||||
WHERE NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM collection_items ci2
|
|
||||||
WHERE ci2.parent = ci.parent
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM watched_items wi2
|
|
||||||
WHERE wi2.id = ci2.id
|
|
||||||
AND wi2.type = ci2.type
|
|
||||||
AND wi2.user_id = wi.user_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
GROUP BY ci.parent, wi.user_id;
|
|
||||||
"#,
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.get_connection()
|
|
||||||
.execute_raw(Statement::from_string(
|
|
||||||
DbBackend::Sqlite,
|
|
||||||
r#"
|
|
||||||
DROP VIEW flix_watched_collections
|
|
||||||
;
|
|
||||||
"#,
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoEpisodes;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixWatchedEpisodes {
|
|
||||||
Table,
|
|
||||||
Show,
|
|
||||||
Season,
|
|
||||||
Episode,
|
|
||||||
UserId,
|
|
||||||
WatchedDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixWatchedEpisodes::Table)
|
|
||||||
.col(integer(FlixWatchedEpisodes::Show))
|
|
||||||
.col(integer(FlixWatchedEpisodes::Season))
|
|
||||||
.col(integer(FlixWatchedEpisodes::Episode))
|
|
||||||
.col(integer(FlixWatchedEpisodes::UserId))
|
|
||||||
.col(date(FlixWatchedEpisodes::WatchedDate))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixWatchedEpisodes::Show)
|
|
||||||
.col(FlixWatchedEpisodes::Season)
|
|
||||||
.col(FlixWatchedEpisodes::Episode)
|
|
||||||
.col(FlixWatchedEpisodes::UserId),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_watched_episodes-show_season_episode")
|
|
||||||
.from_tbl(FlixWatchedEpisodes::Table)
|
|
||||||
.from_tbl(FlixWatchedEpisodes::Table)
|
|
||||||
.from_col(FlixWatchedEpisodes::Show)
|
|
||||||
.from_col(FlixWatchedEpisodes::Season)
|
|
||||||
.from_col(FlixWatchedEpisodes::Episode)
|
|
||||||
.to_tbl(FlixInfoEpisodes::Table)
|
|
||||||
.to_col(FlixInfoEpisodes::Show)
|
|
||||||
.to_col(FlixInfoEpisodes::Season)
|
|
||||||
.to_col(FlixInfoEpisodes::Episode),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixWatchedEpisodes::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
use sea_orm::sea_query;
|
|
||||||
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
|
|
||||||
use sea_orm::{DbErr, Iden};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
use sea_orm_migration::schema::{date, integer};
|
|
||||||
|
|
||||||
use crate::migration::m_000001::FlixInfoMovies;
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum FlixWatchedMovies {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
UserId,
|
|
||||||
WatchedDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(FlixWatchedMovies::Table)
|
|
||||||
.col(integer(FlixWatchedMovies::Id))
|
|
||||||
.col(integer(FlixWatchedMovies::UserId))
|
|
||||||
.col(date(FlixWatchedMovies::WatchedDate))
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(FlixWatchedMovies::Id)
|
|
||||||
.col(FlixWatchedMovies::UserId),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKeyCreateStatement::new()
|
|
||||||
.name("fk-flix_watched_movies-id")
|
|
||||||
.from_tbl(FlixWatchedMovies::Table)
|
|
||||||
.from_col(FlixWatchedMovies::Id)
|
|
||||||
.to_tbl(FlixInfoMovies::Table)
|
|
||||||
.to_col(FlixInfoMovies::Id),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(FlixWatchedMovies::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
use sea_orm::DbErr;
|
|
||||||
use sea_orm::{ConnectionTrait, DbBackend, Statement};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.get_connection()
|
|
||||||
.execute_raw(Statement::from_string(
|
|
||||||
DbBackend::Sqlite,
|
|
||||||
r#"
|
|
||||||
CREATE VIEW flix_watched_seasons AS
|
|
||||||
SELECT
|
|
||||||
w.show,
|
|
||||||
w.season,
|
|
||||||
w.user_id,
|
|
||||||
MAX(w.watched_date) AS watched_date
|
|
||||||
FROM flix_watched_episodes w
|
|
||||||
WHERE NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM flix_episodes e
|
|
||||||
WHERE e.show = w.show
|
|
||||||
AND e.season = w.season
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM flix_watched_episodes wc
|
|
||||||
WHERE wc.show = e.show
|
|
||||||
AND wc.season = e.season
|
|
||||||
AND wc.episode = e.episode
|
|
||||||
AND wc.user_id = w.user_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
GROUP BY w.show, w.season, w.user_id
|
|
||||||
;
|
|
||||||
"#,
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.get_connection()
|
|
||||||
.execute_raw(Statement::from_string(
|
|
||||||
DbBackend::Sqlite,
|
|
||||||
r#"
|
|
||||||
DROP VIEW flix_watched_seasons
|
|
||||||
;
|
|
||||||
"#,
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
use sea_orm::DbErr;
|
|
||||||
use sea_orm::{ConnectionTrait, DbBackend, Statement};
|
|
||||||
use sea_orm_migration::SchemaManager;
|
|
||||||
|
|
||||||
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.get_connection()
|
|
||||||
.execute_raw(Statement::from_string(
|
|
||||||
DbBackend::Sqlite,
|
|
||||||
r#"
|
|
||||||
CREATE VIEW flix_watched_shows AS
|
|
||||||
SELECT
|
|
||||||
w.show as id,
|
|
||||||
w.user_id,
|
|
||||||
MAX(w.watched_date) AS watched_date
|
|
||||||
FROM flix_watched_seasons w
|
|
||||||
WHERE NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM flix_seasons s
|
|
||||||
WHERE s.show = w.show
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM flix_watched_seasons wc
|
|
||||||
WHERE wc.show = s.show
|
|
||||||
AND wc.season = s.season
|
|
||||||
AND wc.user_id = w.user_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
GROUP BY w.show, w.user_id
|
|
||||||
;
|
|
||||||
"#,
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.get_connection()
|
|
||||||
.execute_raw(Statement::from_string(
|
|
||||||
DbBackend::Sqlite,
|
|
||||||
r#"
|
|
||||||
DROP VIEW flix_watched_shows
|
|
||||||
;
|
|
||||||
"#,
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,4 @@
|
|||||||
seamantic::migrations! {
|
seamantic::migrations! {
|
||||||
"seaql_migrations_flix";
|
"seaql_migrations_flix";
|
||||||
m_000001,
|
m_000001,
|
||||||
m_000002,
|
|
||||||
m_000003,
|
|
||||||
m_000004,
|
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-15
@@ -1,22 +1,22 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix"
|
name = "flix"
|
||||||
version = "0.0.12"
|
version = "0.0.17"
|
||||||
|
edition.workspace = true
|
||||||
categories = []
|
rust-version.workspace = true
|
||||||
description = "Mechanisms for interacting with flix media"
|
description = "Mechanisms for interacting with flix media"
|
||||||
repository = "https://github.com/QuantumShade/flix"
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
rust-version.workspace = true
|
categories = []
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[lints]
|
[dependencies]
|
||||||
workspace = true
|
flix-db = { workspace = true }
|
||||||
|
flix-fs = { workspace = true, optional = true }
|
||||||
|
flix-model = { workspace = true }
|
||||||
|
flix-tmdb = { workspace = true, optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
@@ -24,9 +24,5 @@ fs = ["dep:flix-fs"]
|
|||||||
serde = ["flix-model/serde"]
|
serde = ["flix-model/serde"]
|
||||||
tmdb = ["dep:flix-tmdb", "flix-db/tmdb"]
|
tmdb = ["dep:flix-tmdb", "flix-db/tmdb"]
|
||||||
|
|
||||||
[dependencies]
|
[lints]
|
||||||
flix-db = { workspace = true }
|
workspace = true
|
||||||
flix-model = { workspace = true }
|
|
||||||
|
|
||||||
flix-fs = { workspace = true, optional = true }
|
|
||||||
flix-tmdb = { workspace = true, optional = true }
|
|
||||||
|
|||||||
+10
-13
@@ -1,28 +1,25 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-fs"
|
name = "flix-fs"
|
||||||
version = "0.0.12"
|
version = "0.0.17"
|
||||||
|
edition.workspace = true
|
||||||
categories = []
|
rust-version.workspace = true
|
||||||
description = "Filesystem scanner for flix media"
|
description = "Filesystem scanner for flix media"
|
||||||
repository = "https://github.com/QuantumShade/flix"
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
rust-version.workspace = true
|
categories = []
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
flix-model = { workspace = true }
|
|
||||||
|
|
||||||
async-stream = { workspace = true }
|
async-stream = { workspace = true }
|
||||||
regex = { workspace = true, features = ["std", "perf"] }
|
either = { workspace = true }
|
||||||
|
flix-model = { workspace = true }
|
||||||
|
regex = { workspace = true, features = ["perf", "std"] }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
tokio-stream = { workspace = true, features = ["fs"] }
|
tokio-stream = { workspace = true, features = ["fs"] }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ use core::pin::Pin;
|
|||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, MovieId, ShowId};
|
use flix_model::id::CollectionId;
|
||||||
use flix_model::numbers::{EpisodeNumbers, SeasonNumber};
|
|
||||||
|
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
@@ -14,7 +13,9 @@ use tokio_stream::wrappers::ReadDirStream;
|
|||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::macros::is_image_extension;
|
use crate::macros::is_image_extension;
|
||||||
use crate::scanner::{generic, movie, show};
|
use crate::scanner::{
|
||||||
|
CollectionScan, EpisodeScan, MediaRef, MovieScan, SeasonScan, ShowScan, generic, movie, show,
|
||||||
|
};
|
||||||
|
|
||||||
/// A collection item
|
/// A collection item
|
||||||
pub type Item = crate::Item<Scanner>;
|
pub type Item = crate::Item<Scanner>;
|
||||||
@@ -22,74 +23,21 @@ pub type Item = crate::Item<Scanner>;
|
|||||||
/// The scanner for collections
|
/// The scanner for collections
|
||||||
pub enum Scanner {
|
pub enum Scanner {
|
||||||
/// A scanned collection
|
/// A scanned collection
|
||||||
Collection {
|
Collection(CollectionScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the collection
|
|
||||||
id: CollectionId,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A scanned movie
|
/// A scanned movie
|
||||||
Movie {
|
Movie(MovieScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the movie
|
|
||||||
id: MovieId,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A scanned show
|
/// A scanned show
|
||||||
Show {
|
Show(ShowScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the show
|
|
||||||
id: ShowId,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Season {
|
Season(SeasonScan),
|
||||||
/// The ID of the show this season belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The number of this season
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Episode {
|
Episode(EpisodeScan),
|
||||||
/// The ID of the show this episode belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The number(s) of this episode
|
|
||||||
episode: EpisodeNumbers,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<movie::Scanner> for Scanner {
|
impl From<movie::Scanner> for Scanner {
|
||||||
fn from(value: movie::Scanner) -> Self {
|
fn from(value: movie::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
movie::Scanner::Movie {
|
movie::Scanner::Movie(m) => Self::Movie(m),
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Movie {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,37 +45,9 @@ impl From<movie::Scanner> for Scanner {
|
|||||||
impl From<show::Scanner> for Scanner {
|
impl From<show::Scanner> for Scanner {
|
||||||
fn from(value: show::Scanner) -> Self {
|
fn from(value: show::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
show::Scanner::Show {
|
show::Scanner::Show(s) => Self::Show(s),
|
||||||
parent,
|
show::Scanner::Season(s) => Self::Season(s),
|
||||||
id,
|
show::Scanner::Episode(e) => Self::Episode(e),
|
||||||
poster_file_name,
|
|
||||||
} => Self::Show {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
show::Scanner::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
show::Scanner::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,57 +55,11 @@ impl From<show::Scanner> for Scanner {
|
|||||||
impl From<generic::Scanner> for Scanner {
|
impl From<generic::Scanner> for Scanner {
|
||||||
fn from(value: generic::Scanner) -> Self {
|
fn from(value: generic::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
generic::Scanner::Collection {
|
generic::Scanner::Collection(c) => Self::Collection(c),
|
||||||
parent,
|
generic::Scanner::Movie(m) => Self::Movie(m),
|
||||||
id,
|
generic::Scanner::Show(s) => Self::Show(s),
|
||||||
poster_file_name,
|
generic::Scanner::Season(s) => Self::Season(s),
|
||||||
} => Self::Collection {
|
generic::Scanner::Episode(e) => Self::Episode(e),
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
generic::Scanner::Movie {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Movie {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
generic::Scanner::Show {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Show {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
generic::Scanner::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
generic::Scanner::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,8 +68,8 @@ impl Scanner {
|
|||||||
/// Scan a folder for a collection
|
/// Scan a folder for a collection
|
||||||
pub fn scan_collection(
|
pub fn scan_collection(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
parent: Option<CollectionId>,
|
parent_ref: Option<MediaRef<CollectionId>>,
|
||||||
id: CollectionId,
|
id_ref: MediaRef<CollectionId>,
|
||||||
) -> Pin<Box<impl Stream<Item = Item>>> {
|
) -> Pin<Box<impl Stream<Item = Item>>> {
|
||||||
Box::pin(stream!({
|
Box::pin(stream!({
|
||||||
let dirs = match fs::read_dir(path).await {
|
let dirs = match fs::read_dir(path).await {
|
||||||
@@ -215,18 +89,19 @@ impl Scanner {
|
|||||||
for await dir in ReadDirStream::new(dirs) {
|
for await dir in ReadDirStream::new(dirs) {
|
||||||
match dir {
|
match dir {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
|
let path = dir.path();
|
||||||
|
|
||||||
let filetype = match dir.file_type().await {
|
let filetype = match dir.file_type().await {
|
||||||
Ok(filetype) => filetype,
|
Ok(filetype) => filetype,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::FileType(err)),
|
event: Err(Error::FileType(err)),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = dir.path();
|
|
||||||
if filetype.is_dir() {
|
if filetype.is_dir() {
|
||||||
subdirs_to_scan.push(path);
|
subdirs_to_scan.push(path);
|
||||||
continue;
|
continue;
|
||||||
@@ -236,7 +111,7 @@ impl Scanner {
|
|||||||
is_image_extension!() => {
|
is_image_extension!() => {
|
||||||
if poster_file_name.is_some() {
|
if poster_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicatePosterFile),
|
event: Err(Error::DuplicatePosterFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -248,7 +123,7 @@ impl Scanner {
|
|||||||
}
|
}
|
||||||
Some(_) | None => {
|
Some(_) | None => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedFile),
|
event: Err(Error::UnexpectedFile),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -265,15 +140,17 @@ impl Scanner {
|
|||||||
|
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
event: Ok(Self::Collection {
|
event: Ok(Self::Collection(CollectionScan {
|
||||||
parent,
|
parent_ref,
|
||||||
id,
|
id_ref: id_ref.clone(),
|
||||||
poster_file_name,
|
poster_file_name,
|
||||||
}),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
for subdir in subdirs_to_scan {
|
for subdir in subdirs_to_scan {
|
||||||
for await event in generic::Scanner::scan_detect_folder(&subdir, Some(id)) {
|
for await event in
|
||||||
|
generic::Scanner::scan_detect_folder(&subdir, Some(id_ref.clone()))
|
||||||
|
{
|
||||||
yield event.map(|e| e.into());
|
yield event.map(|e| e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use tokio_stream::wrappers::ReadDirStream;
|
|||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::macros::{is_image_extension, is_media_extension};
|
use crate::macros::{is_image_extension, is_media_extension};
|
||||||
|
use crate::scanner::{EpisodeScan, MediaRef};
|
||||||
|
|
||||||
/// An episode item
|
/// An episode item
|
||||||
pub type Item = crate::Item<Scanner>;
|
pub type Item = crate::Item<Scanner>;
|
||||||
@@ -20,25 +21,14 @@ pub type Item = crate::Item<Scanner>;
|
|||||||
/// The scanner for epispdes
|
/// The scanner for epispdes
|
||||||
pub enum Scanner {
|
pub enum Scanner {
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Episode {
|
Episode(EpisodeScan),
|
||||||
/// The ID of the show this episode belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The number(s) of this episode
|
|
||||||
episode: EpisodeNumbers,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scanner {
|
impl Scanner {
|
||||||
/// Scan a folder for an episode
|
/// Scan a folder for an episode
|
||||||
pub fn scan_episode(
|
pub fn scan_episode(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
show: ShowId,
|
show_ref: MediaRef<ShowId>,
|
||||||
season: SeasonNumber,
|
season: SeasonNumber,
|
||||||
episode: EpisodeNumbers,
|
episode: EpisodeNumbers,
|
||||||
) -> impl Stream<Item = Item> {
|
) -> impl Stream<Item = Item> {
|
||||||
@@ -60,11 +50,13 @@ impl Scanner {
|
|||||||
for await dir in ReadDirStream::new(dirs) {
|
for await dir in ReadDirStream::new(dirs) {
|
||||||
match dir {
|
match dir {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
|
let path = dir.path();
|
||||||
|
|
||||||
let filetype = match dir.file_type().await {
|
let filetype = match dir.file_type().await {
|
||||||
Ok(filetype) => filetype,
|
Ok(filetype) => filetype,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::FileType(err)),
|
event: Err(Error::FileType(err)),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -72,18 +64,17 @@ impl Scanner {
|
|||||||
};
|
};
|
||||||
if !filetype.is_file() {
|
if !filetype.is_file() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedNonFile),
|
event: Err(Error::UnexpectedNonFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = dir.path();
|
|
||||||
match path.extension().and_then(OsStr::to_str) {
|
match path.extension().and_then(OsStr::to_str) {
|
||||||
is_media_extension!() => {
|
is_media_extension!() => {
|
||||||
if media_file_name.is_some() {
|
if media_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicateMediaFile),
|
event: Err(Error::DuplicateMediaFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -97,7 +88,7 @@ impl Scanner {
|
|||||||
is_image_extension!() => {
|
is_image_extension!() => {
|
||||||
if poster_file_name.is_some() {
|
if poster_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicatePosterFile),
|
event: Err(Error::DuplicatePosterFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -109,7 +100,7 @@ impl Scanner {
|
|||||||
}
|
}
|
||||||
Some(_) | None => {
|
Some(_) | None => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedFile),
|
event: Err(Error::UnexpectedFile),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -134,13 +125,13 @@ impl Scanner {
|
|||||||
|
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
event: Ok(Self::Episode {
|
event: Ok(Self::Episode(EpisodeScan {
|
||||||
show,
|
show_ref,
|
||||||
season,
|
season,
|
||||||
episode,
|
episode,
|
||||||
media_file_name,
|
media_file_name,
|
||||||
poster_file_name,
|
poster_file_name,
|
||||||
}),
|
})),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,18 @@ use std::path::Path;
|
|||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, MovieId, RawId, ShowId};
|
use flix_model::id::{CollectionId, MovieId, RawId, ShowId};
|
||||||
use flix_model::numbers::{EpisodeNumbers, SeasonNumber};
|
|
||||||
|
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
|
use either::Either;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio_stream::Stream;
|
use tokio_stream::Stream;
|
||||||
use tokio_stream::wrappers::ReadDirStream;
|
use tokio_stream::wrappers::ReadDirStream;
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::scanner::{collection, movie, show};
|
use crate::scanner::{
|
||||||
|
CollectionScan, EpisodeScan, MediaRef, MovieScan, SeasonScan, ShowScan, collection, movie, show,
|
||||||
|
};
|
||||||
|
|
||||||
static MEDIA_FOLDER_REGEX: OnceLock<Regex> = OnceLock::new();
|
static MEDIA_FOLDER_REGEX: OnceLock<Regex> = OnceLock::new();
|
||||||
static SEASON_FOLDER_REGEX: OnceLock<Regex> = OnceLock::new();
|
static SEASON_FOLDER_REGEX: OnceLock<Regex> = OnceLock::new();
|
||||||
@@ -24,116 +26,28 @@ static SEASON_FOLDER_REGEX: OnceLock<Regex> = OnceLock::new();
|
|||||||
pub type Item = crate::Item<Scanner>;
|
pub type Item = crate::Item<Scanner>;
|
||||||
|
|
||||||
/// The scanner for collections
|
/// The scanner for collections
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Scanner {
|
pub enum Scanner {
|
||||||
/// A scanned collection
|
/// A scanned collection
|
||||||
Collection {
|
Collection(CollectionScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the collection
|
|
||||||
id: CollectionId,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A scanned movie
|
/// A scanned movie
|
||||||
Movie {
|
Movie(MovieScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the movie
|
|
||||||
id: MovieId,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A scanned show
|
/// A scanned show
|
||||||
Show {
|
Show(ShowScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the show
|
|
||||||
id: ShowId,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Season {
|
Season(SeasonScan),
|
||||||
/// The ID of the show this season belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Episode {
|
Episode(EpisodeScan),
|
||||||
/// The ID of the show this episode belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The number(s) of this episode
|
|
||||||
episode: EpisodeNumbers,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<collection::Scanner> for Scanner {
|
impl From<collection::Scanner> for Scanner {
|
||||||
fn from(value: collection::Scanner) -> Self {
|
fn from(value: collection::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
collection::Scanner::Collection {
|
collection::Scanner::Collection(c) => Self::Collection(c),
|
||||||
parent,
|
collection::Scanner::Movie(m) => Self::Movie(m),
|
||||||
id,
|
collection::Scanner::Show(s) => Self::Show(s),
|
||||||
poster_file_name,
|
collection::Scanner::Season(s) => Self::Season(s),
|
||||||
} => Self::Collection {
|
collection::Scanner::Episode(e) => Self::Episode(e),
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
collection::Scanner::Movie {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Movie {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
collection::Scanner::Show {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Show {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
collection::Scanner::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
collection::Scanner::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,17 +55,7 @@ impl From<collection::Scanner> for Scanner {
|
|||||||
impl From<movie::Scanner> for Scanner {
|
impl From<movie::Scanner> for Scanner {
|
||||||
fn from(value: movie::Scanner) -> Self {
|
fn from(value: movie::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
movie::Scanner::Movie {
|
movie::Scanner::Movie(m) => Self::Movie(m),
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Movie {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,42 +63,22 @@ impl From<movie::Scanner> for Scanner {
|
|||||||
impl From<show::Scanner> for Scanner {
|
impl From<show::Scanner> for Scanner {
|
||||||
fn from(value: show::Scanner) -> Self {
|
fn from(value: show::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
show::Scanner::Show {
|
show::Scanner::Show(s) => Self::Show(s),
|
||||||
parent,
|
show::Scanner::Season(s) => Self::Season(s),
|
||||||
id,
|
show::Scanner::Episode(e) => Self::Episode(e),
|
||||||
poster_file_name,
|
|
||||||
} => Self::Show {
|
|
||||||
parent,
|
|
||||||
id,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
show::Scanner::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
show::Scanner::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scanner {
|
impl Scanner {
|
||||||
|
/// Helper function for stripping allowed numerical prefixes for sorting ("01 - ")
|
||||||
|
fn strip_numeric_prefix(mut s: &str) -> &str {
|
||||||
|
while let Some('0'..='9') = s.chars().next() {
|
||||||
|
s = &s[1..]
|
||||||
|
}
|
||||||
|
s.strip_prefix(" - ").unwrap_or(s)
|
||||||
|
}
|
||||||
|
|
||||||
/// Detect the type of a folder and call the correct scanner. Use
|
/// Detect the type of a folder and call the correct scanner. Use
|
||||||
/// this only for detecting possibly ambiguous media:
|
/// this only for detecting possibly ambiguous media:
|
||||||
/// - Collections
|
/// - Collections
|
||||||
@@ -202,7 +86,7 @@ impl Scanner {
|
|||||||
/// - Shows
|
/// - Shows
|
||||||
pub fn scan_detect_folder(
|
pub fn scan_detect_folder(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
parent: Option<CollectionId>,
|
parent: Option<MediaRef<CollectionId>>,
|
||||||
) -> impl Stream<Item = Item> {
|
) -> impl Stream<Item = Item> {
|
||||||
enum MediaType {
|
enum MediaType {
|
||||||
Collection,
|
Collection,
|
||||||
@@ -211,7 +95,7 @@ impl Scanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let media_folder_re = MEDIA_FOLDER_REGEX.get_or_init(|| {
|
let media_folder_re = MEDIA_FOLDER_REGEX.get_or_init(|| {
|
||||||
Regex::new(r"^[[[:alnum:]] -]+ \([[:digit:]]+\) \[[[:digit:]]+\]$")
|
Regex::new(r"^[[[:alnum:]]' -]+ \([[:digit:]]+\)( \[[[:digit:]]+\])?$")
|
||||||
.unwrap_or_else(|err| panic!("regex is invalid: {err}"))
|
.unwrap_or_else(|err| panic!("regex is invalid: {err}"))
|
||||||
});
|
});
|
||||||
let season_folder_re = SEASON_FOLDER_REGEX.get_or_init(|| {
|
let season_folder_re = SEASON_FOLDER_REGEX.get_or_init(|| {
|
||||||
@@ -227,16 +111,23 @@ impl Scanner {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(Ok(id)) = dir_name
|
let dir_name = Self::strip_numeric_prefix(dir_name);
|
||||||
|
|
||||||
|
// Use the explicit ID ("[X]") if it exists, otherwise parse the folder name
|
||||||
|
let media_id = if let Some((id_str, _)) = dir_name
|
||||||
.split_once('[')
|
.split_once('[')
|
||||||
.and_then(|(_, s)| s.split_once(']'))
|
.and_then(|(_, s)| s.split_once(']'))
|
||||||
.map(|(s, _)| s.parse::<RawId>())
|
{
|
||||||
else {
|
let Ok(id) = id_str.parse::<RawId>() else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
|
};
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
return;
|
Either::Left(id)
|
||||||
|
} else {
|
||||||
|
Either::Right(flix_model::text::normalize_fs_name(dir_name))
|
||||||
};
|
};
|
||||||
|
|
||||||
let media_type: MediaType;
|
let media_type: MediaType;
|
||||||
@@ -257,11 +148,13 @@ impl Scanner {
|
|||||||
for await dir in ReadDirStream::new(dirs) {
|
for await dir in ReadDirStream::new(dirs) {
|
||||||
match dir {
|
match dir {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
|
let path = dir.path();
|
||||||
|
|
||||||
let filetype = match dir.file_type().await {
|
let filetype = match dir.file_type().await {
|
||||||
Ok(filetype) => filetype,
|
Ok(filetype) => filetype,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::FileType(err)),
|
event: Err(Error::FileType(err)),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -271,11 +164,9 @@ impl Scanner {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir_path = dir.path();
|
let Some(folder_name) = path.file_name().and_then(OsStr::to_str) else {
|
||||||
let Some(folder_name) = dir_path.file_name().and_then(OsStr::to_str)
|
|
||||||
else {
|
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -306,24 +197,32 @@ impl Scanner {
|
|||||||
|
|
||||||
match media_type {
|
match media_type {
|
||||||
MediaType::Collection => {
|
MediaType::Collection => {
|
||||||
for await event in collection::Scanner::scan_collection(
|
let id = match media_id {
|
||||||
path,
|
Either::Left(raw) => MediaRef::Id(CollectionId::from_raw(raw)),
|
||||||
parent,
|
Either::Right(slug) => MediaRef::Slug(slug),
|
||||||
CollectionId::from_raw(id),
|
};
|
||||||
) {
|
|
||||||
|
for await event in collection::Scanner::scan_collection(path, parent, id) {
|
||||||
yield event.map(|e| e.into());
|
yield event.map(|e| e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MediaType::Movie => {
|
MediaType::Movie => {
|
||||||
for await event in
|
let id = match media_id {
|
||||||
movie::Scanner::scan_movie(path, parent, MovieId::from_raw(id))
|
Either::Left(raw) => MediaRef::Id(MovieId::from_raw(raw)),
|
||||||
{
|
Either::Right(slug) => MediaRef::Slug(slug),
|
||||||
|
};
|
||||||
|
|
||||||
|
for await event in movie::Scanner::scan_movie(path, parent, id) {
|
||||||
yield event.map(|e| e.into());
|
yield event.map(|e| e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MediaType::Show => {
|
MediaType::Show => {
|
||||||
for await event in show::Scanner::scan_show(path, parent, ShowId::from_raw(id))
|
let id = match media_id {
|
||||||
{
|
Either::Left(raw) => MediaRef::Id(ShowId::from_raw(raw)),
|
||||||
|
Either::Right(slug) => MediaRef::Slug(slug),
|
||||||
|
};
|
||||||
|
|
||||||
|
for await event in show::Scanner::scan_show(path, parent, id) {
|
||||||
yield event.map(|e| e.into());
|
yield event.map(|e| e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
//! The most common scanner to use is [generic::Scanner] which will
|
//! The most common scanner to use is [generic::Scanner] which will
|
||||||
//! automatically detect and use the appropriate scanner.
|
//! automatically detect and use the appropriate scanner.
|
||||||
|
|
||||||
|
use flix_model::id::{CollectionId, MovieId, ShowId};
|
||||||
|
use flix_model::numbers::{EpisodeNumbers, SeasonNumber};
|
||||||
|
|
||||||
pub mod library;
|
pub mod library;
|
||||||
|
|
||||||
pub mod generic;
|
pub mod generic;
|
||||||
@@ -14,3 +17,73 @@ pub mod movie;
|
|||||||
pub mod episode;
|
pub mod episode;
|
||||||
pub mod season;
|
pub mod season;
|
||||||
pub mod show;
|
pub mod show;
|
||||||
|
|
||||||
|
/// A reference to a piece of media
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum MediaRef<ID> {
|
||||||
|
/// An explicit ID
|
||||||
|
Id(ID),
|
||||||
|
/// A filesystem slug
|
||||||
|
Slug(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A scanned collection
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CollectionScan {
|
||||||
|
/// The ID of the parent collection (if any)
|
||||||
|
pub parent_ref: Option<MediaRef<CollectionId>>,
|
||||||
|
/// The ID of the collection
|
||||||
|
pub id_ref: MediaRef<CollectionId>,
|
||||||
|
/// The file name of the poster file
|
||||||
|
pub poster_file_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A scanned movie
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct MovieScan {
|
||||||
|
/// The ID of the parent collection (if any)
|
||||||
|
pub parent_ref: Option<MediaRef<CollectionId>>,
|
||||||
|
/// The ID of the movie
|
||||||
|
pub id_ref: MediaRef<MovieId>,
|
||||||
|
/// The file name of the media file
|
||||||
|
pub media_file_name: String,
|
||||||
|
/// The file name of the poster file
|
||||||
|
pub poster_file_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A scanned show
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ShowScan {
|
||||||
|
/// The ID of the parent collection (if any)
|
||||||
|
pub parent_ref: Option<MediaRef<CollectionId>>,
|
||||||
|
/// The ID of the show
|
||||||
|
pub id_ref: MediaRef<ShowId>,
|
||||||
|
/// The file name of the poster file
|
||||||
|
pub poster_file_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A scanned season
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SeasonScan {
|
||||||
|
/// The ID of the show this season belongs to
|
||||||
|
pub show_ref: MediaRef<ShowId>,
|
||||||
|
/// The season this episode belongs to
|
||||||
|
pub season: SeasonNumber,
|
||||||
|
/// The file name of the poster file
|
||||||
|
pub poster_file_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A scanned episode
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct EpisodeScan {
|
||||||
|
/// The ID of the show this episode belongs to
|
||||||
|
pub show_ref: MediaRef<ShowId>,
|
||||||
|
/// The season this episode belongs to
|
||||||
|
pub season: SeasonNumber,
|
||||||
|
/// The number(s) of this episode
|
||||||
|
pub episode: EpisodeNumbers,
|
||||||
|
/// The file name of the media file
|
||||||
|
pub media_file_name: String,
|
||||||
|
/// The file name of the poster file
|
||||||
|
pub poster_file_name: Option<String>,
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use tokio_stream::wrappers::ReadDirStream;
|
|||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::macros::{is_image_extension, is_media_extension};
|
use crate::macros::{is_image_extension, is_media_extension};
|
||||||
|
use crate::scanner::{MediaRef, MovieScan};
|
||||||
|
|
||||||
/// An movie item
|
/// An movie item
|
||||||
pub type Item = crate::Item<Scanner>;
|
pub type Item = crate::Item<Scanner>;
|
||||||
@@ -19,24 +20,15 @@ pub type Item = crate::Item<Scanner>;
|
|||||||
/// The scanner for movies
|
/// The scanner for movies
|
||||||
pub enum Scanner {
|
pub enum Scanner {
|
||||||
/// A scanned movie
|
/// A scanned movie
|
||||||
Movie {
|
Movie(MovieScan),
|
||||||
/// The ID of the parent collection (if any)
|
|
||||||
parent: Option<CollectionId>,
|
|
||||||
/// The ID of the movie
|
|
||||||
id: MovieId,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scanner {
|
impl Scanner {
|
||||||
/// Scan a folder for a movie
|
/// Scan a folder for a movie
|
||||||
pub fn scan_movie(
|
pub fn scan_movie(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
parent: Option<CollectionId>,
|
parent_ref: Option<MediaRef<CollectionId>>,
|
||||||
id: MovieId,
|
id_ref: MediaRef<MovieId>,
|
||||||
) -> impl Stream<Item = Item> {
|
) -> impl Stream<Item = Item> {
|
||||||
stream!({
|
stream!({
|
||||||
let dirs = match fs::read_dir(path).await {
|
let dirs = match fs::read_dir(path).await {
|
||||||
@@ -56,11 +48,13 @@ impl Scanner {
|
|||||||
for await dir in ReadDirStream::new(dirs) {
|
for await dir in ReadDirStream::new(dirs) {
|
||||||
match dir {
|
match dir {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
|
let path = dir.path();
|
||||||
|
|
||||||
let filetype = match dir.file_type().await {
|
let filetype = match dir.file_type().await {
|
||||||
Ok(filetype) => filetype,
|
Ok(filetype) => filetype,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::FileType(err)),
|
event: Err(Error::FileType(err)),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -68,18 +62,17 @@ impl Scanner {
|
|||||||
};
|
};
|
||||||
if !filetype.is_file() {
|
if !filetype.is_file() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedNonFile),
|
event: Err(Error::UnexpectedNonFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = dir.path();
|
|
||||||
match path.extension().and_then(OsStr::to_str) {
|
match path.extension().and_then(OsStr::to_str) {
|
||||||
is_media_extension!() => {
|
is_media_extension!() => {
|
||||||
if media_file_name.is_some() {
|
if media_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicateMediaFile),
|
event: Err(Error::DuplicateMediaFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -93,7 +86,7 @@ impl Scanner {
|
|||||||
is_image_extension!() => {
|
is_image_extension!() => {
|
||||||
if poster_file_name.is_some() {
|
if poster_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicatePosterFile),
|
event: Err(Error::DuplicatePosterFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -105,7 +98,7 @@ impl Scanner {
|
|||||||
}
|
}
|
||||||
Some(_) | None => {
|
Some(_) | None => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedFile),
|
event: Err(Error::UnexpectedFile),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -130,12 +123,12 @@ impl Scanner {
|
|||||||
|
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
event: Ok(Self::Movie {
|
event: Ok(Self::Movie(MovieScan {
|
||||||
parent,
|
parent_ref,
|
||||||
id,
|
id_ref,
|
||||||
media_file_name,
|
media_file_name,
|
||||||
poster_file_name,
|
poster_file_name,
|
||||||
}),
|
})),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,53 +13,23 @@ use tokio_stream::wrappers::ReadDirStream;
|
|||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::macros::is_image_extension;
|
use crate::macros::is_image_extension;
|
||||||
use crate::scanner::episode;
|
use crate::scanner::{EpisodeScan, MediaRef, SeasonScan, episode};
|
||||||
|
|
||||||
/// A season item
|
/// A season item
|
||||||
pub type Item = crate::Item<Scanner>;
|
pub type Item = crate::Item<Scanner>;
|
||||||
|
|
||||||
/// The scanner for seasons
|
/// The scanner for seasons
|
||||||
pub enum Scanner {
|
pub enum Scanner {
|
||||||
|
/// A scanned season
|
||||||
|
Season(SeasonScan),
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Season {
|
Episode(EpisodeScan),
|
||||||
/// The ID of the show this season belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
|
||||||
Episode {
|
|
||||||
/// The ID of the show this episode belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The number(s) of this episode
|
|
||||||
episode: EpisodeNumbers,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<episode::Scanner> for Scanner {
|
impl From<episode::Scanner> for Scanner {
|
||||||
fn from(value: episode::Scanner) -> Self {
|
fn from(value: episode::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
episode::Scanner::Episode {
|
episode::Scanner::Episode(e) => Self::Episode(e),
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +38,7 @@ impl Scanner {
|
|||||||
/// Scan a folder for a season and its episodes
|
/// Scan a folder for a season and its episodes
|
||||||
pub fn scan_season(
|
pub fn scan_season(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
show: ShowId,
|
show_ref: MediaRef<ShowId>,
|
||||||
season: SeasonNumber,
|
season: SeasonNumber,
|
||||||
) -> impl Stream<Item = Item> {
|
) -> impl Stream<Item = Item> {
|
||||||
stream!({
|
stream!({
|
||||||
@@ -89,18 +59,19 @@ impl Scanner {
|
|||||||
for await dir in ReadDirStream::new(dirs) {
|
for await dir in ReadDirStream::new(dirs) {
|
||||||
match dir {
|
match dir {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
|
let path = dir.path();
|
||||||
|
|
||||||
let filetype = match dir.file_type().await {
|
let filetype = match dir.file_type().await {
|
||||||
Ok(filetype) => filetype,
|
Ok(filetype) => filetype,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::FileType(err)),
|
event: Err(Error::FileType(err)),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = dir.path();
|
|
||||||
if filetype.is_dir() {
|
if filetype.is_dir() {
|
||||||
episode_dirs_to_scan.push(path);
|
episode_dirs_to_scan.push(path);
|
||||||
continue;
|
continue;
|
||||||
@@ -110,7 +81,7 @@ impl Scanner {
|
|||||||
is_image_extension!() => {
|
is_image_extension!() => {
|
||||||
if poster_file_name.is_some() {
|
if poster_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicatePosterFile),
|
event: Err(Error::DuplicatePosterFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -122,7 +93,7 @@ impl Scanner {
|
|||||||
}
|
}
|
||||||
Some(_) | None => {
|
Some(_) | None => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedFile),
|
event: Err(Error::UnexpectedFile),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -139,17 +110,17 @@ impl Scanner {
|
|||||||
|
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
event: Ok(Self::Season {
|
event: Ok(Self::Season(SeasonScan {
|
||||||
show,
|
show_ref: show_ref.clone(),
|
||||||
season,
|
season,
|
||||||
poster_file_name,
|
poster_file_name,
|
||||||
}),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
for episode_dir in episode_dirs_to_scan {
|
for episode_dir in episode_dirs_to_scan {
|
||||||
let Some(episode_dir_name) = episode_dir.file_name().and_then(OsStr::to_str) else {
|
let Some(episode_dir_name) = episode_dir.file_name().and_then(OsStr::to_str) else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -157,14 +128,14 @@ impl Scanner {
|
|||||||
|
|
||||||
let Some((_, s_e_str)) = episode_dir_name.split_once('S') else {
|
let Some((_, s_e_str)) = episode_dir_name.split_once('S') else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let Some((s_str, e_str)) = s_e_str.split_once('E') else {
|
let Some((s_str, e_str)) = s_e_str.split_once('E') else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -172,14 +143,14 @@ impl Scanner {
|
|||||||
|
|
||||||
let Ok(season_number) = s_str.parse::<SeasonNumber>() else {
|
let Ok(season_number) = s_str.parse::<SeasonNumber>() else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if season_number != season {
|
if season_number != season {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::Inconsistent),
|
event: Err(Error::Inconsistent),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -191,14 +162,14 @@ impl Scanner {
|
|||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
else {
|
else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let Ok(episode_numbers) = EpisodeNumbers::try_from(episode_numbers.as_ref()) else {
|
let Ok(episode_numbers) = EpisodeNumbers::try_from(episode_numbers.as_ref()) else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: episode_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -206,7 +177,7 @@ impl Scanner {
|
|||||||
|
|
||||||
for await event in episode::Scanner::scan_episode(
|
for await event in episode::Scanner::scan_episode(
|
||||||
&episode_dir,
|
&episode_dir,
|
||||||
show,
|
show_ref.clone(),
|
||||||
season_number,
|
season_number,
|
||||||
episode_numbers,
|
episode_numbers,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::ffi::OsStr;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use flix_model::id::{CollectionId, ShowId};
|
use flix_model::id::{CollectionId, ShowId};
|
||||||
use flix_model::numbers::{EpisodeNumbers, SeasonNumber};
|
use flix_model::numbers::SeasonNumber;
|
||||||
|
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
@@ -13,7 +13,7 @@ use tokio_stream::wrappers::ReadDirStream;
|
|||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::macros::is_image_extension;
|
use crate::macros::is_image_extension;
|
||||||
use crate::scanner::season;
|
use crate::scanner::{EpisodeScan, MediaRef, SeasonScan, ShowScan, season};
|
||||||
|
|
||||||
/// A show item
|
/// A show item
|
||||||
pub type Item = crate::Item<Scanner>;
|
pub type Item = crate::Item<Scanner>;
|
||||||
@@ -21,63 +21,18 @@ pub type Item = crate::Item<Scanner>;
|
|||||||
/// The scanner for shows
|
/// The scanner for shows
|
||||||
pub enum Scanner {
|
pub enum Scanner {
|
||||||
/// A scanned show
|
/// A scanned show
|
||||||
Show {
|
Show(ShowScan),
|
||||||
/// The ID of the parent collection (if any)
|
/// A scanned season
|
||||||
parent: Option<CollectionId>,
|
Season(SeasonScan),
|
||||||
/// The ID of the show
|
|
||||||
id: ShowId,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
/// A scanned episode
|
||||||
Season {
|
Episode(EpisodeScan),
|
||||||
/// The ID of the show this season belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
/// A scanned episode
|
|
||||||
Episode {
|
|
||||||
/// The ID of the show this episode belongs to
|
|
||||||
show: ShowId,
|
|
||||||
/// The season this episode belongs to
|
|
||||||
season: SeasonNumber,
|
|
||||||
/// The number(s) of this episode
|
|
||||||
episode: EpisodeNumbers,
|
|
||||||
/// The file name of the media file
|
|
||||||
media_file_name: String,
|
|
||||||
/// The file name of the poster file
|
|
||||||
poster_file_name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<season::Scanner> for Scanner {
|
impl From<season::Scanner> for Scanner {
|
||||||
fn from(value: season::Scanner) -> Self {
|
fn from(value: season::Scanner) -> Self {
|
||||||
match value {
|
match value {
|
||||||
season::Scanner::Season {
|
season::Scanner::Season(s) => Self::Season(s),
|
||||||
show,
|
season::Scanner::Episode(e) => Self::Episode(e),
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Season {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
season::Scanner::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
} => Self::Episode {
|
|
||||||
show,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
media_file_name,
|
|
||||||
poster_file_name,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,8 +41,8 @@ impl Scanner {
|
|||||||
/// Scan a folder for a show and its seasons/episodes
|
/// Scan a folder for a show and its seasons/episodes
|
||||||
pub fn scan_show(
|
pub fn scan_show(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
parent: Option<CollectionId>,
|
parent_ref: Option<MediaRef<CollectionId>>,
|
||||||
id: ShowId,
|
id_ref: MediaRef<ShowId>,
|
||||||
) -> impl Stream<Item = Item> {
|
) -> impl Stream<Item = Item> {
|
||||||
stream!({
|
stream!({
|
||||||
let dirs = match fs::read_dir(path).await {
|
let dirs = match fs::read_dir(path).await {
|
||||||
@@ -107,18 +62,19 @@ impl Scanner {
|
|||||||
for await dir in ReadDirStream::new(dirs) {
|
for await dir in ReadDirStream::new(dirs) {
|
||||||
match dir {
|
match dir {
|
||||||
Ok(dir) => {
|
Ok(dir) => {
|
||||||
|
let path = dir.path();
|
||||||
|
|
||||||
let filetype = match dir.file_type().await {
|
let filetype = match dir.file_type().await {
|
||||||
Ok(filetype) => filetype,
|
Ok(filetype) => filetype,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::FileType(err)),
|
event: Err(Error::FileType(err)),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = dir.path();
|
|
||||||
if filetype.is_dir() {
|
if filetype.is_dir() {
|
||||||
season_dirs_to_scan.push(path);
|
season_dirs_to_scan.push(path);
|
||||||
continue;
|
continue;
|
||||||
@@ -128,7 +84,7 @@ impl Scanner {
|
|||||||
is_image_extension!() => {
|
is_image_extension!() => {
|
||||||
if poster_file_name.is_some() {
|
if poster_file_name.is_some() {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::DuplicatePosterFile),
|
event: Err(Error::DuplicatePosterFile),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -140,7 +96,7 @@ impl Scanner {
|
|||||||
}
|
}
|
||||||
Some(_) | None => {
|
Some(_) | None => {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path,
|
||||||
event: Err(Error::UnexpectedFile),
|
event: Err(Error::UnexpectedFile),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -157,17 +113,17 @@ impl Scanner {
|
|||||||
|
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: path.to_owned(),
|
||||||
event: Ok(Self::Show {
|
event: Ok(Self::Show(ShowScan {
|
||||||
parent,
|
parent_ref,
|
||||||
id,
|
id_ref: id_ref.clone(),
|
||||||
poster_file_name,
|
poster_file_name,
|
||||||
}),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
for season_dir in season_dirs_to_scan {
|
for season_dir in season_dirs_to_scan {
|
||||||
let Some(season_dir_name) = season_dir.file_name().and_then(OsStr::to_str) else {
|
let Some(season_dir_name) = season_dir.file_name().and_then(OsStr::to_str) else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: season_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
@@ -178,13 +134,15 @@ impl Scanner {
|
|||||||
.map(|(_, s)| s.parse::<SeasonNumber>())
|
.map(|(_, s)| s.parse::<SeasonNumber>())
|
||||||
else {
|
else {
|
||||||
yield Item {
|
yield Item {
|
||||||
path: path.to_owned(),
|
path: season_dir,
|
||||||
event: Err(Error::UnexpectedFolder),
|
event: Err(Error::UnexpectedFolder),
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
for await event in season::Scanner::scan_season(&season_dir, id, season_number) {
|
for await event in
|
||||||
|
season::Scanner::scan_season(&season_dir, id_ref.clone(), season_number)
|
||||||
|
{
|
||||||
yield event.map(|e| e.into());
|
yield event.map(|e| e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-14
@@ -1,29 +1,26 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-model"
|
name = "flix-model"
|
||||||
version = "0.0.12"
|
version = "0.0.17"
|
||||||
|
edition.workspace = true
|
||||||
categories = []
|
rust-version.workspace = true
|
||||||
description = "Core types for flix data"
|
description = "Core types for flix data"
|
||||||
repository = "https://github.com/QuantumShade/flix"
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
rust-version.workspace = true
|
categories = []
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[lints]
|
[dependencies]
|
||||||
workspace = true
|
itertools = { workspace = true }
|
||||||
|
seamantic = { workspace = true }
|
||||||
|
serde = { workspace = true, features = ["derive", "std"], optional = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
serde = ["dep:serde"]
|
serde = ["dep:serde"]
|
||||||
|
|
||||||
[dependencies]
|
[lints]
|
||||||
seamantic = { workspace = true }
|
workspace = true
|
||||||
|
|
||||||
serde = { workspace = true, optional = true, features = ["std", "derive"] }
|
|
||||||
thiserror = { workspace = true }
|
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
|
|
||||||
pub mod id;
|
pub mod id;
|
||||||
pub mod numbers;
|
pub mod numbers;
|
||||||
|
pub mod text;
|
||||||
|
|||||||
@@ -1,12 +1,76 @@
|
|||||||
//! This module contains season and episode numbers and related errors
|
//! This module contains season and episode numbers and related errors
|
||||||
|
|
||||||
|
use core::fmt;
|
||||||
use core::ops::RangeInclusive;
|
use core::ops::RangeInclusive;
|
||||||
|
use core::str::FromStr;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
/// Type alias for representing season numbers
|
use seamantic::sea_orm;
|
||||||
pub type SeasonNumber = u32;
|
|
||||||
/// Type alias for representing episode numbers
|
/// Newtype for representing season numbers
|
||||||
pub type EpisodeNumber = u32;
|
#[derive(
|
||||||
|
Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, sea_orm::DeriveValueType,
|
||||||
|
)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct SeasonNumber(u32);
|
||||||
|
|
||||||
|
impl SeasonNumber {
|
||||||
|
/// Create a `SeasonNumber` from an integer
|
||||||
|
pub fn new(value: u32) -> Self {
|
||||||
|
Self(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for SeasonNumber {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for SeasonNumber {
|
||||||
|
type Err = <u32 as FromStr>::Err;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
u32::from_str(s).map(Self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Newtype for representing episode numbers
|
||||||
|
#[derive(
|
||||||
|
Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, sea_orm::DeriveValueType,
|
||||||
|
)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct EpisodeNumber(u32);
|
||||||
|
|
||||||
|
impl EpisodeNumber {
|
||||||
|
/// Create an `EpisodeNumber` from an integer
|
||||||
|
pub fn new(value: u32) -> Self {
|
||||||
|
Self(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the underlying value
|
||||||
|
pub fn into_inner(self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for EpisodeNumber {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for EpisodeNumber {
|
||||||
|
type Err = <u32 as FromStr>::Err;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
u32::from_str(s).map(Self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Potential errors when building EpisodeNumbers
|
/// Potential errors when building EpisodeNumbers
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
@@ -20,7 +84,7 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper for handling single and multi-episode entries
|
/// A wrapper for handling single and multi-episode entries
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct EpisodeNumbers(RangeInclusive<EpisodeNumber>);
|
pub struct EpisodeNumbers(RangeInclusive<EpisodeNumber>);
|
||||||
|
|
||||||
@@ -37,7 +101,7 @@ impl TryFrom<&[EpisodeNumber]> for EpisodeNumbers {
|
|||||||
let max = value.iter().copied().max().unwrap_or_default();
|
let max = value.iter().copied().max().unwrap_or_default();
|
||||||
let len = value.len();
|
let len = value.len();
|
||||||
|
|
||||||
if usize::try_from(max.saturating_sub(min).saturating_add(1)) != Ok(len) {
|
if usize::try_from(max.0.saturating_sub(min.0).saturating_add(1)) != Ok(len) {
|
||||||
return Err(Error::Noncontiguous);
|
return Err(Error::Noncontiguous);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,8 +117,27 @@ impl TryFrom<&[EpisodeNumber]> for EpisodeNumbers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeNumbers {
|
impl EpisodeNumbers {
|
||||||
|
/// Create an [EpisodeNumbers] from a starting number and a count.
|
||||||
|
/// `count` should be zero for single episodes.
|
||||||
|
pub fn new(start: EpisodeNumber, count: u8) -> Self {
|
||||||
|
Self(start..=EpisodeNumber(start.0.saturating_add(count.into())))
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the range of episodes
|
/// Get the range of episodes
|
||||||
pub fn as_range(&self) -> &RangeInclusive<EpisodeNumber> {
|
pub fn as_range(&self) -> &RangeInclusive<EpisodeNumber> {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render this [EpisodeNumbers] as a range. If only one episode is
|
||||||
|
/// is present it renders as `01`, if multiple it renders as `01-02`
|
||||||
|
pub fn range_string(&self) -> String {
|
||||||
|
let start = self.0.start();
|
||||||
|
let end = self.0.end();
|
||||||
|
|
||||||
|
if start == end {
|
||||||
|
format!("{:02}", start)
|
||||||
|
} else {
|
||||||
|
format!("{:02}-{:02}", start, end)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
//! This module contains helper functions for normalizing media titles
|
||||||
|
|
||||||
|
use core::iter::Peekable;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `input` is not ASCII.
|
||||||
|
fn split_normalized_words(input: &str) -> impl Iterator<Item = String> {
|
||||||
|
if !input.is_ascii() {
|
||||||
|
panic!("Input is not ASCII: {input}");
|
||||||
|
}
|
||||||
|
|
||||||
|
input.split_ascii_whitespace().map(|s| {
|
||||||
|
let chars = s
|
||||||
|
.chars()
|
||||||
|
.filter(|c| c.is_ascii_alphanumeric() || *c == '-')
|
||||||
|
.map(|c| c.to_ascii_lowercase());
|
||||||
|
|
||||||
|
if s.len() > 4
|
||||||
|
&& s.len().is_multiple_of(2)
|
||||||
|
&& chars.clone().tuples().all(|(l, r)| l != '.' && r == '.')
|
||||||
|
{
|
||||||
|
// Collapse acronym
|
||||||
|
chars.tuples().map(|(l, _)| l).collect()
|
||||||
|
} else {
|
||||||
|
chars.collect()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn split_leading_article<I: Iterator<Item = String>>(iter: I) -> (Option<String>, Peekable<I>) {
|
||||||
|
let mut iter = iter.peekable();
|
||||||
|
match iter.peek().map(String::as_str) {
|
||||||
|
Some("a" | "an" | "the") => (iter.next(), iter),
|
||||||
|
_ => (None, iter),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a media title to be sortable and searchable
|
||||||
|
///
|
||||||
|
/// use flix_model::text::make_sortable_title;
|
||||||
|
///
|
||||||
|
/// assert_eq!(make_sortable_title("The Matrix"), "matrix, the");
|
||||||
|
/// assert_eq!(make_sortable_title("Marvel's Agents of S.H.I.E.L.D."), "marvels agents of shield");
|
||||||
|
/// assert_eq!(make_sortable_title("Avatar: The Last Airbender"), "avatar the last airbender");
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `input` is not ASCII.
|
||||||
|
pub fn make_sortable_title(title: &str) -> String {
|
||||||
|
let words = split_normalized_words(title);
|
||||||
|
let (article, words) = split_leading_article(words);
|
||||||
|
|
||||||
|
let output = Itertools::intersperse(words, " ".to_string());
|
||||||
|
if let Some(article) = article {
|
||||||
|
output.chain([", ".to_string(), article]).collect()
|
||||||
|
} else {
|
||||||
|
output.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a media title to a folder name representable on filesystems
|
||||||
|
///
|
||||||
|
/// use flix_model::text::make_fs_slug;
|
||||||
|
///
|
||||||
|
/// assert_eq!(make_fs_slug("The Matrix"), "matrix");
|
||||||
|
/// assert_eq!(make_fs_slug("Marvel's Agents of S.H.I.E.L.D."), "marvels agents of shield");
|
||||||
|
/// assert_eq!(make_fs_slug("Avatar: The Last Airbender"), "avatar the last airbender");
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `input` is not ASCII.
|
||||||
|
pub fn make_fs_slug(title: &str) -> String {
|
||||||
|
let words = split_normalized_words(title);
|
||||||
|
let (_, words) = split_leading_article(words);
|
||||||
|
|
||||||
|
Itertools::intersperse(words, " ".to_string()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a media title and year to a folder name representable on filesystems
|
||||||
|
///
|
||||||
|
/// use flix_model::text::make_fs_slug_year;
|
||||||
|
///
|
||||||
|
/// assert_eq!(make_fs_slug_year("The Matrix", 1999), "matrix (1999)");
|
||||||
|
/// assert_eq!(make_fs_slug_year("Marvel's Agents of S.H.I.E.L.D.", 2013), "marvels agents of shield (2013)");
|
||||||
|
/// assert_eq!(make_fs_slug_year("Avatar: The Last Airbender", 2005), "avatar the last airbender (2005)");
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `input` is not ASCII.
|
||||||
|
pub fn make_fs_slug_year(title: &str, year: i32) -> String {
|
||||||
|
let words = split_normalized_words(title);
|
||||||
|
let (_, words) = split_leading_article(words);
|
||||||
|
|
||||||
|
Itertools::intersperse(words, " ".to_string())
|
||||||
|
.chain([format!(" ({year})")])
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Normalize a filesystem name
|
||||||
|
///
|
||||||
|
/// use flix_model::text::normalize_fs_name;
|
||||||
|
///
|
||||||
|
/// assert_eq!(normalize_fs_name("Matrix (1999)"), "matrix (1999)");
|
||||||
|
/// assert_eq!(normalize_fs_name("Marvel's Agents of SHIELD (2013)"), "marvels agents of shield (2013)");
|
||||||
|
/// assert_eq!(normalize_fs_name("Avatar The Last Airbender (2005)"), "avatar the last airbender (2005)");
|
||||||
|
pub fn normalize_fs_name(input: &str) -> String {
|
||||||
|
let chars = input.split_ascii_whitespace().map(|s| {
|
||||||
|
let chars = s
|
||||||
|
.chars()
|
||||||
|
.filter(|c| c.is_ascii_alphanumeric() || *c == '-' || *c == '(' || *c == ')')
|
||||||
|
.map(|c| c.to_ascii_lowercase());
|
||||||
|
|
||||||
|
if s.len() > 4
|
||||||
|
&& s.len().is_multiple_of(2)
|
||||||
|
&& chars.clone().tuples().all(|(l, r)| l != '.' && r == '.')
|
||||||
|
{
|
||||||
|
// Collapse acronym
|
||||||
|
chars.tuples().map(|(l, _)| l).collect()
|
||||||
|
} else {
|
||||||
|
chars.collect()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Itertools::intersperse(chars, " ".to_string()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a media title to a url compatible string
|
||||||
|
///
|
||||||
|
/// use flix_model::text::make_web_slug;
|
||||||
|
///
|
||||||
|
/// assert_eq!(make_web_slug("The Matrix"), "matrix");
|
||||||
|
/// assert_eq!(make_web_slug("Marvel's Agents of S.H.I.E.L.D."), "marvels-agents-of-shield");
|
||||||
|
/// assert_eq!(make_web_slug("Avatar: The Last Airbender"), "avatar-the-last-airbender");
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `input` is not ASCII.
|
||||||
|
pub fn make_web_slug(title: &str) -> String {
|
||||||
|
let words = split_normalized_words(title);
|
||||||
|
let (_, words) = split_leading_article(words);
|
||||||
|
|
||||||
|
Itertools::intersperse(words, "-".to_string()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a media title and year to a url compatible string
|
||||||
|
///
|
||||||
|
/// use flix_model::text::make_web_slug_year;
|
||||||
|
///
|
||||||
|
/// assert_eq!(make_web_slug_year("The Matrix", 1999), "matrix-1999");
|
||||||
|
/// assert_eq!(make_web_slug_year("Marvel's Agents of S.H.I.E.L.D.", 2013), "marvels-agents-of-shield-2013");
|
||||||
|
/// assert_eq!(make_web_slug_year("Avatar: The Last Airbender", 2005), "avatar-the-last-airbender-2005");
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `input` is not ASCII.
|
||||||
|
pub fn make_web_slug_year(title: &str, year: i32) -> String {
|
||||||
|
let words = split_normalized_words(title);
|
||||||
|
let (_, words) = split_leading_article(words);
|
||||||
|
|
||||||
|
Itertools::intersperse(words, "-".to_string())
|
||||||
|
.chain([format!("-{year}")])
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
+23
-25
@@ -1,40 +1,38 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-tmdb"
|
name = "flix-tmdb"
|
||||||
version = "0.0.12"
|
version = "0.0.17"
|
||||||
|
edition.workspace = true
|
||||||
categories = []
|
rust-version.workspace = true
|
||||||
description = "Clients and models for fetching data from TMDB"
|
description = "Clients and models for fetching data from TMDB"
|
||||||
repository = "https://github.com/QuantumShade/flix"
|
repository = "https://github.com/QuantumShade/flix"
|
||||||
|
|
||||||
authors.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license-file.workspace = true
|
license-file.workspace = true
|
||||||
rust-version.workspace = true
|
categories = []
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[lints]
|
[dependencies]
|
||||||
workspace = true
|
bytes = { workspace = true }
|
||||||
|
chrono = { workspace = true, features = ["serde"] }
|
||||||
|
flix-model = { workspace = true, features = ["serde"] }
|
||||||
|
governor = { workspace = true, features = ["jitter", "std"] }
|
||||||
|
nonzero_ext = { workspace = true }
|
||||||
|
redb = { workspace = true }
|
||||||
|
reqwest = { workspace = true, features = ["query", "rustls"] }
|
||||||
|
sea-orm = { workspace = true, optional = true }
|
||||||
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
url = { workspace = true }
|
||||||
|
url-macro = { workspace = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde_test = { workspace = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
sea-orm = ["dep:sea-orm"]
|
sea-orm = ["dep:sea-orm"]
|
||||||
|
|
||||||
[dependencies]
|
[lints]
|
||||||
flix-model = { workspace = true }
|
workspace = true
|
||||||
|
|
||||||
chrono = { workspace = true, features = ["serde"] }
|
|
||||||
governor = { workspace = true, features = ["std", "jitter"] }
|
|
||||||
nonzero_ext = { workspace = true }
|
|
||||||
reqwest = { workspace = true, features = ["json", "rustls-tls"] }
|
|
||||||
serde = { workspace = true, features = ["derive"] }
|
|
||||||
thiserror = { workspace = true }
|
|
||||||
url = { workspace = true }
|
|
||||||
url-macro = { workspace = true }
|
|
||||||
|
|
||||||
sea-orm = { workspace = true, optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
serde_test = { workspace = true }
|
|
||||||
|
|||||||
@@ -1,25 +1,30 @@
|
|||||||
//! Collections API
|
//! Collections API
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use governor::Jitter;
|
use crate::api::exec_request;
|
||||||
|
|
||||||
use crate::Config;
|
|
||||||
use crate::model::Collection;
|
use crate::model::Collection;
|
||||||
use crate::model::id::CollectionId;
|
use crate::model::id::CollectionId;
|
||||||
|
use crate::{Cache, CachePolicy, Config};
|
||||||
|
|
||||||
use super::{Error, make_request};
|
use super::{Error, make_request};
|
||||||
|
|
||||||
/// TMDB Collections API client
|
/// TMDB Collections API client
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
config: Rc<Config>,
|
config: Rc<Config>,
|
||||||
|
cache: Rc<dyn Cache>,
|
||||||
|
policy: Rc<RwLock<CachePolicy>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Create a new client with the given configuration
|
/// Create a new client with the given configuration
|
||||||
pub fn new(config: Rc<Config>) -> Self {
|
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
|
||||||
Self { config }
|
Self {
|
||||||
|
config,
|
||||||
|
cache,
|
||||||
|
policy,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,25 +35,11 @@ impl Client {
|
|||||||
id: impl Into<CollectionId>,
|
id: impl Into<CollectionId>,
|
||||||
language: Option<&str>,
|
language: Option<&str>,
|
||||||
) -> Result<Collection, Error> {
|
) -> Result<Collection, Error> {
|
||||||
self.config
|
let request = make_request(
|
||||||
.limiter
|
&self.config,
|
||||||
.until_ready_with_jitter(Jitter::new(
|
&format!("/3/collection/{}", id.into().into_raw()),
|
||||||
Duration::from_millis(0),
|
language,
|
||||||
Duration::from_millis(50),
|
)?;
|
||||||
))
|
exec_request(&self.config, &*self.cache, &self.policy, request).await
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(self
|
|
||||||
.config
|
|
||||||
.client
|
|
||||||
.execute(make_request(
|
|
||||||
&self.config,
|
|
||||||
&format!("/3/collection/{}", id.into().into_raw()),
|
|
||||||
language,
|
|
||||||
)?)
|
|
||||||
.await?
|
|
||||||
.error_for_status()?
|
|
||||||
.json()
|
|
||||||
.await?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,32 @@
|
|||||||
//! Episodes API
|
//! Episodes API
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
||||||
|
|
||||||
use governor::Jitter;
|
use crate::api::exec_request;
|
||||||
|
|
||||||
use crate::Config;
|
|
||||||
use crate::model::Episode;
|
use crate::model::Episode;
|
||||||
use crate::model::id::ShowId;
|
use crate::model::id::ShowId;
|
||||||
|
use crate::{Cache, CachePolicy, Config};
|
||||||
|
|
||||||
use super::{Error, make_request};
|
use super::{Error, make_request};
|
||||||
|
|
||||||
/// TMDB Episodes API client
|
/// TMDB Episodes API client
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
config: Rc<Config>,
|
config: Rc<Config>,
|
||||||
|
cache: Rc<dyn Cache>,
|
||||||
|
policy: Rc<RwLock<CachePolicy>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Create a new client with the given configuration
|
/// Create a new client with the given configuration
|
||||||
pub fn new(config: Rc<Config>) -> Self {
|
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
|
||||||
Self { config }
|
Self {
|
||||||
|
config,
|
||||||
|
cache,
|
||||||
|
policy,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,30 +39,16 @@ impl Client {
|
|||||||
episode: impl Into<EpisodeNumber>,
|
episode: impl Into<EpisodeNumber>,
|
||||||
language: Option<&str>,
|
language: Option<&str>,
|
||||||
) -> Result<Episode, Error> {
|
) -> Result<Episode, Error> {
|
||||||
self.config
|
let request = make_request(
|
||||||
.limiter
|
&self.config,
|
||||||
.until_ready_with_jitter(Jitter::new(
|
&format!(
|
||||||
Duration::from_millis(0),
|
"/3/tv/{}/season/{}/episode/{}",
|
||||||
Duration::from_millis(50),
|
id.into().into_raw(),
|
||||||
))
|
season.into(),
|
||||||
.await;
|
episode.into()
|
||||||
|
),
|
||||||
Ok(self
|
language,
|
||||||
.config
|
)?;
|
||||||
.client
|
exec_request(&self.config, &*self.cache, &self.policy, request).await
|
||||||
.execute(make_request(
|
|
||||||
&self.config,
|
|
||||||
&format!(
|
|
||||||
"/3/tv/{}/season/{}/episode/{}",
|
|
||||||
id.into().into_raw(),
|
|
||||||
season.into(),
|
|
||||||
episode.into()
|
|
||||||
),
|
|
||||||
language,
|
|
||||||
)?)
|
|
||||||
.await?
|
|
||||||
.error_for_status()?
|
|
||||||
.json()
|
|
||||||
.await?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
//! TMDB API clients
|
//! TMDB API clients
|
||||||
|
|
||||||
|
use core::ops::Deref;
|
||||||
|
use core::time::Duration;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
|
use governor::Jitter;
|
||||||
use reqwest::Request;
|
use reqwest::Request;
|
||||||
use reqwest::header;
|
use reqwest::header;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
use crate::Config;
|
use crate::{Cache, CachePolicy, Config};
|
||||||
|
|
||||||
pub mod collections;
|
pub mod collections;
|
||||||
pub mod episodes;
|
pub mod episodes;
|
||||||
@@ -20,6 +26,9 @@ pub enum Error {
|
|||||||
/// Reqwest error wrapper
|
/// Reqwest error wrapper
|
||||||
#[error("reqwest error: {0}")]
|
#[error("reqwest error: {0}")]
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
|
/// Json error wrapper
|
||||||
|
#[error("json error: {0}")]
|
||||||
|
Json(#[from] serde_json::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_request(config: &Config, path: &str, language: Option<&str>) -> Result<Request, Error> {
|
fn make_request(config: &Config, path: &str, language: Option<&str>) -> Result<Request, Error> {
|
||||||
@@ -38,3 +47,58 @@ fn make_request(config: &Config, path: &str, language: Option<&str>) -> Result<R
|
|||||||
|
|
||||||
Ok(builder.build()?)
|
Ok(builder.build()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn exec_request<T: DeserializeOwned>(
|
||||||
|
config: &Config,
|
||||||
|
cache: &dyn Cache,
|
||||||
|
policy: &RwLock<CachePolicy>,
|
||||||
|
request: Request,
|
||||||
|
) -> Result<T, Error> {
|
||||||
|
let (read_cache, write_cache) = if let Ok(guard) = policy.read() {
|
||||||
|
match guard.deref() {
|
||||||
|
CachePolicy::None => (None, None),
|
||||||
|
CachePolicy::Full => (Some(cache), Some(cache)),
|
||||||
|
CachePolicy::Read => (Some(cache), None),
|
||||||
|
CachePolicy::Update => (None, Some(cache)),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
|
};
|
||||||
|
|
||||||
|
let path = request.url().path().to_owned();
|
||||||
|
|
||||||
|
// read the cache and fall back to reqwest
|
||||||
|
let mut response = None;
|
||||||
|
if let Some(cache) = read_cache {
|
||||||
|
response = cache.get(&path);
|
||||||
|
}
|
||||||
|
let needs_cache_write = response.is_none();
|
||||||
|
let response = match response {
|
||||||
|
Some(response) => response,
|
||||||
|
None => {
|
||||||
|
config
|
||||||
|
.limiter
|
||||||
|
.until_ready_with_jitter(Jitter::new(
|
||||||
|
Duration::from_millis(0),
|
||||||
|
Duration::from_millis(50),
|
||||||
|
))
|
||||||
|
.await;
|
||||||
|
config
|
||||||
|
.client
|
||||||
|
.execute(request)
|
||||||
|
.await?
|
||||||
|
.error_for_status()?
|
||||||
|
.bytes()
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// write to the cache if needed
|
||||||
|
if let Some(cache) = write_cache
|
||||||
|
&& needs_cache_write
|
||||||
|
{
|
||||||
|
cache.set(&path, &response);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(serde_json::from_slice(&response)?)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,25 +1,30 @@
|
|||||||
//! Movies API
|
//! Movies API
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use governor::Jitter;
|
use crate::api::exec_request;
|
||||||
|
|
||||||
use crate::Config;
|
|
||||||
use crate::model::Movie;
|
use crate::model::Movie;
|
||||||
use crate::model::id::MovieId;
|
use crate::model::id::MovieId;
|
||||||
|
use crate::{Cache, CachePolicy, Config};
|
||||||
|
|
||||||
use super::{Error, make_request};
|
use super::{Error, make_request};
|
||||||
|
|
||||||
/// TMDB Movies API client
|
/// TMDB Movies API client
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
config: Rc<Config>,
|
config: Rc<Config>,
|
||||||
|
cache: Rc<dyn Cache>,
|
||||||
|
policy: Rc<RwLock<CachePolicy>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Create a new client with the given configuration
|
/// Create a new client with the given configuration
|
||||||
pub fn new(config: Rc<Config>) -> Self {
|
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
|
||||||
Self { config }
|
Self {
|
||||||
|
config,
|
||||||
|
cache,
|
||||||
|
policy,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,25 +35,11 @@ impl Client {
|
|||||||
id: impl Into<MovieId>,
|
id: impl Into<MovieId>,
|
||||||
language: Option<&str>,
|
language: Option<&str>,
|
||||||
) -> Result<Movie, Error> {
|
) -> Result<Movie, Error> {
|
||||||
self.config
|
let request = make_request(
|
||||||
.limiter
|
&self.config,
|
||||||
.until_ready_with_jitter(Jitter::new(
|
&format!("/3/movie/{}", id.into().into_raw()),
|
||||||
Duration::from_millis(0),
|
language,
|
||||||
Duration::from_millis(50),
|
)?;
|
||||||
))
|
exec_request(&self.config, &*self.cache, &self.policy, request).await
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(self
|
|
||||||
.config
|
|
||||||
.client
|
|
||||||
.execute(make_request(
|
|
||||||
&self.config,
|
|
||||||
&format!("/3/movie/{}", id.into().into_raw()),
|
|
||||||
language,
|
|
||||||
)?)
|
|
||||||
.await?
|
|
||||||
.error_for_status()?
|
|
||||||
.json()
|
|
||||||
.await?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,32 @@
|
|||||||
//! Seasons API
|
//! Seasons API
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use flix_model::numbers::SeasonNumber;
|
use flix_model::numbers::SeasonNumber;
|
||||||
|
|
||||||
use governor::Jitter;
|
use crate::api::exec_request;
|
||||||
|
|
||||||
use crate::Config;
|
|
||||||
use crate::model::Season;
|
use crate::model::Season;
|
||||||
use crate::model::id::ShowId;
|
use crate::model::id::ShowId;
|
||||||
|
use crate::{Cache, CachePolicy, Config};
|
||||||
|
|
||||||
use super::{Error, make_request};
|
use super::{Error, make_request};
|
||||||
|
|
||||||
/// TMDB Seasons API client
|
/// TMDB Seasons API client
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
config: Rc<Config>,
|
config: Rc<Config>,
|
||||||
|
cache: Rc<dyn Cache>,
|
||||||
|
policy: Rc<RwLock<CachePolicy>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Create a new client with the given configuration
|
/// Create a new client with the given configuration
|
||||||
pub fn new(config: Rc<Config>) -> Self {
|
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
|
||||||
Self { config }
|
Self {
|
||||||
|
config,
|
||||||
|
cache,
|
||||||
|
policy,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,25 +38,11 @@ impl Client {
|
|||||||
season: impl Into<SeasonNumber>,
|
season: impl Into<SeasonNumber>,
|
||||||
language: Option<&str>,
|
language: Option<&str>,
|
||||||
) -> Result<Season, Error> {
|
) -> Result<Season, Error> {
|
||||||
self.config
|
let request = make_request(
|
||||||
.limiter
|
&self.config,
|
||||||
.until_ready_with_jitter(Jitter::new(
|
&format!("/3/tv/{}/season/{}", id.into().into_raw(), season.into()),
|
||||||
Duration::from_millis(0),
|
language,
|
||||||
Duration::from_millis(50),
|
)?;
|
||||||
))
|
exec_request(&self.config, &*self.cache, &self.policy, request).await
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(self
|
|
||||||
.config
|
|
||||||
.client
|
|
||||||
.execute(make_request(
|
|
||||||
&self.config,
|
|
||||||
&format!("/3/tv/{}/season/{}", id.into().into_raw(), season.into()),
|
|
||||||
language,
|
|
||||||
)?)
|
|
||||||
.await?
|
|
||||||
.error_for_status()?
|
|
||||||
.json()
|
|
||||||
.await?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,30 @@
|
|||||||
//! Shows API
|
//! Shows API
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use governor::Jitter;
|
use crate::api::exec_request;
|
||||||
|
|
||||||
use crate::Config;
|
|
||||||
use crate::model::Show;
|
use crate::model::Show;
|
||||||
use crate::model::id::ShowId;
|
use crate::model::id::ShowId;
|
||||||
|
use crate::{Cache, CachePolicy, Config};
|
||||||
|
|
||||||
use super::{Error, make_request};
|
use super::{Error, make_request};
|
||||||
|
|
||||||
/// TMDB Shows API client
|
/// TMDB Shows API client
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
config: Rc<Config>,
|
config: Rc<Config>,
|
||||||
|
cache: Rc<dyn Cache>,
|
||||||
|
policy: Rc<RwLock<CachePolicy>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Create a new client with the given configuration
|
/// Create a new client with the given configuration
|
||||||
pub fn new(config: Rc<Config>) -> Self {
|
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
|
||||||
Self { config }
|
Self {
|
||||||
|
config,
|
||||||
|
cache,
|
||||||
|
policy,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,25 +35,11 @@ impl Client {
|
|||||||
id: impl Into<ShowId>,
|
id: impl Into<ShowId>,
|
||||||
language: Option<&str>,
|
language: Option<&str>,
|
||||||
) -> Result<Show, Error> {
|
) -> Result<Show, Error> {
|
||||||
self.config
|
let request = make_request(
|
||||||
.limiter
|
&self.config,
|
||||||
.until_ready_with_jitter(Jitter::new(
|
&format!("/3/tv/{}", id.into().into_raw()),
|
||||||
Duration::from_millis(0),
|
language,
|
||||||
Duration::from_millis(50),
|
)?;
|
||||||
))
|
exec_request(&self.config, &*self.cache, &self.policy, request).await
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(self
|
|
||||||
.config
|
|
||||||
.client
|
|
||||||
.execute(make_request(
|
|
||||||
&self.config,
|
|
||||||
&format!("/3/tv/{}", id.into().into_raw()),
|
|
||||||
language,
|
|
||||||
)?)
|
|
||||||
.await?
|
|
||||||
.error_for_status()?
|
|
||||||
.json()
|
|
||||||
.await?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use bytes::Bytes;
|
||||||
|
use redb::{Database, DatabaseError, ReadableDatabase, TableDefinition};
|
||||||
|
|
||||||
|
/// The client cache policy
|
||||||
|
pub enum CachePolicy {
|
||||||
|
/// Do not use a cache
|
||||||
|
None,
|
||||||
|
/// Use and update the cache
|
||||||
|
Full,
|
||||||
|
/// Use the cache but don't update it
|
||||||
|
Read,
|
||||||
|
/// Ignore the cache but update it
|
||||||
|
Update,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The trait representing a caching backend
|
||||||
|
pub trait Cache {
|
||||||
|
/// Get a cached value, or None
|
||||||
|
fn get(&self, query: &str) -> Option<Bytes>;
|
||||||
|
/// Set a value in the cache
|
||||||
|
fn set(&self, query: &str, response: &Bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
const TABLE: TableDefinition<&str, (u64, &[u8])> = TableDefinition::new("tmdb_responses");
|
||||||
|
|
||||||
|
/// A [Cache] implementation using [redb] as the backend
|
||||||
|
pub struct RedbCache {
|
||||||
|
db: Database,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RedbCache {
|
||||||
|
/// Create/open a [redb] database at the path
|
||||||
|
pub fn new(path: &Path) -> Result<Self, DatabaseError> {
|
||||||
|
Ok(Self {
|
||||||
|
db: Database::create(path)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper function allowing for `.ok()?`
|
||||||
|
fn write(&self, timestamp: u64, query: &str, response: &Bytes) -> Option<()> {
|
||||||
|
let write_txn = self.db.begin_write().ok()?;
|
||||||
|
{
|
||||||
|
let mut table = write_txn.open_table(TABLE).ok()?;
|
||||||
|
table
|
||||||
|
.insert(query, (timestamp, response.iter().as_slice()))
|
||||||
|
.ok()?;
|
||||||
|
}
|
||||||
|
write_txn.commit().ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cache for RedbCache {
|
||||||
|
fn get(&self, query: &str) -> Option<Bytes> {
|
||||||
|
let read_txn = self.db.begin_read().ok()?;
|
||||||
|
let table = read_txn.open_table(TABLE).ok()?;
|
||||||
|
|
||||||
|
let result = table.get(query).ok()??;
|
||||||
|
let (timestamp, data) = result.value();
|
||||||
|
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_secs())
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
if now.saturating_sub(timestamp) >= 60 * 60 * 24 * 30 * 6 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(Bytes::copy_from_slice(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set(&self, query: &str, response: &Bytes) {
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_secs())
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
self.write(now, query, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
-13
@@ -1,6 +1,7 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use crate::{Config, api};
|
use crate::{Cache, CachePolicy, Config, api};
|
||||||
|
|
||||||
/// The primary client that references all other clients
|
/// The primary client that references all other clients
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
@@ -9,23 +10,42 @@ pub struct Client {
|
|||||||
shows: api::shows::Client,
|
shows: api::shows::Client,
|
||||||
seasons: api::seasons::Client,
|
seasons: api::seasons::Client,
|
||||||
episodes: api::episodes::Client,
|
episodes: api::episodes::Client,
|
||||||
|
|
||||||
|
cache_policy: Rc<RwLock<CachePolicy>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Create a new client from a default configuration using the bearer token
|
/// Create a new client with the given configuration
|
||||||
pub fn new(bearer_token: String) -> Self {
|
pub fn new(config: Config, cache: Rc<dyn Cache>, cache_policy: CachePolicy) -> Self {
|
||||||
Self::new_with_config(Config::new(bearer_token))
|
let config = Rc::new(config);
|
||||||
|
let cache_policy = Rc::new(RwLock::new(cache_policy));
|
||||||
|
Self {
|
||||||
|
collections: api::collections::Client::new(
|
||||||
|
config.clone(),
|
||||||
|
cache.clone(),
|
||||||
|
cache_policy.clone(),
|
||||||
|
),
|
||||||
|
movies: api::movies::Client::new(config.clone(), cache.clone(), cache_policy.clone()),
|
||||||
|
shows: api::shows::Client::new(config.clone(), cache.clone(), cache_policy.clone()),
|
||||||
|
seasons: api::seasons::Client::new(config.clone(), cache.clone(), cache_policy.clone()),
|
||||||
|
episodes: api::episodes::Client::new(
|
||||||
|
config.clone(),
|
||||||
|
cache.clone(),
|
||||||
|
cache_policy.clone(),
|
||||||
|
),
|
||||||
|
|
||||||
|
cache_policy,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new client with the given configuration
|
/// Modify the [CachePolicy]
|
||||||
pub fn new_with_config(config: Config) -> Self {
|
pub fn set_cache_policy(&self, new_policy: CachePolicy) {
|
||||||
let config = Rc::new(config);
|
match self.cache_policy.write() {
|
||||||
Self {
|
Ok(mut policy) => *policy = new_policy,
|
||||||
collections: api::collections::Client::new(config.clone()),
|
Err(mut poison) => {
|
||||||
movies: api::movies::Client::new(config.clone()),
|
**poison.get_mut() = new_policy;
|
||||||
shows: api::shows::Client::new(config.clone()),
|
self.cache_policy.clear_poison();
|
||||||
seasons: api::seasons::Client::new(config.clone()),
|
}
|
||||||
episodes: api::episodes::Client::new(config.clone()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
|
|
||||||
|
mod cache;
|
||||||
|
pub use cache::{Cache, CachePolicy, RedbCache};
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
pub use client::Client;
|
pub use client::Client;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
# Init database
|
||||||
|
rm flix.db
|
||||||
|
cargo run -- init
|
||||||
|
|
||||||
|
|
||||||
|
###############
|
||||||
|
# Collections #
|
||||||
|
###############
|
||||||
|
|
||||||
|
# DC
|
||||||
|
cargo run -- add flix collection "DC Collection" ""
|
||||||
|
cargo run -- add tmdb show 60708 # Gotham (2014)
|
||||||
|
|
||||||
|
# DCEU
|
||||||
|
cargo run -- add --sort-title "dceu" flix collection "Worlds of DC" "American media franchise and shared universe that is centered on a series of superhero films, distributed by Warner Bros. Pictures and based on characters that appear in American comic books by DC Comics."
|
||||||
|
cargo run -- add tmdb collection 573693 # Aquaman Collection
|
||||||
|
cargo run -- add tmdb movie 297802 # Aquaman (2018)
|
||||||
|
cargo run -- add tmdb movie 572802 # Aquaman and the Lost Kingdom (2023)
|
||||||
|
|
||||||
|
# Marvel
|
||||||
|
cargo run -- add --sort-title "marvel" flix collection "In Association With Marvel" "Movies based on Marvel Comics properties not produced by Marvel Studios"
|
||||||
|
cargo run -- add --fs-slug "cloak and dagger (2018)" --web-slug "cloak-and-dagger-2018" tmdb show 66190 # Marvel's Cloak & Dagger (2018)
|
||||||
|
cargo run -- add --fs-slug "daredevil (2015)" --web-slug "daredevil-2015" tmdb show 61889 # Marvel's Daredevil (2015)
|
||||||
|
cargo run -- add --fs-slug "inhumans (2017)" --web-slug "inhumans-2017" tmdb show 68716 # Marvel's Inhumans (2017)
|
||||||
|
cargo run -- add --fs-slug "iron fist (2017)" --web-slug "iron-fist-2017" tmdb show 62127 # Marvel's Iron Fist (2017)
|
||||||
|
cargo run -- add --fs-slug "jessica jones (2015)" --web-slug "jessica-jones-2015" tmdb show 38472 # Marvel's Jessica Jones (2015)
|
||||||
|
cargo run -- add --fs-slug "luke cage (2016)" --web-slug "luke-cage-2016" tmdb show 62126 # Marvel's Luke Cage (2016)
|
||||||
|
cargo run -- add --fs-slug "runaways (2017)" --web-slug "runaways-2017" tmdb show 67466 # Marvel's Runaways (2017)
|
||||||
|
cargo run -- add --fs-slug "defenders (2017)" --web-slug "defenders-2017" tmdb show 62285 # Marvel's The Defenders (2017)
|
||||||
|
cargo run -- add --fs-slug "punisher (2017)" --web-slug "punisher-2017" tmdb show 67178 # Marvel's The Punisher (2017)
|
||||||
|
|
||||||
|
# Marvel Cinematic Universe
|
||||||
|
cargo run -- add flix collection "Marvel Cinematic Universe" ""
|
||||||
|
cargo run -- add tmdb show 84958 # Loki (2021)
|
||||||
|
cargo run -- add --fs-slug "agent carter (2015)" --web-slug "agent-carter-2015" tmdb show 61550 # Marvel's Agent Carter (2015)
|
||||||
|
cargo run -- add --fs-slug "agents of shield (2013)" --web-slug "agents-of-shield-2013" tmdb show 1403 # Marvel's Agents of S.H.I.E.L.D. (2013)
|
||||||
|
|
||||||
|
# Star Wars
|
||||||
|
cargo run -- add tmdb collection 10 # Star Wars Collection
|
||||||
|
cargo run -- add --title "Star Wars: Episode I - The Phantom Menace" --sort-title "star wars 1 - the phantom menace" --fs-slug "the phantom menace (1999)" --web-slug "star-wars-the-phantom-menace-1999" tmdb movie 1893 # Star Wars: Episode I - The Phantom Menace (1999)
|
||||||
|
cargo run -- add --title "Star Wars: Episode II - Attack of the Clones" --sort-title "star wars 2 - attack of the clones" --fs-slug "attack of the clones (2002)" --web-slug "star-wars-attack-of-the-clones-2002" tmdb movie 1894 # Star Wars: Episode II - Attack of the Clones (2002)
|
||||||
|
cargo run -- add --title "Star Wars: Episode III - Revenge of the Sith" --sort-title "star wars 3 - revenge of the sith" --fs-slug "revenge of the sith (2005)" --web-slug "star-wars-revenge-of-the-sith-2005" tmdb movie 1895 # Star Wars: Episode III - Revenge of the Sith (2005)
|
||||||
|
cargo run -- add --title "Star Wars: Episode IV - A New Hope" --sort-title "star wars 4 - a new hope" --fs-slug "a new hope (1977)" --web-slug "star-wars-a-new-hope-1977" tmdb movie 11 # Star Wars (1977)
|
||||||
|
cargo run -- add --title "Star Wars: Episode V - The Empire Strikes Back" --sort-title "star wars 5 - the empire strikes back" --fs-slug "the empire strikes back (1980)" --web-slug "star-wars-the-empire-strikes-back-1980" tmdb movie 1891 # The Empire Strikes Back (1980)
|
||||||
|
cargo run -- add --title "Star Wars: Episode VI - Return of the Jedi" --sort-title "star wars 6 - return of the jedi" --fs-slug "return of the jedi (1983)" --web-slug "star-wars-return-of-the-jedi-1983" tmdb movie 1892 # Return of the Jedi (1983)
|
||||||
|
cargo run -- add --title "Star Wars: Episode VII - The Force Awakens" --sort-title "star wars 7 - the force awakens" --fs-slug "the force awakens (2015)" --web-slug "star-wars-the-force-awakens-2015" tmdb movie 140607 # Star Wars: The Force Awakens (2015)
|
||||||
|
cargo run -- add --title "Star Wars: Episode VIII - The Last Jedi" --sort-title "star wars 8 - the last jedi" --fs-slug "the last jedi (2017)" --web-slug "star-wars-the-last-jedi-2017" tmdb movie 181808 # Star Wars: The Last Jedi (2017)
|
||||||
|
cargo run -- add --title "Star Wars: Episode IX - The Rise of Skywalker" --sort-title "star wars 9 - the rise of skywalker" --fs-slug "the rise of skywalker (2019)" --web-slug "star-wars-the-rise-of-skywalker-2019" tmdb movie 181812 # Star Wars: The Rise of Skywalker (2019)
|
||||||
|
cargo run -- add tmdb show 82856 # The Mandalorian (2019)
|
||||||
|
|
||||||
|
# Twin Peaks
|
||||||
|
cargo run -- add flix collection "Twin Peaks Collection" ""
|
||||||
|
cargo run -- add tmdb show 1920 # Twin Peaks (1990)
|
||||||
|
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# Movie Collections #
|
||||||
|
#####################
|
||||||
|
|
||||||
|
# Disney Live-Action Remakes
|
||||||
|
cargo run -- add flix collection "Disney Live-Action Remakes" "Live-action or photorealistic remakes produced by Walt Disney Pictures of its animated films."
|
||||||
|
cargo run -- add tmdb movie 447273 # Snow White (2025)
|
||||||
|
|
||||||
|
# Happy Gilmore
|
||||||
|
cargo run -- add tmdb collection 1263259 # Happy Gilmore Collection
|
||||||
|
cargo run -- add tmdb movie 9614 # Happy Gilmore (1996)
|
||||||
|
cargo run -- add tmdb movie 1263256 # Happy Gilmore 2 (2025)
|
||||||
|
|
||||||
|
# Minecraft
|
||||||
|
cargo run -- add tmdb collection 1461530 # The Minecraft Movie Collection
|
||||||
|
cargo run -- add tmdb movie 950387 # A Minecraft Movie (2025)
|
||||||
|
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Show Collections #
|
||||||
|
####################
|
||||||
|
|
||||||
|
# Arrowverse
|
||||||
|
cargo run -- add flix collection "Arrowverse" "A television franchise that is based on characters that appear in publications by DC Comics."
|
||||||
|
cargo run -- add tmdb show 1412 # Arrow (2012)
|
||||||
|
cargo run -- add tmdb show 89247 # Batwoman (2019)
|
||||||
|
cargo run -- add tmdb show 71663 # Black Lightning (2018)
|
||||||
|
cargo run -- add tmdb show 60735 # The Flash (2014)
|
||||||
|
cargo run -- add --fs-slug "legends of tomorrow (2016)" --web-slug "legends-of-tomorrow-2016" tmdb show 62643
|
||||||
|
cargo run -- add tmdb show 62688 # Supergirl (2015)
|
||||||
|
|
||||||
|
# Avatar Universe
|
||||||
|
cargo run -- add flix collection "Avatar Universe" "Avatar: The Last Airbender is set in an Asiatic-like world in which some people can manipulate the classical elements with psychokinetic variants of the Chinese martial arts known as 'bending'."
|
||||||
|
cargo run -- add tmdb show 246 # Avatar: The Last Airbender (2005)
|
||||||
|
cargo run -- add tmdb show 33880 # The Legend of Korra (2012)
|
||||||
|
|
||||||
|
# Breaking Bad
|
||||||
|
cargo run -- add flix collection "Breaking Bad Collection" "Collection containing the original Breaking Bad show along with a documentary chronicling the process of making the final season, a sequel movie and prequel show."
|
||||||
|
cargo run -- add tmdb show 1396 # Breaking Bad (2008)
|
||||||
|
|
||||||
|
# Buffyverse
|
||||||
|
cargo run -- add flix collection "Buffyverse" "The Buffyverse is a setting in which supernatural phenomena exist, and supernatural evil can be challenged by people willing to fight against such forces."
|
||||||
|
cargo run -- add tmdb show 2426 # Angel (1999)
|
||||||
|
cargo run -- add tmdb show 95 # Buffy the Vampire Slayer (1997)
|
||||||
|
|
||||||
|
|
||||||
|
##########
|
||||||
|
# Movies #
|
||||||
|
##########
|
||||||
|
cargo run -- add tmdb movie 940551 # Migration (2023)
|
||||||
|
|
||||||
|
|
||||||
|
#########
|
||||||
|
# Shows #
|
||||||
|
#########
|
||||||
|
cargo run -- add tmdb show 62110 # Assassination Classroom (2015)
|
||||||
|
cargo run -- add tmdb show 1429 # Attack on Titan (2013)
|
||||||
|
cargo run -- add tmdb show 42009 # Black Mirror (2011)
|
||||||
|
cargo run -- add tmdb show 1911 # Bones (2005)
|
||||||
|
cargo run -- add tmdb show 48891 # Brooklyn Nine-Nine (2013)
|
||||||
|
cargo run -- add flix episode "brooklyn-nine-nine-2013" 8 10 "The Last Day (Part 2)" "The squad takes stock of its eight years together and looks toward the future." "2021-09-16"
|
||||||
|
cargo run -- add tmdb show 3787 # Chaotic (2006)
|
||||||
|
cargo run -- add tmdb show 2557 # Class of the Titans (2006)
|
||||||
|
cargo run -- add tmdb show 13916 # Death Note (2006)
|
||||||
|
cargo run -- add tmdb show 1405 # Dexter (2006)
|
||||||
|
cargo run -- add tmdb show 1399 # Game of Thrones (2011)
|
||||||
|
cargo run -- add tmdb show 40075 # Gravity Falls (2012)
|
||||||
|
cargo run -- add tmdb show 1639 # Heroes (2006)
|
||||||
|
cargo run -- add tmdb show 60858 # Heroes Reborn (2015)
|
||||||
|
cargo run -- add tmdb show 71340 # Krypton (2018)
|
||||||
|
cargo run -- add tmdb show 62687 # Limitless (2015)
|
||||||
|
cargo run -- add tmdb show 60846 # Log Horizon (2013)
|
||||||
|
cargo run -- add tmdb show 64432 # The Magicians (2015)
|
||||||
|
cargo run -- add tmdb show 5920 # The Mentalist (2008)
|
||||||
|
cargo run -- add tmdb show 12786 # Murdoch Mysteries (2008)
|
||||||
|
cargo run -- add tmdb show 65930 # My Hero Academia (2016)
|
||||||
|
cargo run -- add tmdb show 2288 # Prison Break (2005)
|
||||||
|
cargo run -- add tmdb show 95396 # Severance (2022)
|
||||||
|
cargo run -- add tmdb show 60573 # Silicon Valley (2014)
|
||||||
|
cargo run -- add tmdb show 37680 # Suits (2011)
|
||||||
|
cargo run -- add tmdb show 45782 # Sword Art Online (2012)
|
||||||
|
cargo run -- add tmdb show 48860 # The Tomorrow People (2013)
|
||||||
|
cargo run -- add tmdb show 46331 # Under the Dome (2013)
|
||||||
|
cargo run -- add tmdb show 1432 # Veronica Mars (2004)
|
||||||
|
cargo run -- add tmdb show 186 # Weeds (2005)
|
||||||
|
cargo run -- add tmdb show 63247 # Westworld (2016)
|
||||||
|
cargo run -- add tmdb show 71912 # The Witcher (2019)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
toml-version = "v1.0.0"
|
||||||
|
|
||||||
|
[format.rules]
|
||||||
|
indent-style = "tab"
|
||||||
|
indent-width = 4
|
||||||
Reference in New Issue
Block a user