summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-01-02 17:36:50 +0000
committerdakkar <dakkar@thenautilus.net>2018-01-02 17:36:50 +0000
commit359821f1bc3d201abceb6d095c17d54dc5293045 (patch)
treeb0ceaaae92e2b3ec275f7e1a8e76544254ed2d3a
parentbetter structure, and test, for License (diff)
downloadUltramarine-359821f1bc3d201abceb6d095c17d54dc5293045.tar.gz
Ultramarine-359821f1bc3d201abceb6d095c17d54dc5293045.tar.bz2
Ultramarine-359821f1bc3d201abceb6d095c17d54dc5293045.zip
make MusicFile work with non-absolute paths
-rw-r--r--lib/Ultramarine/Model/MusicFile.pm63
-rw-r--r--t/tests/model/music-file.t31
2 files changed, 12 insertions, 22 deletions
diff --git a/lib/Ultramarine/Model/MusicFile.pm6 b/lib/Ultramarine/Model/MusicFile.pm6
index 0370310..7c3ccd1 100644
--- a/lib/Ultramarine/Model/MusicFile.pm6
+++ b/lib/Ultramarine/Model/MusicFile.pm6
@@ -3,9 +3,10 @@ use JSON::Fast;
class Ultramarine::Model::MusicFile {
has $.path is required;
+ submethod BUILD(IO() :$!path!) {}
method metadata() {
- my $proc = run 'avprobe', '-show_format','-of', 'json', $.path,
+ my $proc = run 'avprobe', '-show_format','-of', 'json', $.path.absolute,
:err,:out;
CATCH { when X::Proc::Unsuccessful { return %() } }
my $json-str = $proc.out.slurp(:close);
diff --git a/t/tests/model/music-file.t b/t/tests/model/music-file.t
index 2016f8e..845a88d 100644
--- a/t/tests/model/music-file.t
+++ b/t/tests/model/music-file.t
@@ -5,28 +5,17 @@ use Ultramarine::Model::MusicFile;
# test file generated with:
# avconv -ac 2 -ar 44100 -f s16le -i /dev/zero -t 1 -q 0 -metadata title="some title" -metadata artist="some artist" test.mp3
-my Ultramarine::Model::MusicFile $mf .= new(:path('t/data/test.mp3'));
-my $data = $mf.metadata;
+# this way we test that MusicFile passes a usable path to avprobe, not
+# just the .Str
+my $path = IO::Path.new('test.mp3',:CWD('t/data/'));
+my Ultramarine::Model::MusicFile $mf .= new(:$path);
+my %data = $mf.metadata;
-is-deeply(
- $data,
- %(
- :bit_rate("33633.000000"),
- :duration("1.044898"),
- :filename("t/data/test.mp3"),
- :format_long_name("MP2/3 (MPEG audio layer 2/3)"),
- :format_name("mp3"),
- :nb_streams(1),
- :size("4393.000000"),
- :start_time("0.000000"),
- :tags(%(
- :artist("some artist"),
- :encoder("Lavf56.1.0"),
- :title("some title"),
- )),
- ),
- 'metadata should match',
-);
+is-approx(%data<bit_rate>.Num,33633,:1abs-tol,'bit rate should match');
+is-approx(%data<duration>.Num,1,:1abs-tol,'length should match');
+is(%data<format_name>,'mp3','format should match');
+is(%data<tags><artist>,'some artist','artist should match');
+is(%data<tags><title>,'some title','title should match');
done-testing;