mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Check search scopes before replacing
This commit is contained in:
parent
845ade24ee
commit
d2a8339ab7
1 changed files with 51 additions and 15 deletions
|
|
@ -165,7 +165,7 @@ impl From<&Subtitle> for FormatSubtitle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
enum Scope {
|
enum Scope {
|
||||||
Series,
|
Series,
|
||||||
Season,
|
Season,
|
||||||
|
|
@ -192,13 +192,11 @@ macro_rules! must_match_if_true {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! self_and_versions {
|
macro_rules! self_and_versions {
|
||||||
($var:expr => $audio:expr) => {
|
($var:expr => $audio:expr) => {{
|
||||||
{
|
|
||||||
let mut items = vec![$var.clone()];
|
let mut items = vec![$var.clone()];
|
||||||
items.extend($var.clone().version($audio).await?);
|
items.extend($var.clone().version($audio).await?);
|
||||||
items
|
items
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Format {
|
pub struct Format {
|
||||||
|
|
@ -281,20 +279,41 @@ impl Format {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pattern_count_empty(&self, scope: Scope) -> bool {
|
|
||||||
self.pattern_count.get(&scope).cloned().unwrap_or_default() == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn parse(&self, media_collection: MediaCollection) -> Result<String> {
|
pub async fn parse(&self, media_collection: MediaCollection) -> Result<String> {
|
||||||
match &media_collection {
|
match &media_collection {
|
||||||
MediaCollection::Series(_)
|
MediaCollection::Series(_)
|
||||||
| MediaCollection::Season(_)
|
| MediaCollection::Season(_)
|
||||||
| MediaCollection::Episode(_) => self.parse_series(media_collection).await,
|
| MediaCollection::Episode(_) => {
|
||||||
|
self.check_scopes(vec![
|
||||||
|
Scope::Series,
|
||||||
|
Scope::Season,
|
||||||
|
Scope::Episode,
|
||||||
|
Scope::Stream,
|
||||||
|
Scope::Subtitle,
|
||||||
|
])?;
|
||||||
|
|
||||||
|
self.parse_series(media_collection).await
|
||||||
|
}
|
||||||
MediaCollection::MovieListing(_) | MediaCollection::Movie(_) => {
|
MediaCollection::MovieListing(_) | MediaCollection::Movie(_) => {
|
||||||
|
self.check_scopes(vec![
|
||||||
|
Scope::MovieListing,
|
||||||
|
Scope::Movie,
|
||||||
|
Scope::Stream,
|
||||||
|
Scope::Subtitle,
|
||||||
|
])?;
|
||||||
|
|
||||||
self.parse_movie_listing(media_collection).await
|
self.parse_movie_listing(media_collection).await
|
||||||
}
|
}
|
||||||
MediaCollection::MusicVideo(_) => self.parse_music_video(media_collection).await,
|
MediaCollection::MusicVideo(_) => {
|
||||||
MediaCollection::Concert(_) => self.parse_concert(media_collection).await,
|
self.check_scopes(vec![Scope::MusicVideo, Scope::Stream, Scope::Subtitle])?;
|
||||||
|
|
||||||
|
self.parse_music_video(media_collection).await
|
||||||
|
}
|
||||||
|
MediaCollection::Concert(_) => {
|
||||||
|
self.check_scopes(vec![Scope::Concert, Scope::Stream, Scope::Subtitle])?;
|
||||||
|
|
||||||
|
self.parse_concert(media_collection).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -520,6 +539,23 @@ impl Format {
|
||||||
serde_json::from_value(serde_json::to_value(s).unwrap()).unwrap()
|
serde_json::from_value(serde_json::to_value(s).unwrap()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_pattern_count_empty(&self, scope: Scope) -> bool {
|
||||||
|
self.pattern_count.get(&scope).cloned().unwrap_or_default() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_scopes(&self, available_scopes: Vec<Scope>) -> Result<()> {
|
||||||
|
for (_, scope, field) in self.pattern.iter() {
|
||||||
|
if !available_scopes.contains(scope) {
|
||||||
|
bail!(
|
||||||
|
"'{}.{}' is not a valid keyword",
|
||||||
|
format!("{:?}", scope).to_lowercase(),
|
||||||
|
field
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn replace_all(
|
fn replace_all(
|
||||||
&self,
|
&self,
|
||||||
values: HashMap<Scope, &Map<String, Value>>,
|
values: HashMap<Scope, &Map<String, Value>>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue