Skip to main content

radio_cli/
model.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
4#[serde(default)]
5pub struct Station {
6    pub stationuuid: String,
7    pub name: String,
8    pub url: String,
9    pub url_resolved: String,
10    pub homepage: String,
11    pub favicon: String,
12    pub country: String,
13    pub countrycode: String,
14    pub state: String,
15    pub language: String,
16    pub languagecodes: String,
17    pub tags: String,
18    pub codec: String,
19    pub bitrate: u32,
20    pub hls: u8,
21    pub lastcheckok: u8,
22    pub votes: u64,
23    pub clickcount: u64,
24    pub custom: bool,
25    pub active: bool,
26    pub favorite: bool,
27}
28
29impl Station {
30    pub fn primary_url(&self) -> &str {
31        if self.url_resolved.is_empty() {
32            &self.url
33        } else {
34            &self.url_resolved
35        }
36    }
37
38    pub fn stream_candidates(&self, backups: &[String]) -> Vec<String> {
39        let mut result = Vec::new();
40        for url in std::iter::once(self.primary_url())
41            .chain(std::iter::once(self.url.as_str()))
42            .chain(backups.iter().map(String::as_str))
43        {
44            if crate::config::validate_url(url).is_ok() && !result.iter().any(|s| s == url) {
45                result.push(url.to_owned());
46            }
47        }
48        result
49    }
50
51    pub fn search_text(&self) -> String {
52        format!(
53            "{} {} {} {} {} {} {}",
54            self.name,
55            self.country,
56            self.countrycode,
57            self.state,
58            self.language,
59            self.languagecodes,
60            self.tags
61        )
62        .to_lowercase()
63    }
64}
65
66#[derive(Debug, Clone, Default, PartialEq, Eq)]
67pub struct Filter {
68    pub sort: Sort,
69    pub query: String,
70    pub country: Option<String>,
71    pub language: Option<String>,
72    pub tag: Option<String>,
73    pub min_bitrate: u32,
74    pub favorites: bool,
75    pub history: bool,
76    pub custom: bool,
77    pub limit: usize,
78    pub recordings: bool,
79    pub offset: usize,
80}
81
82#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, clap::ValueEnum)]
83pub enum Sort {
84    Name,
85    Bitrate,
86    Votes,
87    #[default]
88    Clickcount,
89    Random,
90}
91
92#[derive(Debug, Clone, Copy)]
93pub enum FacetKind {
94    Country,
95    Language,
96    Tag,
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
100pub struct Facet {
101    pub value: String,
102    pub count: usize,
103}
104
105#[derive(Debug, Clone, Deserialize, Serialize)]
106pub struct Recording {
107    pub id: String,
108    pub stationuuid: String,
109    pub station_name: String,
110    /// Track title captured when recording was requested; absent for old records.
111    #[serde(default, skip_serializing_if = "Option::is_none")]
112    pub track: Option<String>,
113    pub source_url_resolved: String,
114    pub started_at: String,
115    pub stopped_at: Option<String>,
116    pub media_duration_ms: Option<u64>,
117    pub codec: String,
118    pub container: String,
119    pub path: String,
120    #[serde(default)]
121    pub final_path: Option<String>,
122    pub size_bytes: u64,
123    pub status: String,
124    pub error: Option<String>,
125    /// FFmpeg reconnect attempts; live audio may have gaps even on completion.
126    #[serde(default)]
127    pub reconnects: u64,
128    #[serde(default)]
129    pub recovery_pending: bool,
130}