From 2762b47cd7e9fbb270d1492d71dea0db7b0de161 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 18 Jul 2016 11:40:48 +0300 Subject: [PATCH] Scrobble only if playing, print time --- Cargo.toml | 6 ++++-- src/main.rs | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 70394e7..88d9b15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,17 @@ [package] name = "anmusic" -version = "0.1.0" +version = "0.1.1" authors = ["aNNiMON "] [dependencies] url = "1.0" rust-ini = "*" +chrono = "0.2.22" [dependencies.hyper] version = "0.9" default-features = false [dependencies.aimpremote] -git = "https://bitbucket.org/annimon/rust-aimpremote" \ No newline at end of file +git = "https://bitbucket.org/annimon/rust-aimpremote" +version = "0.1.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1cab1bf..186a290 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,15 @@ extern crate aimpremote; +extern crate chrono; extern crate ini; extern crate hyper; extern crate url; use std::io::Read; -use std::time::Duration; +use std::time::{Duration}; use std::thread; -use aimpremote::TrackInfo; +use aimpremote::{State, TrackInfo}; +use chrono::{Local}; use ini::Ini; use hyper::Client; use hyper::header::{ContentType, Headers}; @@ -67,10 +69,19 @@ fn main() { return } }; + println!("Starting aNMusic"); + let update_duration = Duration::from_secs(60 * time as u64); + let update_duration_if_paused = Duration::from_secs(10); loop { + while { + let state = aimpremote::get_state().unwrap_or(State::Stopped); + (state == State::Stopped) || (state == State::Paused) + } { + thread::sleep(update_duration_if_paused); + } if let Some(track) = aimpremote::aimp_track_info() { - println!("{} - {}", track.artist, track.title); + println!("[{}] {} - {}", Local::now().format("%H:%M").to_string(), track.artist, track.title); let result = send_track_info(login.clone(), token.clone(), track); if result.starts_with("{\"error") { println!("{}", result);