musk 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/musk.rb +1 -0
- data/lib/musk/track.rb +4 -6
- data/lib/musk/track_adapter.rb +56 -0
- data/lib/musk/track_loader.rb +15 -29
- data/lib/musk/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d3cfe8d2f4b025504f856f58912b4dbb2dc806b
|
4
|
+
data.tar.gz: fef5e17b70ea89e296e4734dab2ed4c1c22833e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06954d894d0a0c26b3b7db4bd502e9ec458e4d431ca8fbc90302123afd60e0348af85a98c6fc6e1d82fd91b4e57b7352069ee68b05a2038e6566d01dc8bb44fe
|
7
|
+
data.tar.gz: ba57a7874101c727a5ecc5195fcfc2f6cc94556f4931aa272bdffb235134e937f2fda3727299aad4741c451555c832e721f6eb116bb46d2764af92448162d1d5
|
data/Gemfile.lock
CHANGED
data/lib/musk.rb
CHANGED
data/lib/musk/track.rb
CHANGED
@@ -15,14 +15,12 @@ module Musk
|
|
15
15
|
|
16
16
|
attr_accessor *ATTRIBUTES
|
17
17
|
|
18
|
-
def attributes
|
19
|
-
|
18
|
+
def initialize(attributes = {})
|
19
|
+
attributes.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
20
20
|
end
|
21
21
|
|
22
|
-
def attributes
|
23
|
-
|
24
|
-
send("#{key}=", value) if respond_to?("#{key}=")
|
25
|
-
end
|
22
|
+
def attributes
|
23
|
+
Hash[ATTRIBUTES.map { |a| [a, send("#{a}")] }]
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Musk
|
2
|
+
class TrackAdapter
|
3
|
+
def self.adapt(tag)
|
4
|
+
new(tag).adapt
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(tag)
|
8
|
+
@tag = tag
|
9
|
+
end
|
10
|
+
|
11
|
+
def adapt
|
12
|
+
Musk::Track.new(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def attributes
|
18
|
+
Musk::Track::ATTRIBUTES.inject({}) do |hash, attribute|
|
19
|
+
hash[attribute] = send(attribute) if respond_to?(attribute, true)
|
20
|
+
hash
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def number
|
25
|
+
@tag.frame_list("TRCK").first.to_s.split("/").first
|
26
|
+
end
|
27
|
+
|
28
|
+
def number_of
|
29
|
+
@tag.frame_list("TRCK").first.to_s.split("/").last
|
30
|
+
end
|
31
|
+
|
32
|
+
def title
|
33
|
+
@tag.title
|
34
|
+
end
|
35
|
+
|
36
|
+
def artist
|
37
|
+
@tag.artist
|
38
|
+
end
|
39
|
+
|
40
|
+
def release
|
41
|
+
@tag.album
|
42
|
+
end
|
43
|
+
|
44
|
+
def genre
|
45
|
+
@tag.genre
|
46
|
+
end
|
47
|
+
|
48
|
+
def year
|
49
|
+
@tag.year.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def comment
|
53
|
+
@tag.comment
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/musk/track_loader.rb
CHANGED
@@ -31,45 +31,31 @@ module Musk
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
34
|
+
def create_tracks
|
35
|
+
Dir[deeppath].map do |filepath|
|
36
|
+
TagLib::MPEG::File.open(filepath) do |file|
|
37
|
+
Musk::TrackAdapter.adapt(file.id3v2_tag).tap do |track|
|
38
|
+
track.loadpath = loadpath
|
39
|
+
track.fullpath = filepath
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
36
43
|
end
|
37
44
|
|
38
|
-
def
|
39
|
-
@
|
45
|
+
def deeppath
|
46
|
+
@deeppath ||= File.file?(fullpath) ? fullpath : File.join(fullpath, "**", "*.mp3")
|
40
47
|
end
|
41
48
|
|
42
49
|
def loadpath
|
43
50
|
@loadpath ||= "#{File.file?(fullpath) ? basepath : fullpath}#{File::SEPARATOR}"
|
44
51
|
end
|
45
52
|
|
46
|
-
def
|
47
|
-
@
|
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)
|
54
|
-
end
|
55
|
-
end
|
53
|
+
def basepath
|
54
|
+
@basepath ||= File.dirname(fullpath)
|
56
55
|
end
|
57
56
|
|
58
|
-
def
|
59
|
-
|
60
|
-
track.attributes = {
|
61
|
-
loadpath: loadpath,
|
62
|
-
fullpath: filepath,
|
63
|
-
number: tag.frame_list("TRCK").first.to_s.split("/").first,
|
64
|
-
number_of: tag.frame_list("TRCK").first.to_s.split("/").last,
|
65
|
-
title: tag.title,
|
66
|
-
artist: tag.artist,
|
67
|
-
release: tag.album,
|
68
|
-
genre: tag.genre,
|
69
|
-
year: tag.year.to_s,
|
70
|
-
comment: tag.comment,
|
71
|
-
}
|
72
|
-
end
|
57
|
+
def fullpath
|
58
|
+
@fullpath ||= File.expand_path(@path)
|
73
59
|
end
|
74
60
|
end
|
75
61
|
end
|
data/lib/musk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: musk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Pempel
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/musk/formatter/csv.rb
|
60
60
|
- lib/musk/formatter/pretty.rb
|
61
61
|
- lib/musk/track.rb
|
62
|
+
- lib/musk/track_adapter.rb
|
62
63
|
- lib/musk/track_loader.rb
|
63
64
|
- lib/musk/track_printer.rb
|
64
65
|
- lib/musk/version.rb
|