Skip to content

Commit

Permalink
media-file: Import/export sort fields
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Jul 12, 2023
1 parent b4d7102 commit a672b5a
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 127 deletions.
21 changes: 21 additions & 0 deletions crates/core/src/track/title/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub enum TitlesInvalidity {
Title(TitleInvalidity),
MainTitleMissing,
MainTitleAmbiguous,
TitleSortingAmbiguous,
}

pub const ANY_KIND_FILTER: Option<Kind> = None;
Expand All @@ -115,6 +116,12 @@ impl Titles {
_ => context.invalidate(TitlesInvalidity::MainTitleAmbiguous),
}
}
if context.is_valid() {
context = match Self::sorting_titles(titles.to_owned()).count() {
0 | 1 => context, // ok
_ => context.invalidate(TitlesInvalidity::TitleSortingAmbiguous),
}
}
context.into()
}

Expand Down Expand Up @@ -145,6 +152,20 @@ impl Titles {
Self::main_titles(titles).next()
}

pub fn sorting_titles<'a, 'b, I>(titles: I) -> impl Iterator<Item = &'a Title>
where
I: IntoIterator<Item = &'a Title>,
{
Self::filter_kind(titles, Kind::Sorting)
}

pub fn title_sorting<'a, I>(titles: I) -> Option<&'a Title>
where
I: IntoIterator<Item = &'a Title>,
{
Self::sorting_titles(titles).next()
}

pub fn set_main_title(titles: &mut Vec<Title>, name: impl Into<String>) -> bool {
debug_assert!(titles.is_canonical());
let name = name.into();
Expand Down
Loading

0 comments on commit a672b5a

Please sign in to comment.