fix: parsing is_ytm for playlists
This commit is contained in:
parent
0677fd487e
commit
97492780c6
7 changed files with 38 additions and 23 deletions
|
|
@ -184,11 +184,7 @@ impl MapResponse<MusicPlaylist> for response::MusicPlaylist {
|
|||
Some(header) => {
|
||||
let h = header.music_detail_header_renderer;
|
||||
|
||||
let from_ytm = h
|
||||
.subtitle
|
||||
.0
|
||||
.iter()
|
||||
.any(|c| c.as_str() == util::YT_MUSIC_NAME);
|
||||
let from_ytm = h.subtitle.0.iter().any(util::is_ytm);
|
||||
let channel = h
|
||||
.subtitle
|
||||
.0
|
||||
|
|
|
|||
|
|
@ -731,7 +731,8 @@ impl MusicListMapper {
|
|||
|
||||
let from_ytm = channel_p
|
||||
.as_ref()
|
||||
.map(|p| p.first_str() == util::YT_MUSIC_NAME)
|
||||
.and_then(|p| p.0.first())
|
||||
.map(util::is_ytm)
|
||||
.unwrap_or_default();
|
||||
let channel = channel_p.and_then(|p| {
|
||||
p.0.into_iter().find_map(|c| ChannelId::try_from(c).ok())
|
||||
|
|
@ -872,7 +873,8 @@ impl MusicListMapper {
|
|||
// (featured on the startpage or in genres)
|
||||
let from_ytm = subtitle_p2
|
||||
.as_ref()
|
||||
.map(|p| p.first_str() == util::YT_MUSIC_NAME)
|
||||
.and_then(|p| p.0.first())
|
||||
.map(util::is_ytm)
|
||||
.unwrap_or(true);
|
||||
let channel = subtitle_p2.and_then(|p| {
|
||||
p.0.into_iter().find_map(|c| ChannelId::try_from(c).ok())
|
||||
|
|
@ -1007,7 +1009,8 @@ impl MusicListMapper {
|
|||
MusicPageType::Playlist => {
|
||||
let from_ytm = subtitle_p2
|
||||
.as_ref()
|
||||
.map(|p| p.first_str() == util::YT_MUSIC_NAME)
|
||||
.and_then(|p| p.0.first())
|
||||
.map(util::is_ytm)
|
||||
.unwrap_or(true);
|
||||
let channel = subtitle_p2
|
||||
.and_then(|p| p.0.into_iter().find_map(|c| ChannelId::try_from(c).ok()));
|
||||
|
|
|
|||
|
|
@ -4233,18 +4233,21 @@ pub(crate) fn entry(lang: Language) -> Entry {
|
|||
},
|
||||
comma_decimal: false,
|
||||
number_tokens: ::phf::Map {
|
||||
key: 12913932095322966823,
|
||||
key: 15467950696543387533,
|
||||
disps: &[
|
||||
(0, 1),
|
||||
(0, 0),
|
||||
(2, 0),
|
||||
(2, 1),
|
||||
],
|
||||
entries: &[
|
||||
("ବ\u{b3f}ଜଣ", 9),
|
||||
("ହଟ\u{b3f}", 3),
|
||||
("ନ\u{b3f}ଜଣ", 6),
|
||||
("ହଜଣ", 3),
|
||||
("ବ\u{b3f}", 9),
|
||||
("ନ\u{b3f}", 6),
|
||||
("ବ\u{b3f}ଜଣ", 9),
|
||||
("ବ\u{b3f}ଟ\u{b3f}", 9),
|
||||
("ହଜଣ", 3),
|
||||
("ନ\u{b3f}ଟ\u{b3f}", 6),
|
||||
("ହ", 3),
|
||||
("ହଟ\u{b3f}", 3),
|
||||
],
|
||||
},
|
||||
album_types: ::phf::Map {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use rand::Rng;
|
|||
use regex::Regex;
|
||||
use url::Url;
|
||||
|
||||
use crate::{error::Error, param::Language};
|
||||
use crate::{error::Error, param::Language, serializer::text::TextComponent};
|
||||
|
||||
pub static VIDEO_ID_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[A-Za-z0-9_-]{11}$").unwrap());
|
||||
pub static CHANNEL_ID_REGEX: Lazy<Regex> =
|
||||
|
|
@ -34,8 +34,6 @@ pub static VANITY_PATH_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|||
|
||||
/// Separator string for YouTube Music subtitles
|
||||
pub const DOT_SEPARATOR: &str = " • ";
|
||||
/// YouTube Music name (author of official playlists)
|
||||
pub const YT_MUSIC_NAME: &str = "YouTube Music";
|
||||
pub const VARIOUS_ARTISTS: &str = "Various Artists";
|
||||
pub const PLAYLIST_ID_ALBUM_PREFIX: &str = "OLAK";
|
||||
|
||||
|
|
@ -269,6 +267,16 @@ impl<T> TryRemove<T> for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Check if a channel name equals "YouTube Music"
|
||||
/// (the author of original YouTube music playlists)
|
||||
pub(crate) fn is_ytm(text: &TextComponent) -> bool {
|
||||
if let TextComponent::Text { text } = text {
|
||||
text.starts_with("YouTube")
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if a language should be parsed by character
|
||||
pub fn lang_by_char(lang: Language) -> bool {
|
||||
matches!(
|
||||
|
|
|
|||
Reference in a new issue