Scrobble only if playing, print time

This commit is contained in:
Victor 2016-07-18 11:40:48 +03:00
parent 3e13d9be4e
commit 2762b47cd7
2 changed files with 18 additions and 5 deletions

View File

@ -1,15 +1,17 @@
[package]
name = "anmusic"
version = "0.1.0"
version = "0.1.1"
authors = ["aNNiMON <annimon119@gmail.com>"]
[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"
git = "https://bitbucket.org/annimon/rust-aimpremote"
version = "0.1.1"

View File

@ -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);