this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(status): move display impl onto `Status` record object

+105 -103
+1 -1
src/main.rs
··· 369 369 370 370 let status_man = StatusManager::new(&ident); 371 371 let status = status_man.get_status().await?; 372 - status_man.display_status(&status, raw, full); 372 + status.display(raw, full); 373 373 } 374 374 StatusCommands::Clear => { 375 375 let auth = get_auth()?;
+104
src/record.rs
··· 199 199 } 200 200 } 201 201 } 202 + 203 + impl Status { 204 + pub fn display(&self, raw: bool, full: bool) { 205 + // if both track name and artists are blank, probably nothing's playing 206 + if self.item.track_name.is_empty() && self.item.artists.is_empty() && !raw { 207 + println!("nothing playing right now"); 208 + return; 209 + } 210 + 211 + println!("track: {}", self.item.track_name); 212 + 213 + if let Some(track_id) = &self.item.track_mb_id 214 + && full 215 + { 216 + println!("track id: {}", track_id); 217 + } 218 + 219 + if let Some(recording_id) = &self.item.recording_mb_id 220 + && full 221 + { 222 + println!("recording id: {}", recording_id); 223 + } 224 + 225 + if !self.item.artists.is_empty() || raw { 226 + print!("artists: "); 227 + 228 + for i in 0..self.item.artists.len() { 229 + print!("{}", self.item.artists[i].artist_name); 230 + 231 + if let Some(artist_id) = &self.item.artists[i].artist_mb_id 232 + && full 233 + { 234 + print!(" [{}]", artist_id); 235 + } 236 + 237 + if i != self.item.artists.len() - 1 { 238 + print!(", "); 239 + } 240 + } 241 + 242 + println!(); 243 + } 244 + 245 + if let Some(release) = &self.item.release_name { 246 + println!("release: {}", release); 247 + } 248 + 249 + if let Some(release_id) = &self.item.release_mb_id 250 + && full 251 + { 252 + println!("release id: {}", release_id); 253 + } 254 + 255 + if let Some(isrc) = &self.item.isrc 256 + && full 257 + { 258 + println!("isrc: {}", isrc); 259 + } 260 + 261 + if let Some(played_time) = &self.item.played_time { 262 + if raw { 263 + println!("played: {}", played_time.format("%Y-%m-%d %H:%M:%S %:z")); 264 + } else { 265 + let local_dt = played_time.with_timezone(&chrono::Local); 266 + println!("played: {}", local_dt.format("%Y-%m-%d %H:%M:%S")); 267 + } 268 + } 269 + 270 + if let Some(duration) = self.item.duration { 271 + if raw { 272 + println!("duration: {}", duration); 273 + } else { 274 + let hours = duration / 3600; 275 + let minutes = (duration - (hours * 3600)) / 60; 276 + let seconds = duration - (minutes * 60); 277 + 278 + let mut duration_str = "".to_string(); 279 + if hours > 0 { 280 + duration_str = format!("{:02}:", hours); 281 + } 282 + if minutes > 0 || hours > 0 { 283 + duration_str = format!("{}{:02}:", duration_str, minutes); 284 + } 285 + if seconds > 0 || minutes > 0 || hours > 0 { 286 + duration_str = format!("{}{:02}", duration_str, seconds); 287 + } 288 + 289 + println!("duration: {}", duration_str); 290 + } 291 + } 292 + 293 + if let Some(service) = &self.item.music_service_base_domain 294 + && full 295 + { 296 + println!("service: {}", service); 297 + } 298 + 299 + if let Some(client) = &self.item.submission_client_agent 300 + && full 301 + { 302 + println!("client: {}", client); 303 + } 304 + } 305 + }
-102
src/status.rs
··· 101 101 ) 102 102 .await 103 103 } 104 - 105 - pub fn display_status(&self, status: &Status, raw: bool, full: bool) { 106 - // if both track name and artists are blank, probably nothing's playing 107 - if status.item.track_name.is_empty() && status.item.artists.is_empty() && !raw { 108 - println!("nothing playing right now"); 109 - return; 110 - } 111 - 112 - println!("track: {}", status.item.track_name); 113 - 114 - if let Some(track_id) = &status.item.track_mb_id 115 - && full 116 - { 117 - println!("track id: {}", track_id); 118 - } 119 - 120 - if let Some(recording_id) = &status.item.recording_mb_id 121 - && full 122 - { 123 - println!("recording id: {}", recording_id); 124 - } 125 - 126 - if !status.item.artists.is_empty() || raw { 127 - print!("artists: "); 128 - 129 - for i in 0..status.item.artists.len() { 130 - print!("{}", status.item.artists[i].artist_name); 131 - 132 - if let Some(artist_id) = &status.item.artists[i].artist_mb_id 133 - && full 134 - { 135 - print!(" [{}]", artist_id); 136 - } 137 - 138 - if i != status.item.artists.len() - 1 { 139 - print!(", "); 140 - } 141 - } 142 - 143 - println!(); 144 - } 145 - 146 - if let Some(release) = &status.item.release_name { 147 - println!("release: {}", release); 148 - } 149 - 150 - if let Some(release_id) = &status.item.release_mb_id 151 - && full 152 - { 153 - println!("release id: {}", release_id); 154 - } 155 - 156 - if let Some(isrc) = &status.item.isrc 157 - && full 158 - { 159 - println!("isrc: {}", isrc); 160 - } 161 - 162 - if let Some(played_time) = &status.item.played_time { 163 - if raw { 164 - println!("played: {}", played_time.format("%Y-%m-%d %H:%M:%S %:z")); 165 - } else { 166 - let local_dt = played_time.with_timezone(&chrono::Local); 167 - println!("played: {}", local_dt.format("%Y-%m-%d %H:%M:%S")); 168 - } 169 - } 170 - 171 - if let Some(duration) = status.item.duration { 172 - if raw { 173 - println!("duration: {}", duration); 174 - } else { 175 - let hours = duration / 3600; 176 - let minutes = (duration - (hours * 3600)) / 60; 177 - let seconds = duration - (minutes * 60); 178 - 179 - let mut duration_str = "".to_string(); 180 - if hours > 0 { 181 - duration_str = format!("{:02}:", hours); 182 - } 183 - if minutes > 0 || hours > 0 { 184 - duration_str = format!("{}{:02}:", duration_str, minutes); 185 - } 186 - if seconds > 0 || minutes > 0 || hours > 0 { 187 - duration_str = format!("{}{:02}", duration_str, seconds); 188 - } 189 - 190 - println!("duration: {}", duration_str); 191 - } 192 - } 193 - 194 - if let Some(service) = &status.item.music_service_base_domain 195 - && full 196 - { 197 - println!("service: {}", service); 198 - } 199 - 200 - if let Some(client) = &status.item.submission_client_agent 201 - && full 202 - { 203 - println!("client: {}", client); 204 - } 205 - } 206 104 }