feat: add music playlist
This commit is contained in:
parent
b64aabb6b6
commit
566b3e5bfc
24 changed files with 238892 additions and 61192 deletions
|
|
@ -113,6 +113,7 @@ pub(crate) enum TextComponent {
|
|||
/// runs aka components, which can be simple strings or links.
|
||||
#[derive(Deserialize)]
|
||||
struct RichTextInternal {
|
||||
#[serde(default)]
|
||||
runs: Vec<RichTextRun>,
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +296,7 @@ impl TryFrom<TextComponent> for crate::model::ChannelId {
|
|||
page_type,
|
||||
browse_id,
|
||||
} => match page_type {
|
||||
PageType::Channel => Ok(crate::model::ChannelId {
|
||||
PageType::Channel | PageType::Artist => Ok(crate::model::ChannelId {
|
||||
id: browse_id,
|
||||
name: text,
|
||||
}),
|
||||
|
|
@ -306,6 +307,24 @@ impl TryFrom<TextComponent> for crate::model::ChannelId {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<TextComponent> for crate::model::AlbumId {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: TextComponent) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
TextComponent::Browse {
|
||||
text,
|
||||
page_type: PageType::Album,
|
||||
browse_id,
|
||||
} => Ok(Self {
|
||||
id: browse_id,
|
||||
name: text,
|
||||
}),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TextComponent> for crate::model::richtext::TextComponent {
|
||||
fn from(component: TextComponent) -> Self {
|
||||
match component {
|
||||
|
|
@ -343,6 +362,23 @@ impl From<TextComponents> for crate::model::richtext::RichText {
|
|||
}
|
||||
}
|
||||
|
||||
impl TextComponent {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
TextComponent::Video { text, .. } => text,
|
||||
TextComponent::Browse { text, .. } => text,
|
||||
TextComponent::Web { text, .. } => text,
|
||||
TextComponent::Text { text } => text,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for TextComponents {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.iter().map(|x| x.as_str()).collect::<String>()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct AccessibilityText {
|
||||
|
|
@ -669,6 +705,14 @@ mod tests {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_links_empty() {
|
||||
let test_json = r#"{"ln": {}}"#;
|
||||
|
||||
let res = serde_json::from_str::<SLinks>(&test_json).unwrap();
|
||||
assert!(res.ln.0.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_attributed_description() {
|
||||
let test_json = r#"{
|
||||
|
|
|
|||
Reference in a new issue