easytag 0.2.0 → 0.3.0
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/CHANGELOG.md +19 -1
- data/easytag.gemspec +5 -1
- data/lib/easytag/attributes.rb +0 -0
- data/lib/easytag/attributes/base.rb +103 -0
- data/lib/easytag/attributes/mp3.rb +382 -0
- data/lib/easytag/attributes/mp4.rb +309 -0
- data/lib/easytag/interfaces/mp3.rb +24 -157
- data/lib/easytag/interfaces/mp4.rb +7 -175
- data/lib/easytag/version.rb +1 -1
- data/test/test_consistency.rb +8 -2
- data/test/test_mp3.rb +13 -13
- data/test/test_mp4.rb +1 -1
- data/test/test_util.rb +5 -0
- metadata +10 -5
@@ -1,188 +1,20 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'easytag/attributes/mp4'
|
4
|
+
|
3
5
|
module EasyTag::Interfaces
|
4
6
|
class MP4 < Base
|
5
|
-
# type of TagLib::MP4::Item
|
6
|
-
module ItemType
|
7
|
-
STRING = 0 # not part of TagLib::MP4::Item, just for convenience
|
8
|
-
STRING_LIST = 1
|
9
|
-
BOOL = 2
|
10
|
-
INT = 3
|
11
|
-
INT_PAIR = 4
|
12
|
-
COVER_ART_LIST = 5
|
13
|
-
end
|
14
|
-
|
15
|
-
ITEM_LIST_KEY_MAP = {
|
16
|
-
:aart => 'aART', # Album Artist
|
17
|
-
:akid => 'akID',
|
18
|
-
:apid => 'apID', # Apple ID
|
19
|
-
:atid => 'atID',
|
20
|
-
:cnid => 'cnID',
|
21
|
-
:covr => 'covr', # Cover Art
|
22
|
-
:cpil => 'cpil',
|
23
|
-
:cprt => 'cprt',
|
24
|
-
:disk => 'disk', # Disk [num, total]
|
25
|
-
:geid => 'geID',
|
26
|
-
:pgap => 'pgap',
|
27
|
-
:plid => 'plID',
|
28
|
-
:purd => 'purd', # Purchase Date
|
29
|
-
:rtng => 'rtng',
|
30
|
-
:sfid => 'sfID',
|
31
|
-
:stik => 'stik',
|
32
|
-
:trkn => 'trkn', # Track [num, total]
|
33
|
-
:art => '©ART', # Track Artist
|
34
|
-
:alb => '©alb', # Album
|
35
|
-
:cmt => '©cmt', # Comments
|
36
|
-
:day => '©day', # Release Date
|
37
|
-
# (ex: 2006, 2004-08-10, 2007-11-27T08:00:00Z)
|
38
|
-
:gen => '©gen', # Genre
|
39
|
-
:nam => '©nam', # Title
|
40
|
-
:too => '©too', # Encoder
|
41
|
-
:soaa => 'soaa', # Sort Order - Album Artist
|
42
|
-
:soar => 'soar', # Sort Order - Track Artist
|
43
|
-
}
|
44
|
-
|
45
7
|
def initialize(file)
|
46
8
|
@info = TagLib::MP4::File.new(file)
|
47
|
-
@tag = @info.tag
|
48
|
-
end
|
49
|
-
|
50
|
-
def title
|
51
|
-
obj_for_item_key(:nam, ItemType::STRING)
|
52
|
-
end
|
53
|
-
|
54
|
-
def title_sort_order
|
55
|
-
obj_for_item_key(:sonm, ItemType::STRING)
|
56
|
-
end
|
57
|
-
|
58
|
-
def artist
|
59
|
-
obj_for_item_key(:art, ItemType::STRING)
|
60
|
-
end
|
61
|
-
|
62
|
-
def artist_sort_order
|
63
|
-
obj_for_item_key(:soar, ItemType::STRING)
|
64
|
-
end
|
65
|
-
|
66
|
-
def album_artist
|
67
|
-
obj_for_item_key(:aart, ItemType::STRING)
|
68
|
-
end
|
69
|
-
|
70
|
-
def album_artist_sort_order
|
71
|
-
obj_for_item_key(:soaa, ItemType::STRING)
|
72
|
-
end
|
73
|
-
|
74
|
-
def album
|
75
|
-
obj_for_item_key(:alb, ItemType::STRING)
|
76
|
-
end
|
77
|
-
|
78
|
-
def album_sort_order
|
79
|
-
obj_for_item_key(:soal, ItemType::STRING)
|
80
|
-
end
|
81
|
-
|
82
|
-
def genre
|
83
|
-
obj_for_item_key(:gen, ItemType::STRING)
|
84
|
-
end
|
85
|
-
|
86
|
-
def comments
|
87
|
-
obj_for_item_key(:cmt, ItemType::STRING)
|
88
|
-
end
|
89
|
-
|
90
|
-
# because :day can be anything, including a year, or an exact date,
|
91
|
-
# we'll let #date do the parsing, and just grab the year from it
|
92
|
-
def year
|
93
|
-
date.nil? ? 0 : date.year
|
94
|
-
end
|
95
|
-
|
96
|
-
def date
|
97
|
-
return @date unless @date.nil?
|
98
|
-
|
99
|
-
date_str = obj_for_item_key(:day, ItemType::STRING)
|
100
|
-
@date ||= EasyTag::Utilities.get_datetime(date_str)
|
101
|
-
end
|
102
|
-
|
103
|
-
def album_art
|
104
|
-
return @album_art unless @album_art.nil?
|
105
|
-
|
106
|
-
@album_art = []
|
107
|
-
covers = obj_for_item_key(:covr, ItemType::COVER_ART_LIST) || []
|
108
|
-
covers.each do |cover|
|
109
|
-
@album_art << EasyTag::Image.new(cover.data)
|
110
|
-
end
|
111
|
-
|
112
|
-
@album_art
|
113
|
-
end
|
114
|
-
|
115
|
-
def apple_id
|
116
|
-
obj_for_item_key(:apid, ItemType::STRING)
|
117
|
-
end
|
118
|
-
|
119
|
-
def track_num
|
120
|
-
obj_for_item_key(:trkn, ItemType::INT_PAIR) || [0, 0]
|
121
|
-
end
|
122
|
-
|
123
|
-
def disc_num
|
124
|
-
obj_for_item_key(:disk, ItemType::INT_PAIR) || [0, 0]
|
125
|
-
end
|
126
|
-
|
127
|
-
def user_info
|
128
|
-
return @user_info unless @user_info.nil?
|
129
|
-
|
130
|
-
@user_info = {}
|
131
|
-
@tag.item_list_map.to_a.each do |key, value|
|
132
|
-
match_data = key.match(/\:com.apple.iTunes\:(.*)/)
|
133
|
-
if match_data
|
134
|
-
key = EasyTag::Utilities.normalize_string(match_data[1])
|
135
|
-
@user_info[key.to_sym] = value.to_string_list[0]
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
@user_info
|
140
|
-
end
|
141
|
-
|
142
|
-
def disc_subtitle
|
143
|
-
user_info[:discsubtitle]
|
144
|
-
end
|
145
|
-
|
146
|
-
def media
|
147
|
-
user_info[:media]
|
148
9
|
end
|
149
10
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
def lookup_item(key)
|
156
|
-
item_id = ITEM_LIST_KEY_MAP.fetch(key, nil)
|
157
|
-
@tag.item_list_map.fetch(item_id) unless item_id.nil?
|
158
|
-
end
|
159
|
-
|
160
|
-
def item_to_obj(item, item_type)
|
161
|
-
case item_type
|
162
|
-
when ItemType::STRING
|
163
|
-
item.to_string_list[0]
|
164
|
-
when ItemType::STRING_LIST
|
165
|
-
item.to_string_list
|
166
|
-
when ItemType::BOOL
|
167
|
-
item.to_bool
|
168
|
-
when ItemType::INT
|
169
|
-
item.to_int
|
170
|
-
when ItemType::INT_PAIR
|
171
|
-
item.to_int_pair
|
172
|
-
when ItemType::COVER_ART_LIST
|
173
|
-
item.to_cover_art_list
|
174
|
-
else
|
175
|
-
nil
|
11
|
+
EasyTag::Attributes::MP4_ATTRIB_ARGS.each do |attrib_args|
|
12
|
+
attrib = EasyTag::Attributes::MP4Attribute.new(attrib_args)
|
13
|
+
define_method(attrib.name) do
|
14
|
+
instance_variable_get(attrib.ivar) ||
|
15
|
+
instance_variable_set(attrib.ivar, attrib.call(self))
|
176
16
|
end
|
177
17
|
end
|
178
18
|
|
179
|
-
def obj_for_item_key(item_key, item_type)
|
180
|
-
return nil if @tag.nil?
|
181
|
-
|
182
|
-
item = lookup_item(item_key)
|
183
|
-
o = item_to_obj(item, item_type) unless item.nil?
|
184
|
-
|
185
|
-
Base.obj_or_nil(o)
|
186
|
-
end
|
187
19
|
end
|
188
20
|
end
|
data/lib/easytag/version.rb
CHANGED
data/test/test_consistency.rb
CHANGED
@@ -15,11 +15,13 @@ class TestConsistencyMP301 < Test::Unit::TestCase
|
|
15
15
|
assert_equal('Artist Name Here', @mp3.artist)
|
16
16
|
assert_equal('Album Artist Here', @mp3.album_artist)
|
17
17
|
assert_equal('Album Name Here', @mp3.album)
|
18
|
-
assert_equal('This is my comment.', @mp3.
|
18
|
+
assert_equal('This is my comment.', @mp3.comment)
|
19
19
|
assert_equal('Polka', @mp3.genre)
|
20
20
|
assert_equal(1941, @mp3.year)
|
21
21
|
assert_equal([5, 0], @mp3.track_num)
|
22
22
|
assert_equal([3, 0], @mp3.disc_num)
|
23
|
+
assert_equal(false, @mp3.compilation?)
|
24
|
+
assert_equal(0, @mp3.bpm)
|
23
25
|
end
|
24
26
|
|
25
27
|
def test_date
|
@@ -95,7 +97,7 @@ class TestConsistencyMP302 < Test::Unit::TestCase
|
|
95
97
|
#[nil, @mp3.album_artist_sort_order],
|
96
98
|
['Speakerboxxx / The Love Below', @mp3.album],
|
97
99
|
[nil, @mp3.album_sort_order],
|
98
|
-
[
|
100
|
+
[[], @mp3.comments],
|
99
101
|
[nil, @mp3.genre],
|
100
102
|
[2003, @mp3.year],
|
101
103
|
[[8, 21], @mp3.track_num],
|
@@ -103,6 +105,8 @@ class TestConsistencyMP302 < Test::Unit::TestCase
|
|
103
105
|
['The Love Below', @mp3.disc_subtitle],
|
104
106
|
['CD', @mp3.media],
|
105
107
|
['Arista', @mp3.label],
|
108
|
+
[true, @mp3.compilation?],
|
109
|
+
[0, @mp3.bpm],
|
106
110
|
]
|
107
111
|
|
108
112
|
cases.each do |c|
|
@@ -157,6 +161,8 @@ class TestConsistency02 < Test::Unit::TestCase
|
|
157
161
|
:disc_subtitle,
|
158
162
|
:media,
|
159
163
|
:label,
|
164
|
+
:compilation?,
|
165
|
+
:bpm,
|
160
166
|
]
|
161
167
|
|
162
168
|
cases.each do |c|
|
data/test/test_mp3.rb
CHANGED
@@ -10,17 +10,17 @@ class TestID3v1OnlyMP3 < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_tags
|
13
|
-
assert_equal('Track Title',
|
14
|
-
assert_equal('Track Artist',
|
15
|
-
assert_equal('Album Name',
|
16
|
-
assert_equal('this is a comment', @f.comments)
|
17
|
-
assert_equal('Swing',
|
18
|
-
assert_equal(1988,
|
19
|
-
assert_equal(1988,
|
20
|
-
assert_equal(true,
|
21
|
-
assert_equal(nil,
|
22
|
-
assert_equal([3, 0],
|
23
|
-
assert_equal([0, 0],
|
13
|
+
assert_equal('Track Title', @f.title)
|
14
|
+
assert_equal('Track Artist', @f.artist)
|
15
|
+
assert_equal('Album Name', @f.album)
|
16
|
+
assert_equal(['this is a comment'], @f.comments)
|
17
|
+
assert_equal('Swing', @f.genre)
|
18
|
+
assert_equal(1988, @f.year)
|
19
|
+
assert_equal(1988, @f.date.year)
|
20
|
+
assert_equal(true, @f.album_art.empty?)
|
21
|
+
assert_equal(nil, @f.apple_id)
|
22
|
+
assert_equal([3, 0], @f.track_num)
|
23
|
+
assert_equal([0, 0], @f.disc_num)
|
24
24
|
|
25
25
|
end
|
26
26
|
end
|
@@ -34,7 +34,7 @@ class TestID3v2OnlyMP3 < Test::Unit::TestCase
|
|
34
34
|
assert_equal('Track Title', @f.title)
|
35
35
|
assert_equal('Track Artist', @f.artist)
|
36
36
|
assert_equal('Album Name', @f.album)
|
37
|
-
assert_equal('this is a comment', @f.
|
37
|
+
assert_equal('this is a comment', @f.comment)
|
38
38
|
assert_equal('Swing', @f.genre)
|
39
39
|
assert_equal(1988, @f.year)
|
40
40
|
assert_equal(1988, @f.date.year)
|
@@ -56,7 +56,7 @@ class TestNoTagsMP3 < Test::Unit::TestCase
|
|
56
56
|
assert_equal(nil, @f.artist)
|
57
57
|
assert_equal(nil, @f.album)
|
58
58
|
assert_equal(nil, @f.album_artist)
|
59
|
-
assert_equal(
|
59
|
+
assert_equal([], @f.comments)
|
60
60
|
assert_equal(nil, @f.genre)
|
61
61
|
assert_equal(0, @f.year)
|
62
62
|
assert_equal(nil, @f.date)
|
data/test/test_mp4.rb
CHANGED
@@ -14,7 +14,7 @@ class TestNoTagsMP4 < Test::Unit::TestCase
|
|
14
14
|
assert_equal(nil, @f.artist)
|
15
15
|
assert_equal(nil, @f.album)
|
16
16
|
assert_equal(nil, @f.album_artist)
|
17
|
-
assert_equal(
|
17
|
+
assert_equal([], @f.comments)
|
18
18
|
assert_equal(nil, @f.genre)
|
19
19
|
assert_equal(0, @f.year)
|
20
20
|
assert_equal(nil, @f.date)
|
data/test/test_util.rb
CHANGED
@@ -31,6 +31,11 @@ class TestUtilities < Test::Unit::TestCase
|
|
31
31
|
assert_equal(7, date.day)
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_get_datetime04
|
35
|
+
date = EasyTag::Utilities.get_datetime('')
|
36
|
+
assert_equal(nil, date)
|
37
|
+
end
|
38
|
+
|
34
39
|
def test_get_int_pair
|
35
40
|
assert_equal([0, 0], EasyTag::Utilities.get_int_pair(''))
|
36
41
|
assert_equal([0, 0], EasyTag::Utilities.get_int_pair(nil))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easytag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Lucas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|
@@ -66,8 +66,10 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: |
|
70
|
-
|
69
|
+
description: |2
|
70
|
+
EasyTag is an abstraction layer to the TagLib audio tagging library.
|
71
|
+
It is designed to provide a simple and consistent API regardless
|
72
|
+
of file format being read.
|
71
73
|
email:
|
72
74
|
- chris@chrisjlucas.com
|
73
75
|
executables: []
|
@@ -81,6 +83,10 @@ files:
|
|
81
83
|
- Rakefile
|
82
84
|
- easytag.gemspec
|
83
85
|
- lib/easytag.rb
|
86
|
+
- lib/easytag/attributes.rb
|
87
|
+
- lib/easytag/attributes/base.rb
|
88
|
+
- lib/easytag/attributes/mp3.rb
|
89
|
+
- lib/easytag/attributes/mp4.rb
|
84
90
|
- lib/easytag/base.rb
|
85
91
|
- lib/easytag/file.rb
|
86
92
|
- lib/easytag/image.rb
|
@@ -132,4 +138,3 @@ test_files:
|
|
132
138
|
- test/test_mp3.rb
|
133
139
|
- test/test_mp4.rb
|
134
140
|
- test/test_util.rb
|
135
|
-
has_rdoc:
|