lyrics_core/models/
lyrics_data.rs1use serde::{Deserialize, Serialize};
2
3use super::line_info::LineInfo;
4use super::lyrics_types::{LyricsTypes, SyncTypes};
5use super::track_metadata::TrackMetadata;
6
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct LyricsData {
10 pub file: Option<FileInfo>,
12 pub lines: Option<Vec<LineInfo>>,
14 pub writers: Option<Vec<String>>,
16 pub track_metadata: Option<TrackMetadata>,
18}
19
20#[derive(Debug, Clone, Default, Serialize, Deserialize)]
22pub struct FileInfo {
23 #[serde(rename = "type")]
25 pub lyrics_type: LyricsTypes,
26 pub sync_types: SyncTypes,
28 pub additional_info: Option<AdditionalFileInfo>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(tag = "type")]
37pub enum AdditionalFileInfo {
38 General {
40 attributes: Vec<(String, String)>,
42 },
43 Krc {
45 attributes: Vec<(String, String)>,
47 hash: Option<String>,
49 },
50 Spotify {
52 provider: Option<String>,
54 provider_lyrics_id: Option<String>,
56 provider_display_name: Option<String>,
58 lyrics_language: Option<String>,
60 },
61}
62
63impl AdditionalFileInfo {
64 pub fn new_general() -> Self {
66 Self::General {
67 attributes: Vec::new(),
68 }
69 }
70
71 pub fn new_krc() -> Self {
73 Self::Krc {
74 attributes: Vec::new(),
75 hash: None,
76 }
77 }
78
79 pub fn new_spotify(
81 provider: Option<String>,
82 provider_lyrics_id: Option<String>,
83 provider_display_name: Option<String>,
84 lyrics_language: Option<String>,
85 ) -> Self {
86 Self::Spotify {
87 provider,
88 provider_lyrics_id,
89 provider_display_name,
90 lyrics_language,
91 }
92 }
93
94 pub fn attributes(&self) -> Option<&Vec<(String, String)>> {
96 match self {
97 Self::General { attributes } | Self::Krc { attributes, .. } => Some(attributes),
98 _ => None,
99 }
100 }
101
102 pub fn attributes_mut(&mut self) -> Option<&mut Vec<(String, String)>> {
104 match self {
105 Self::General { attributes } | Self::Krc { attributes, .. } => Some(attributes),
106 _ => None,
107 }
108 }
109
110 pub fn hash(&self) -> Option<&str> {
112 match self {
113 Self::Krc { hash, .. } => hash.as_deref(),
114 _ => None,
115 }
116 }
117}