Model refinement

This commit is contained in:
2025-10-01 19:34:07 -06:00
parent 06110b91a1
commit 6eec67a0fd
28 changed files with 292 additions and 143 deletions
+13 -13
View File
@@ -47,17 +47,17 @@ pub enum Scanner {
Show {
/// The ID of the parent collection (if any)
parent: Option<CollectionId>,
/// The ID of the show this episode belongs to
/// The ID of the show
id: ShowId,
/// The file name of the poster file
poster_file_name: Option<String>,
},
/// A scanned episode
Season {
/// The ID of the show this episode belongs to
/// The ID of the show this season belongs to
show: ShowId,
/// The season this episode belongs to
number: SeasonNumber,
/// The number of this season
season: SeasonNumber,
/// The file name of the poster file
poster_file_name: Option<String>,
},
@@ -68,7 +68,7 @@ pub enum Scanner {
/// The season this episode belongs to
season: SeasonNumber,
/// The number(s) of this episode
number: EpisodeNumbers,
episode: EpisodeNumbers,
/// The file name of the media file
media_file_name: String,
/// The file name of the poster file
@@ -108,23 +108,23 @@ impl From<show::Scanner> for Scanner {
},
show::Scanner::Season {
show,
number,
season,
poster_file_name,
} => Self::Season {
show,
number,
season,
poster_file_name,
},
show::Scanner::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
} => Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
},
@@ -166,23 +166,23 @@ impl From<generic::Scanner> for Scanner {
},
generic::Scanner::Season {
show,
number,
season,
poster_file_name,
} => Self::Season {
show,
number,
season,
poster_file_name,
},
generic::Scanner::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
} => Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
},
+3 -3
View File
@@ -26,7 +26,7 @@ pub enum Scanner {
/// The season this episode belongs to
season: SeasonNumber,
/// The number(s) of this episode
number: EpisodeNumbers,
episode: EpisodeNumbers,
/// The file name of the media file
media_file_name: String,
/// The file name of the poster file
@@ -40,7 +40,7 @@ impl Scanner {
path: &Path,
show: ShowId,
season: SeasonNumber,
number: EpisodeNumbers,
episode: EpisodeNumbers,
) -> impl Stream<Item = Item> {
stream!({
let dirs = match fs::read_dir(path).await {
@@ -137,7 +137,7 @@ impl Scanner {
event: Ok(Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
}),
+17 -15
View File
@@ -51,17 +51,17 @@ pub enum Scanner {
Show {
/// The ID of the parent collection (if any)
parent: Option<CollectionId>,
/// The ID of the show this episode belongs to
/// The ID of the show
id: ShowId,
/// The file name of the poster file
poster_file_name: Option<String>,
},
/// A scanned episode
Season {
/// The ID of the show this episode belongs to
/// The ID of the show this season belongs to
show: ShowId,
/// The season this episode belongs to
number: SeasonNumber,
season: SeasonNumber,
/// The file name of the poster file
poster_file_name: Option<String>,
},
@@ -72,7 +72,7 @@ pub enum Scanner {
/// The season this episode belongs to
season: SeasonNumber,
/// The number(s) of this episode
number: EpisodeNumbers,
episode: EpisodeNumbers,
/// The file name of the media file
media_file_name: String,
/// The file name of the poster file
@@ -114,23 +114,23 @@ impl From<collection::Scanner> for Scanner {
},
collection::Scanner::Season {
show,
number,
season,
poster_file_name,
} => Self::Season {
show,
number,
season,
poster_file_name,
},
collection::Scanner::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
} => Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
},
@@ -170,23 +170,23 @@ impl From<show::Scanner> for Scanner {
},
show::Scanner::Season {
show,
number,
season,
poster_file_name,
} => Self::Season {
show,
number,
season,
poster_file_name,
},
show::Scanner::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
} => Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
},
@@ -211,10 +211,12 @@ impl Scanner {
}
let media_folder_re = MEDIA_FOLDER_REGEX.get_or_init(|| {
Regex::new(r"^[\w ]+ \(\d+\) \[\d+\]$").unwrap_or_else(|_| panic!("regex is invalid"))
Regex::new(r"^[[[:alnum:]] -]+ \([[:digit:]]+\) \[[[:digit:]]+\]$")
.unwrap_or_else(|err| panic!("regex is invalid: {err}"))
});
let season_folder_re = SEASON_FOLDER_REGEX.get_or_init(|| {
Regex::new(r"^S[[:digit:]]+$").unwrap_or_else(|err| panic!("regex is invalid: {err}"))
});
let season_folder_re = SEASON_FOLDER_REGEX
.get_or_init(|| Regex::new(r"^S\d+$").unwrap_or_else(|_| panic!("regex is invalid")));
stream!({
let Some(dir_name) = path.file_name().and_then(OsStr::to_str) else {
+15 -12
View File
@@ -22,10 +22,10 @@ pub type Item = crate::Item<Scanner>;
pub enum Scanner {
/// A scanned episode
Season {
/// The ID of the show this episode belongs to
/// The ID of the show this season belongs to
show: ShowId,
/// The season this episode belongs to
number: SeasonNumber,
season: SeasonNumber,
/// The file name of the poster file
poster_file_name: Option<String>,
},
@@ -36,7 +36,7 @@ pub enum Scanner {
/// The season this episode belongs to
season: SeasonNumber,
/// The number(s) of this episode
number: EpisodeNumbers,
episode: EpisodeNumbers,
/// The file name of the media file
media_file_name: String,
/// The file name of the poster file
@@ -50,13 +50,13 @@ impl From<episode::Scanner> for Scanner {
episode::Scanner::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
} => Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
},
@@ -69,7 +69,7 @@ impl Scanner {
pub fn scan_season(
path: &Path,
show: ShowId,
number: SeasonNumber,
season: SeasonNumber,
) -> impl Stream<Item = Item> {
stream!({
let dirs = match fs::read_dir(path).await {
@@ -141,7 +141,7 @@ impl Scanner {
path: path.to_owned(),
event: Ok(Self::Season {
show,
number,
season,
poster_file_name,
}),
};
@@ -170,14 +170,14 @@ impl Scanner {
continue;
};
let Ok(season) = s_str.parse::<SeasonNumber>() else {
let Ok(season_number) = s_str.parse::<SeasonNumber>() else {
yield Item {
path: path.to_owned(),
event: Err(Error::UnexpectedFolder),
};
continue;
};
if season != number {
if season_number != season {
yield Item {
path: path.to_owned(),
event: Err(Error::Inconsistent),
@@ -204,9 +204,12 @@ impl Scanner {
continue;
};
for await event in
episode::Scanner::scan_episode(&episode_dir, show, number, episode_numbers)
{
for await event in episode::Scanner::scan_episode(
&episode_dir,
show,
season_number,
episode_numbers,
) {
yield event.map(|e| e.into());
}
}
+8 -8
View File
@@ -24,17 +24,17 @@ pub enum Scanner {
Show {
/// The ID of the parent collection (if any)
parent: Option<CollectionId>,
/// The ID of the show this episode belongs to
/// The ID of the show
id: ShowId,
/// The file name of the poster file
poster_file_name: Option<String>,
},
/// A scanned episode
Season {
/// The ID of the show this episode belongs to
/// The ID of the show this season belongs to
show: ShowId,
/// The season this episode belongs to
number: SeasonNumber,
season: SeasonNumber,
/// The file name of the poster file
poster_file_name: Option<String>,
},
@@ -45,7 +45,7 @@ pub enum Scanner {
/// The season this episode belongs to
season: SeasonNumber,
/// The number(s) of this episode
number: EpisodeNumbers,
episode: EpisodeNumbers,
/// The file name of the media file
media_file_name: String,
/// The file name of the poster file
@@ -58,23 +58,23 @@ impl From<season::Scanner> for Scanner {
match value {
season::Scanner::Season {
show,
number,
season,
poster_file_name,
} => Self::Season {
show,
number,
season,
poster_file_name,
},
season::Scanner::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
} => Self::Episode {
show,
season,
number,
episode,
media_file_name,
poster_file_name,
},