Skip to content

Commit

Permalink
Merge pull request #67 from naglis/improve-song-duration
Browse files Browse the repository at this point in the history
Use `duration` tag instead of `Time` for song duration
  • Loading branch information
kstep authored Dec 27, 2023
2 parents 6ec7da3 + 9862108 commit 216cdcd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/song.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ impl FromIter for Song {
"Last-Modified" => result.last_mod = Some(line.1.to_owned()),
"Artist" => result.artist = Some(line.1.to_owned()),
"Name" => result.name = Some(line.1.to_owned()),
"Time" => result.duration = Some(Duration::from_secs(line.1.parse()?)),
// Deprecated in MPD.
"Time" => (),
"duration" => result.duration = Some(Duration::from_secs_f64(line.1.parse()?)),
"Range" => result.range = Some(line.1.parse()?),
"Id" => match result.place {
None => result.place = Some(QueuePlace { id: Id(line.1.parse()?), pos: 0, prio: 0 }),
Expand Down
Binary file removed tests/data/empty.flac
Binary file not shown.
Binary file added tests/data/silence.flac
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/helpers/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn sleep() {
thread::sleep(ten_millis);
}

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

impl Daemon {
pub fn start() -> Daemon {
Expand All @@ -97,7 +97,7 @@ impl Daemon {
config.generate();

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

let process = Command::new("mpd")
.arg("--no-daemon")
Expand Down
14 changes: 14 additions & 0 deletions tests/song.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extern crate mpd;

mod helpers;
use std::time::Duration;

use helpers::connect;
use mpd::Song;

#[test]
fn currentsong() {
Expand All @@ -20,6 +23,17 @@ fn queue() {
assert_eq!(songs, queue);
}

#[test]
fn lsinfo() {
let mut mpd = connect();
let songs = mpd.lsinfo(Song { file: "silence.flac".into(), ..Default::default() }).unwrap();
assert_eq!(songs.len(), 1);

let song = songs.get(0).unwrap();
assert_eq!(song.file, "silence.flac");
assert_eq!(song.duration.expect("song should have duration"), Duration::from_millis(500));
}

#[test]
fn rescan_update() {
let mut mpd = connect();
Expand Down
4 changes: 2 additions & 2 deletions tests/stickers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fn set_sticker() {

static VALUE: &str = "value";

mpd.set_sticker("song", "empty.flac", "test_sticker", VALUE).unwrap();
mpd.set_sticker("song", "silence.flac", "test_sticker", VALUE).unwrap();

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

0 comments on commit 216cdcd

Please sign in to comment.