Files
Jellymove/crates/jm-server/examples/demo.rs
T
IxianPixel 484ac50508
CI / test (push) Successful in 1m14s
Move a single season of a TV show (#4)
Shows can be expanded to list their seasons, each with its size and its own Dry run / Move buttons. A season joins the same show on the other
server, so finished seasons can go to the big server while the current one stays on the fast one.

- Source exports a season from the show folder, with a manifest of just that season's folder plus the show's loose non-video files. Refuses
  seasons with no folder of their own, or whose folder holds otherseasons' episodes.
- Destination finds the show by provider ID, then name. If it already has the show, the show's own files are skipped (Job.skip_files) and
  never overwritten; otherwise they come with the season. Refuses if the season folder already exists.
- Only episode watch state is carried for a season.
- Source trashes just the season folder; after the last season, the leftover show folder joins it in the same trash entry if no videos
  remain. The chosen trash entry is saved so a re-run after a crash finishes in the same place.
- New GET /seasons (UI and peer). Fake Jellyfin gains season items.
- e2e tests: season into a new show, into an existing show, last season leaving, destination already has the season, misfiled episodes.
2026-11-06 17:02:40 +00:00

139 lines
4.6 KiB
Rust

//! Local demo: two jellymove agents ("cloud" on :8097, "home" on :8098), each
//! with a fake Jellyfin and some throwaway media in a temp folder.
//!
//! npm --prefix ui ci && npm --prefix ui run build
//! cargo run -p jm-server --example demo
//!
//! Then open http://127.0.0.1:8097 and move something to "home".
#[path = "../tests/fake_jellyfin/mod.rs"]
#[allow(dead_code)]
mod fake_jellyfin;
use std::path::Path;
use std::sync::Arc;
use fake_jellyfin::{Fake, Lib};
use jm_server::config::{
Config, HooksConfig, JellyfinConfig, PeerConfig, TransferConfig, UiConfig,
};
fn write(path: &Path, len: usize) {
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
let data: Vec<u8> = (0..len as u32)
.map(|i| (i.wrapping_mul(2654435761) >> 11) as u8)
.collect();
std::fs::write(path, data).unwrap();
}
fn libs(root: &Path) -> Vec<Lib> {
vec![
Lib {
name: "Movies".into(),
collection_type: "movies",
location: root.join("movies"),
},
Lib {
name: "TV Shows".into(),
collection_type: "tvshows",
location: root.join("tv"),
},
]
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber_init();
let tmp = tempfile::tempdir()?;
let cloud = tmp.path().join("cloud");
let home = tmp.path().join("home");
for r in [&cloud, &home] {
std::fs::create_dir_all(r.join("movies"))?;
std::fs::create_dir_all(r.join("tv"))?;
}
const MB: usize = 1024 * 1024;
for (folder, size) in [
("Arrival (2016)", 180 * MB),
("Blade Runner (1982)", 120 * MB),
("Heat (1995)", 60 * MB),
] {
let base = cloud.join("movies").join(folder);
write(&base.join(format!("{folder}.mkv")), size);
write(&base.join(format!("{folder}.nfo")), 300);
write(&base.join(format!("{folder}.en.srt")), 40_000);
write(&base.join("poster.jpg"), 200_000);
}
for (season, eps) in [(1, 6), (2, 4)] {
for ep in 1..=eps {
write(
&cloud.join(format!(
"tv/Severance/Season {season:02}/Severance S{season:02}E{ep:02}.mkv"
)),
20 * MB,
);
}
}
write(&cloud.join("tv/Severance/tvshow.nfo"), 2_000);
write(&cloud.join("tv/Severance/poster.jpg"), 300_000);
write(
&home.join("movies/The Thing (1982)/The Thing (1982).mkv"),
40 * MB,
);
let fake_cloud = Fake::new(libs(&cloud));
let fake_home = Fake::new(libs(&home));
if let Some(id) = fake_cloud.find("Movie", "Arrival") {
fake_cloud.set_user_data(&id, serde_json::json!({"Played": true, "PlayCount": 1}));
}
let jf_cloud = fake_cloud.serve().await;
let jf_home = fake_home.serve().await;
let mut tasks = Vec::new();
for (name, root, jf, port, peer_port) in [
("cloud", &cloud, jf_cloud, 8097, 8098),
("home", &home, jf_home, 8098, 8097),
] {
let cfg = Config {
node_name: name.into(),
listen: format!("127.0.0.1:{port}").parse()?,
data_dir: root.join(".state"),
jellyfin: JellyfinConfig {
url: jf,
api_key: "demo".into(),
},
path_map: Default::default(),
peer: Some(PeerConfig {
url: format!("http://127.0.0.1:{peer_port}"),
token: "demo-token".into(),
}),
incoming_libraries: Default::default(),
// Throttled so you can watch the progress bar.
transfer: TransferConfig {
bandwidth_limit_mbps: 200.0,
..Default::default()
},
ui: UiConfig::default(),
hooks: HooksConfig::default(),
};
std::fs::create_dir_all(&cfg.data_dir)?;
let store = jm_store::Store::open(&cfg.data_dir.join("db"))?;
let state = Arc::new(jm_server::state::AppState::new(cfg, store)?);
jm_server::runner::resume_all(&state).await?;
let listener = tokio::net::TcpListener::bind(("127.0.0.1", port)).await?;
tasks.push(tokio::spawn(async move {
axum::serve(listener, jm_server::api::router(state)).await
}));
}
println!("demo media in {}", tmp.path().display());
println!("cloud: http://127.0.0.1:8097 home: http://127.0.0.1:8098 (Ctrl+C to stop)");
tokio::signal::ctrl_c().await?;
Ok(())
}
fn tracing_subscriber_init() {
// Keep the demo quiet unless asked.
if std::env::var_os("RUST_LOG").is_some() {
eprintln!("(set up your own subscriber for logs)");
}
}