Skip to content

Commit 216cdcd

Browse files
authored
Merge pull request #67 from naglis/improve-song-duration
Use `duration` tag instead of `Time` for song duration
2 parents 6ec7da3 + 9862108 commit 216cdcd

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/song.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ impl FromIter for Song {
117117
"Last-Modified" => result.last_mod = Some(line.1.to_owned()),
118118
"Artist" => result.artist = Some(line.1.to_owned()),
119119
"Name" => result.name = Some(line.1.to_owned()),
120-
"Time" => result.duration = Some(Duration::from_secs(line.1.parse()?)),
120+
// Deprecated in MPD.
121+
"Time" => (),
122+
"duration" => result.duration = Some(Duration::from_secs_f64(line.1.parse()?)),
121123
"Range" => result.range = Some(line.1.parse()?),
122124
"Id" => match result.place {
123125
None => result.place = Some(QueuePlace { id: Id(line.1.parse()?), pos: 0, prio: 0 }),

tests/data/empty.flac

-8.09 KB
Binary file not shown.

tests/data/silence.flac

154 Bytes
Binary file not shown.

tests/helpers/daemon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn sleep() {
8888
thread::sleep(ten_millis);
8989
}
9090

91-
static EMPTY_FLAC_BYTES: &[u8] = include_bytes!("../data/empty.flac");
91+
static EMPTY_FLAC_BYTES: &[u8] = include_bytes!("../data/silence.flac");
9292

9393
impl Daemon {
9494
pub fn start() -> Daemon {
@@ -97,7 +97,7 @@ impl Daemon {
9797
config.generate();
9898

9999
// TODO: Factor out putting files in the music directory.
100-
File::create(config.music_directory.join("empty.flac")).unwrap().write_all(EMPTY_FLAC_BYTES).unwrap();
100+
File::create(config.music_directory.join("silence.flac")).unwrap().write_all(EMPTY_FLAC_BYTES).unwrap();
101101

102102
let process = Command::new("mpd")
103103
.arg("--no-daemon")

tests/song.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
extern crate mpd;
22

33
mod helpers;
4+
use std::time::Duration;
5+
46
use helpers::connect;
7+
use mpd::Song;
58

69
#[test]
710
fn currentsong() {
@@ -20,6 +23,17 @@ fn queue() {
2023
assert_eq!(songs, queue);
2124
}
2225

26+
#[test]
27+
fn lsinfo() {
28+
let mut mpd = connect();
29+
let songs = mpd.lsinfo(Song { file: "silence.flac".into(), ..Default::default() }).unwrap();
30+
assert_eq!(songs.len(), 1);
31+
32+
let song = songs.get(0).unwrap();
33+
assert_eq!(song.file, "silence.flac");
34+
assert_eq!(song.duration.expect("song should have duration"), Duration::from_millis(500));
35+
}
36+
2337
#[test]
2438
fn rescan_update() {
2539
let mut mpd = connect();

tests/stickers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ fn set_sticker() {
1010

1111
static VALUE: &str = "value";
1212

13-
mpd.set_sticker("song", "empty.flac", "test_sticker", VALUE).unwrap();
13+
mpd.set_sticker("song", "silence.flac", "test_sticker", VALUE).unwrap();
1414

15-
let sticker = mpd.sticker("song", "empty.flac", "test_sticker").unwrap();
15+
let sticker = mpd.sticker("song", "silence.flac", "test_sticker").unwrap();
1616
assert_eq!(sticker, VALUE);
1717
}

0 commit comments

Comments
 (0)