musk 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/musk/decorator/printable_track.rb +29 -9
- data/lib/musk/track.rb +2 -2
- data/lib/musk/track_loader.rb +38 -25
- data/lib/musk/version.rb +1 -1
- data/spec/lib/musk/decorator/printable_track_spec.rb +7 -7
- data/spec/lib/musk/track_spec.rb +4 -4
- data/spec/support/factories/tracks.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1609e780b7c7837ccd4b98100a6e350261f2ebd
|
4
|
+
data.tar.gz: d4cc00ca5b1fe8353cda02ade420cb22a0f0d9bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53c425a51d2fde4f633dfbee9133a6754364d7025ee506a44803b75eed93b64ba2715f6078e361fa67d8e4128af1e1ecc059a86e4a02b7bd29163e96d4100ba1
|
7
|
+
data.tar.gz: 707e0862f0fa78c0e0c80452943578959a90eea99de746abd645a4ae3cbd5c8c06f301d6625ed8c37c83ed5e942cf78bd5faeb86688d735a11b4138a05dd24a1
|
data/Gemfile.lock
CHANGED
@@ -10,19 +10,39 @@ module Musk
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def position
|
13
|
-
"#{
|
13
|
+
"#{number}/#{number_of}"
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
[nil, 0, "0"].include?(@track.send(method)) ? "-" : @track.send(method)
|
19
|
-
end
|
16
|
+
def number
|
17
|
+
[nil, 0, "0"].include?(@track.number) ? "-" : @track.number
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
def number_of
|
21
|
+
[nil, 0, "0"].include?(@track.number_of) ? "-" : @track.number_of
|
22
|
+
end
|
23
|
+
|
24
|
+
def year
|
25
|
+
[nil, 0, "0"].include?(@track.year) ? "-" : @track.year
|
26
|
+
end
|
27
|
+
|
28
|
+
def comment
|
29
|
+
[nil, 0, "0"].include?(@track.comment) ? "-" : @track.comment
|
30
|
+
end
|
31
|
+
|
32
|
+
def title
|
33
|
+
@track.title or "-"
|
34
|
+
end
|
35
|
+
|
36
|
+
def artist
|
37
|
+
@track.artist or "-"
|
38
|
+
end
|
39
|
+
|
40
|
+
def release
|
41
|
+
@track.release or "-"
|
42
|
+
end
|
43
|
+
|
44
|
+
def genre
|
45
|
+
@track.genre or "-"
|
26
46
|
end
|
27
47
|
end
|
28
48
|
end
|
data/lib/musk/track.rb
CHANGED
data/lib/musk/track_loader.rb
CHANGED
@@ -11,13 +11,13 @@ module Musk
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def load!
|
14
|
-
|
15
|
-
create_tracks
|
14
|
+
verify_path!
|
15
|
+
create_tracks
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def
|
20
|
+
def verify_path!
|
21
21
|
unless @path and @path.length > 0
|
22
22
|
raise "Undefined path to a file or files"
|
23
23
|
end
|
@@ -31,29 +31,42 @@ module Musk
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
track.comment = tag.comment
|
34
|
+
def fullpath
|
35
|
+
@fullpath ||= File.expand_path(@path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def basepath
|
39
|
+
@basepath ||= File.dirname(fullpath)
|
40
|
+
end
|
41
|
+
|
42
|
+
def loadpath
|
43
|
+
@loadpath ||= "#{File.file?(fullpath) ? basepath : fullpath}#{File::SEPARATOR}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def deeppath
|
47
|
+
@deeppath ||= File.file?(fullpath) ? fullpath : File.join(fullpath, "**", "*.mp3")
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_tracks
|
51
|
+
Dir[deeppath].map do |filepath|
|
52
|
+
TagLib::MPEG::File.open(filepath) do |file|
|
53
|
+
create_track(filepath, file.id3v2_tag)
|
55
54
|
end
|
56
|
-
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_track(filepath, tag)
|
59
|
+
Musk::Track.new.tap do |track|
|
60
|
+
track.loadpath = loadpath
|
61
|
+
track.fullpath = filepath
|
62
|
+
track.number = tag.frame_list("TRCK").first.to_s.split("/").first
|
63
|
+
track.number_of = tag.frame_list("TRCK").first.to_s.split("/").last
|
64
|
+
track.title = tag.title.to_s
|
65
|
+
track.artist = tag.artist.to_s
|
66
|
+
track.release = tag.album.to_s
|
67
|
+
track.genre = tag.genre.to_s
|
68
|
+
track.year = tag.year.to_s
|
69
|
+
track.comment = tag.comment.to_s
|
57
70
|
end
|
58
71
|
end
|
59
72
|
end
|
data/lib/musk/version.rb
CHANGED
@@ -14,20 +14,20 @@ describe Musk::Decorator::PrintableTrack do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#position" do
|
17
|
-
it "should return '{
|
17
|
+
it "should return '{number}/{number_of}'" do
|
18
18
|
track = described_class.new(build(:track))
|
19
|
-
allow(track).to receive(:
|
20
|
-
allow(track).to receive(:
|
19
|
+
allow(track).to receive(:number).and_return(1)
|
20
|
+
allow(track).to receive(:number_of).and_return(2)
|
21
21
|
position = track.position
|
22
22
|
position.should eq("1/2")
|
23
|
-
expect(track).to have_received(:
|
24
|
-
expect(track).to have_received(:
|
23
|
+
expect(track).to have_received(:number)
|
24
|
+
expect(track).to have_received(:number_of)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it_should_behave_like "the track decorator with zeroable attributes", [
|
29
|
-
:
|
30
|
-
:
|
29
|
+
:number,
|
30
|
+
:number_of,
|
31
31
|
:comment,
|
32
32
|
:year,
|
33
33
|
]
|
data/spec/lib/musk/track_spec.rb
CHANGED
@@ -7,10 +7,10 @@ describe Musk::Track do
|
|
7
7
|
it { should respond_to(:fullpath=) }
|
8
8
|
it { should respond_to(:title) }
|
9
9
|
it { should respond_to(:title=) }
|
10
|
-
it { should respond_to(:
|
11
|
-
it { should respond_to(:
|
12
|
-
it { should respond_to(:
|
13
|
-
it { should respond_to(:
|
10
|
+
it { should respond_to(:number) }
|
11
|
+
it { should respond_to(:number=) }
|
12
|
+
it { should respond_to(:number_of) }
|
13
|
+
it { should respond_to(:number_of=) }
|
14
14
|
it { should respond_to(:artist) }
|
15
15
|
it { should respond_to(:artist=) }
|
16
16
|
it { should respond_to(:release) }
|
@@ -6,12 +6,12 @@ FactoryGirl.define do
|
|
6
6
|
loadpath ENV["MUSK_TRACKS_PATH"]
|
7
7
|
fullpath File.join(ENV["MUSK_TRACKS_PATH"], "bonobo/jets.mp3")
|
8
8
|
title "Jets"
|
9
|
-
|
10
|
-
|
9
|
+
number "6"
|
10
|
+
number_of "13"
|
11
11
|
artist "Bonobo"
|
12
12
|
release "The North Borders"
|
13
13
|
genre "Electronic"
|
14
|
-
year 2013
|
14
|
+
year "2013"
|
15
15
|
|
16
16
|
trait :loaded do
|
17
17
|
comment "0"
|
@@ -22,12 +22,12 @@ FactoryGirl.define do
|
|
22
22
|
loadpath ENV["MUSK_TRACKS_PATH"]
|
23
23
|
fullpath File.join(ENV["MUSK_TRACKS_PATH"], "emancipator/kamakura.mp3")
|
24
24
|
title "Kamakura"
|
25
|
-
|
26
|
-
|
25
|
+
number "4"
|
26
|
+
number_of "14"
|
27
27
|
artist "Emancipator"
|
28
28
|
release "Safe In The Steep Cliffs"
|
29
29
|
genre "Electronic"
|
30
|
-
year 2010
|
30
|
+
year "2010"
|
31
31
|
|
32
32
|
trait :loaded do
|
33
33
|
comment "0"
|