feat: multilanguage album type parsing

- new album types: Audiobook, Show
This commit is contained in:
ThetaDev 2022-11-01 18:10:28 +01:00
parent abfd630a04
commit 45e2d3c7c7
15 changed files with 2354 additions and 32 deletions

View file

@ -201,7 +201,7 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
.unwrap_or_default();
let by_va = artists_txt == util::VARIOUS_ARTISTS;
let album_type = map_album_type(album_type_txt.as_str());
let album_type = map_album_type(album_type_txt.as_str(), lang);
let year = year_txt.and_then(|txt| util::parse_numeric(&txt).ok());
let mut mapper = match by_va {

View file

@ -11,7 +11,7 @@ use crate::{
text::{Text, TextComponents},
MapResult, VecLogError,
},
util::{self, TryRemove},
util::{self, dictionary, TryRemove},
};
use super::{
@ -278,7 +278,7 @@ impl MusicListMapper {
}
PageType::Album => {
let album_type = subtitle_p1
.map(|st| map_album_type(st.first_str()))
.map(|st| map_album_type(st.first_str(), self.lang))
.unwrap_or_default();
let (artists, artists_txt) = map_artists(subtitle_p2);
@ -469,12 +469,12 @@ impl MusicListMapper {
true,
) => {
year = util::parse_numeric(year_txt.first_str()).ok();
album_type = map_album_type(atype_txt.first_str());
album_type = map_album_type(atype_txt.first_str(), self.lang);
(artists.clone(), artists_txt.clone())
}
// "Album", <"Oonagh"> (Album variants, new releases)
(Some(atype_txt), Some(p2), _, false) => {
album_type = map_album_type(atype_txt.first_str());
album_type = map_album_type(atype_txt.first_str(), self.lang);
map_artists(Some(p2))
}
_ => {
@ -612,11 +612,10 @@ pub(crate) fn map_artists(artists_p: Option<TextComponents>) -> (Vec<ChannelId>,
(artists, artists_txt)
}
pub(crate) fn map_album_type(txt: &str) -> AlbumType {
// TODO: add support for different languages
match txt {
"Single" => AlbumType::Single,
"EP" => AlbumType::Ep,
_ => AlbumType::Album,
}
pub(crate) fn map_album_type(txt: &str, lang: Language) -> AlbumType {
dictionary::entry(lang)
.album_types
.get(&txt.to_lowercase())
.copied()
.unwrap_or_default()
}

View file

@ -598,7 +598,9 @@ pub struct ChannelTag {
*/
/// Verification status of a channel
#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(
Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[non_exhaustive]
pub enum Verification {
#[default]
@ -954,7 +956,9 @@ pub struct MusicPlaylistItem {
}
/// YouTube Music album type
#[derive(Default, Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[derive(
Default, Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[non_exhaustive]
pub enum AlbumType {
/// Regular album (default)
@ -964,6 +968,10 @@ pub enum AlbumType {
Ep,
/// Single
Single,
/// Audiobook
Audiobook,
/// Show (audio drama)
Show,
}
/// Album identifier
@ -1059,7 +1067,7 @@ pub enum MusicItem {
Playlist(MusicPlaylistItem),
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MusicEntityType {
Track,
Album,

File diff suppressed because it is too large Load diff