Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/media/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,13 @@ pub fn parse_tv(name: &str) -> Option<Parsed> {
})
}

/// A number a list puts before a title: `01. The Matrix (1999)`, `3 - Alien (1979)`, `12) Heat (1995)`. Only with
/// a space after it, so `21.Jump.Street.2012` and `1917 (2019)` keep their numbers.
static LIST_NUMBER: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\s*\d{1,3}\s*(?:[.)]|\s-)\s+").unwrap());

pub fn parse_movie(name: &str) -> Option<Parsed> {
let name = LIST_NUMBER.replace(name, "");
let name = name.as_ref();
let spaced = SPACES.replace_all(&name.replace(['.', '_'], " "), " ").into_owned();
let (raw, year): (String, Option<i32>) = if let Some(c) = M1.captures(&spaced) {
(c[1].to_string(), c[2].parse().ok())
Expand Down Expand Up @@ -369,6 +375,29 @@ mod tests {
assert!(wrong.is_empty(), "{}", wrong.join("\n"));
}

#[test]
fn a_list_number_before_the_title_goes() {
// spot titles from a numbered series (spot K6rspFvcMg49TvvagOSea@spot.net and its sequels)
for (name, title, year) in [
("01. The Matrix (1999) 4k UHD Rife 60fps AI-Enhanced Dolby True-HD Atmos", "The Matrix", Some(1999)),
(
"02. The Matrix Reloaded (2006) 4k UHD Rife 60fps AI-Enhanced Dolby True-HD Atmos",
"The Matrix Reloaded",
Some(2006),
),
("3 - Alien (1979) 1080p", "Alien", Some(1979)),
("12) Heat (1995) 1080p", "Heat", Some(1995)),
// a number that is the title, or sits in a dotted name, stays
("21.Jump.Street.2012.1080p.BluRay.x264-GRP", "21 Jump Street", Some(2012)),
("1917 (2019) 2160p", "1917", Some(2019)),
("300 (2006) 1080p BluRay", "300", Some(2006)),
("2001 A Space Odyssey (1968) 1080p", "2001 A Space Odyssey", Some(1968)),
] {
let got = parse_movie(name).unwrap_or_else(|| panic!("{name}"));
assert_eq!((got.title.as_str(), got.year), (title, year), "{name}");
}
}

#[test]
fn an_alias_gives_the_canonical_title() {
assert_eq!(parse_tv("Daily.Show.S01E02.720p.WEB-GRP").unwrap().title, "The Daily Show");
Expand Down
26 changes: 26 additions & 0 deletions src/media/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ fn name_of(r: &ReleaseInfo) -> &str {
}

fn target_of(media: &Media, r: &ReleaseInfo) -> Option<(Kind, Parsed)> {
// a spot's title is what its spotter typed, which the name rules often don't read as a movie or show: the
// spotter's kind says which it is (`spotnet::category`)
if let Some(kind) = r.spot_kind {
let category = match kind {
crate::spotnet::Kind::Movie => 2000,
crate::spotnet::Kind::Series => 5000,
};
return media_target(category, "spot_kind", name_of(r));
}
let d: Decision = category::classify_release(r, &media.category_options());
media_target(d.category, d.rule, name_of(r))
}
Expand Down Expand Up @@ -441,6 +450,23 @@ mod tests {
use super::*;
use std::path::Path;

#[test]
fn a_spots_kind_gives_its_title_to_look_up() {
// a name the category rules don't read as a movie: the spot says it is one
let media = Media::new(Path::new("/nowhere/atlas.db"));
let r = ReleaseInfo {
name: "01. The Matrix (1999) 4k UHD Rife 60fps AI-Enhanced Dolby True-HD Atmos".into(),
group: "alt.binaries.boneless".into(),
poster: Some("yEncBin@Poster.com (FrameMaster)".into()),
..Default::default()
};
assert!(target_of(&media, &r).is_none(), "no movie by its name alone");
let spot = ReleaseInfo { spot_kind: Some(crate::spotnet::Kind::Movie), ..r };
let (kind, p) = target_of(&media, &spot).unwrap();
assert_eq!((kind, p.title.as_str(), p.year), (Kind::Movie, "The Matrix", Some(1999)));
assert_eq!(MediaLookup(media.clone()).skip_reason(&spot), None);
}

#[test]
fn each_step_has_its_lane() {
let media = Media::new(Path::new("/nowhere/atlas.db"));
Expand Down
4 changes: 3 additions & 1 deletion src/postprocess/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ struct Row {
const ROW_COLUMNS: &str = "r.id, r.name, r.display_name, r.group_name, r.poster, r.posted_date, coalesce(r.size, 0),
coalesce(r.complete, 0), coalesce(r.parts, 0), r.file_total, coalesce(r.is_obfuscated, 0), r.name_source,
s.release_id is not null, coalesce(s.done, 0), coalesce(s.failed, 0), coalesce(s.db_attempts, 0),
coalesce(s.net_attempts, 0), coalesce(s.parts_seen, 0), coalesce(s.rerun_gen, 0), coalesce(s.net_transient, 0)";
coalesce(s.net_attempts, 0), coalesce(s.parts_seen, 0), coalesce(s.rerun_gen, 0), coalesce(s.net_transient, 0),
(select kind from spots where release_id = r.id)";

fn read_row(r: &SqlRow<'_>, at: usize, shard: usize) -> rusqlite::Result<Row> {
let col = |i: usize| at + i;
Expand All @@ -134,6 +135,7 @@ fn read_row(r: &SqlRow<'_>, at: usize, shard: usize) -> rusqlite::Result<Row> {
file_total: r.get(col(9))?,
is_obfuscated: r.get::<_, i64>(col(10))? != 0,
name_source: r.get(col(11))?,
spot_kind: crate::spotnet::Kind::parse(r.get::<_, Option<String>>(col(20))?.as_deref()),
},
has_state: r.get(col(12))?,
done: r.get(col(13))?,
Expand Down
2 changes: 2 additions & 0 deletions src/postprocess/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub struct ReleaseInfo {
pub file_total: Option<i64>,
pub is_obfuscated: bool,
pub name_source: Option<i64>,
/// a movie or series, when the release was saved from a Spotnet spot that says so (`spotnet::store::SPOTS`)
pub spot_kind: Option<crate::spotnet::Kind>,
}

/// What a step gets for one release.
Expand Down
9 changes: 9 additions & 0 deletions src/spotnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ pub enum Kind {
}

impl Kind {
/// The kind a `spots` row's `kind` names, if any.
pub fn parse(kind: Option<&str>) -> Option<Kind> {
match kind? {
"movie" => Some(Kind::Movie),
"series" => Some(Kind::Series),
_ => None,
}
}

pub fn as_str(self) -> &'static str {
match self {
Kind::Movie => "movie",
Expand Down
6 changes: 4 additions & 2 deletions src/web_pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ fn read_state(conn: &Connection, s: usize, id: i64) -> rusqlite::Result<State> {
.query_row(
&format!(
"select name, display_name, group_name, poster, posted_date, coalesce(size, 0), coalesce(complete, 0),
coalesce(parts, 0), file_total, coalesce(is_obfuscated, 0), name_source
from s{s}.releases where id = ?"
coalesce(parts, 0), file_total, coalesce(is_obfuscated, 0), name_source,
(select kind from s{s}.spots where release_id = ?1)
from s{s}.releases where id = ?1"
),
[id],
|r| {
Expand All @@ -179,6 +180,7 @@ fn read_state(conn: &Connection, s: usize, id: i64) -> rusqlite::Result<State> {
file_total: r.get(8)?,
is_obfuscated: r.get::<_, i64>(9)? != 0,
name_source: r.get(10)?,
spot_kind: crate::spotnet::Kind::parse(r.get::<_, Option<String>>(11)?.as_deref()),
})
},
)
Expand Down