this repo has no description
0
fork

Configure Feed

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

feat: add `status set` subcommand

+113 -1
+113 -1
src/main.rs
··· 5 5 use crate::{ 6 6 auth::{AuthMethod, Authenticator, GenericSession}, 7 7 error::OnyxError, 8 - record::{Artist, Play}, 8 + record::{Artist, Play, PlayView, Status}, 9 9 scrobble::Scrobbler, 10 10 status::StatusManager, 11 11 }; ··· 171 171 AudioScrobbler, 172 172 } 173 173 174 + #[allow(clippy::large_enum_variant)] 174 175 #[derive(Subcommand, Debug)] 175 176 enum StatusCommands { 176 177 /// Display user playing status ··· 186 187 /// Display all status fields 187 188 #[arg(short, long, action)] 188 189 full: bool, 190 + }, 191 + 192 + /// Set user playing status 193 + Set { 194 + /// The name of the track 195 + track_name: String, 196 + 197 + /// The MusicBrainz ID of the track 198 + #[arg(long)] 199 + track_mb_id: Option<String>, 200 + 201 + /// The MusicBrainz ID of the recording 202 + #[arg(long)] 203 + recording_mb_id: Option<String>, 204 + 205 + /// The track duration in seconds 206 + #[arg(short, long)] 207 + duration: Option<i64>, 208 + 209 + /// A comma-separated list of artist name 210 + #[arg(short, long)] 211 + artist_names: Option<String>, 212 + 213 + /// A comma-separated list of artist MusicBrainz IDs 214 + #[arg(long)] 215 + artist_mb_ids: Option<String>, 216 + 217 + /// The name of the release/album 218 + #[arg(short, long)] 219 + release_name: Option<String>, 220 + 221 + /// The MusicBrainz ID of the release/album 222 + #[arg(long)] 223 + release_mb_id: Option<String>, 224 + 225 + /// The URL associated with the track 226 + #[arg(short, long)] 227 + origin_url: Option<String>, 228 + 229 + /// The ISRC accosiated with the recording 230 + #[arg(long)] 231 + isrc: Option<String>, 232 + 233 + /// Time the track was played (RFC 3339 format) 234 + #[arg(short, long)] 235 + played_time: Option<chrono::DateTime<chrono::FixedOffset>>, 236 + 237 + /// Time of status creation, defaults to current time 238 + #[arg(short, long)] 239 + time: Option<chrono::DateTime<chrono::FixedOffset>>, 240 + 241 + /// Time of status expiry, defaults to start time + 10 minutes 242 + #[arg(short, long)] 243 + expiry: Option<chrono::DateTime<chrono::FixedOffset>>, 189 244 }, 190 245 191 246 /// Clear current playing status ··· 407 462 let status_man = StatusManager::new(&ident); 408 463 let status = status_man.get_status().await?; 409 464 status.display(raw, full); 465 + } 466 + StatusCommands::Set { 467 + track_name, 468 + track_mb_id, 469 + recording_mb_id, 470 + duration, 471 + artist_names, 472 + artist_mb_ids, 473 + release_name, 474 + release_mb_id, 475 + origin_url, 476 + isrc, 477 + played_time, 478 + time, 479 + expiry, 480 + } => { 481 + let artists = parse_artist_list(artist_names, artist_mb_ids)?.unwrap_or(Vec::new()); 482 + 483 + let play = PlayView { 484 + track_name, 485 + track_mb_id, 486 + recording_mb_id, 487 + duration, 488 + artists, 489 + release_name, 490 + release_mb_id, 491 + origin_url, 492 + isrc, 493 + played_time, 494 + music_service_base_domain: None, 495 + submission_client_agent: None, 496 + }; 497 + 498 + let time = time.unwrap_or(chrono::Local::now().into()); 499 + 500 + let status = Status { 501 + time, 502 + expiry: Some(expiry.unwrap_or(time + std::time::Duration::from_mins(10))), 503 + item: play, 504 + }; 505 + 506 + let auth = get_auth()?; 507 + let session_info = auth.get_session_info()?; 508 + let session = auth.restore().await?; 509 + 510 + let status_man = StatusManager::new(&session_info.did); 511 + status_man.set_status(session, status).await?; 512 + 513 + println!( 514 + "{}: set status for {}, {}", 515 + "success".green().bold(), 516 + (session_info 517 + .handles 518 + .first() 519 + .unwrap_or(&"(no handle)".red().to_string())), 520 + session_info.did 521 + ); 410 522 } 411 523 StatusCommands::Clear => { 412 524 let auth = get_auth()?;