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.
This commit is contained in:
1 parent
25a743b350
commit
484ac50508
21 files changed
+959
-111
No files matched your search
@@ -34,7 +34,10 @@ struct FakeItem {
|
||||
kind: &'static str,
|
||||
path: String,
|
||||
parent: String,
|
||||
/// The series a season or episode belongs to.
|
||||
series: Option<String>,
|
||||
season: Option<i32>,
|
||||
/// Episode number, or a season's own number.
|
||||
episode: Option<i32>,
|
||||
}
|
||||
|
||||
@@ -133,6 +136,7 @@ impl Fake {
|
||||
kind: "Movie",
|
||||
path: f.display().to_string(),
|
||||
parent: lib.id(),
|
||||
series: None,
|
||||
season: None,
|
||||
episode: None,
|
||||
});
|
||||
@@ -145,25 +149,74 @@ impl Fake {
|
||||
kind: "Series",
|
||||
path: folder.display().to_string(),
|
||||
parent: lib.id(),
|
||||
series: None,
|
||||
season: None,
|
||||
episode: None,
|
||||
});
|
||||
// Like Jellyfin: a season per season folder, holding its
|
||||
// episodes; episodes loose in the show folder hang off
|
||||
// the series.
|
||||
let mut seasons: Vec<(PathBuf, i32, String)> = Vec::new();
|
||||
for f in files
|
||||
.iter()
|
||||
.filter(|f| f.extension().is_some_and(|e| e == "mkv"))
|
||||
{
|
||||
let fname = f.file_name().unwrap().to_string_lossy();
|
||||
if let Some((s, e)) = parse_sxxexx(&fname) {
|
||||
items.push(FakeItem {
|
||||
id: id_for(f),
|
||||
name: fname.to_string(),
|
||||
kind: "Episode",
|
||||
path: f.display().to_string(),
|
||||
parent: series_id.clone(),
|
||||
season: Some(s),
|
||||
episode: Some(e),
|
||||
});
|
||||
}
|
||||
let Some((s, e)) = parse_sxxexx(&fname) else {
|
||||
continue;
|
||||
};
|
||||
let in_folder = f
|
||||
.strip_prefix(&folder)
|
||||
.ok()
|
||||
.and_then(|r| r.components().next())
|
||||
.map(|c| folder.join(c))
|
||||
.filter(|p| p.is_dir());
|
||||
// The folder name gives the season's number ("Season 02",
|
||||
// "Specials"); an episode filed under the wrong season
|
||||
// doesn't belong to it.
|
||||
let folder_number = |p: &Path| {
|
||||
let n = p.file_name()?.to_string_lossy().to_lowercase();
|
||||
if n == "specials" {
|
||||
return Some(0);
|
||||
}
|
||||
n.chars()
|
||||
.filter(|c| c.is_ascii_digit())
|
||||
.collect::<String>()
|
||||
.parse::<i32>()
|
||||
.ok()
|
||||
};
|
||||
let parent = match in_folder {
|
||||
Some(season_folder) if folder_number(&season_folder) == Some(s) => {
|
||||
let id = id_for(&season_folder);
|
||||
if !seasons.iter().any(|(p, _, _)| p == &season_folder) {
|
||||
seasons.push((season_folder, s, id.clone()));
|
||||
}
|
||||
id
|
||||
}
|
||||
_ => series_id.clone(),
|
||||
};
|
||||
items.push(FakeItem {
|
||||
id: id_for(f),
|
||||
name: fname.to_string(),
|
||||
kind: "Episode",
|
||||
path: f.display().to_string(),
|
||||
parent,
|
||||
series: Some(series_id.clone()),
|
||||
season: Some(s),
|
||||
episode: Some(e),
|
||||
});
|
||||
}
|
||||
for (path, n, id) in seasons {
|
||||
items.push(FakeItem {
|
||||
id,
|
||||
name: if n == 0 { "Specials".into() } else { format!("Season {n}") },
|
||||
kind: "Season",
|
||||
path: path.display().to_string(),
|
||||
parent: series_id.clone(),
|
||||
series: Some(series_id.clone()),
|
||||
season: None,
|
||||
episode: Some(n),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +239,22 @@ impl Fake {
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|i| i.parent == series_id && i.season == Some(season) && i.episode == Some(ep))
|
||||
.find(|i| {
|
||||
i.kind == "Episode"
|
||||
&& i.series.as_deref() == Some(&series_id)
|
||||
&& i.season == Some(season)
|
||||
&& i.episode == Some(ep)
|
||||
})
|
||||
.map(|i| i.id.clone())
|
||||
}
|
||||
|
||||
pub fn season_id(&self, series: &str, season: i32) -> Option<String> {
|
||||
let series_id = self.find("Series", series)?;
|
||||
self.items
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|i| i.kind == "Season" && i.parent == series_id && i.episode == Some(season))
|
||||
.map(|i| i.id.clone())
|
||||
}
|
||||
|
||||
@@ -250,7 +318,14 @@ async fn items(State(f): State<Fake>, Query(q): Query<HashMap<String, String>>)
|
||||
let out: Vec<Value> = all
|
||||
.iter()
|
||||
.filter(|i| ids.as_ref().is_none_or(|ids| ids.contains(&i.id.as_str())))
|
||||
.filter(|i| q.get("parentId").is_none_or(|p| &i.parent == p))
|
||||
.filter(|i| {
|
||||
// Recursive queries under a series also reach its episodes,
|
||||
// which hang off their seasons.
|
||||
let recursive = q.get("recursive").is_some_and(|r| r == "true");
|
||||
q.get("parentId").is_none_or(|p| {
|
||||
&i.parent == p || (recursive && i.series.as_deref() == Some(p.as_str()))
|
||||
})
|
||||
})
|
||||
.filter(|i| types.as_ref().is_none_or(|t| t.contains(&i.kind)))
|
||||
.filter(|i| {
|
||||
q.get("searchTerm")
|
||||
@@ -258,7 +333,7 @@ async fn items(State(f): State<Fake>, Query(q): Query<HashMap<String, String>>)
|
||||
})
|
||||
.map(|i| {
|
||||
let mut v = json!({"Id": i.id, "Name": i.name, "Type": i.kind, "Path": i.path,
|
||||
"ParentIndexNumber": i.season, "IndexNumber": i.episode,
|
||||
"ParentIndexNumber": i.season, "IndexNumber": i.episode, "SeriesId": i.series,
|
||||
"MediaSources": [{"Path": i.path}]});
|
||||
if let Some(u) = user {
|
||||
v["UserData"] = ud
|
||||
|
||||
Reference in new issue
Block a user