easytag 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,6 @@ module EasyTag::Attributes
13
13
  end
14
14
 
15
15
  class MP4Attribute < BaseAttribute
16
- attr_reader :name, :ivar
17
16
 
18
17
  def initialize(args)
19
18
  super(args)
@@ -64,13 +63,15 @@ module EasyTag::Attributes
64
63
 
65
64
  def read_user_info(iface)
66
65
  kv_hash = {}
67
- iface.info.tag.item_list_map.to_a.each do |key, value|
66
+ iface.info.tag.item_list_map.to_a.each do |key, item|
68
67
  match_data = key.match(/\:com.apple.iTunes\:(.*)/)
69
68
  if match_data
70
69
  key = match_data[1]
71
70
  key = Utilities.normalize_string(key) if @options[:normalize]
72
71
  key = key.to_sym if @options[:to_sym]
73
- kv_hash[key] = value.to_string_list[0]
72
+
73
+ values = item.to_string_list
74
+ kv_hash[key] = values.count > 1 ? values : values.first
74
75
  end
75
76
  end
76
77
 
@@ -87,6 +88,7 @@ module EasyTag::Attributes
87
88
  :name => :title,
88
89
  :item_ids => ['©nam'],
89
90
  :handler => :read_first_item,
91
+ :type => Type::STRING,
90
92
  },
91
93
 
92
94
  # title_sort_order
@@ -94,6 +96,7 @@ module EasyTag::Attributes
94
96
  :name => :title_sort_order,
95
97
  :item_ids => ['sonm'],
96
98
  :handler => :read_first_item,
99
+ :type => Type::STRING,
97
100
  },
98
101
 
99
102
  # artist
@@ -101,6 +104,7 @@ module EasyTag::Attributes
101
104
  :name => :artist,
102
105
  :item_ids => ['©ART'],
103
106
  :handler => :read_first_item,
107
+ :type => Type::STRING,
104
108
  },
105
109
 
106
110
  # artist_sort_order
@@ -108,6 +112,7 @@ module EasyTag::Attributes
108
112
  :name => :artist_sort_order,
109
113
  :item_ids => ['soar'],
110
114
  :handler => :read_first_item,
115
+ :type => Type::STRING,
111
116
  },
112
117
 
113
118
  # album_artist
@@ -115,6 +120,7 @@ module EasyTag::Attributes
115
120
  :name => :album_artist,
116
121
  :item_ids => ['aART'],
117
122
  :handler => :read_first_item,
123
+ :type => Type::STRING,
118
124
  },
119
125
 
120
126
  # album_artist_sort_order
@@ -122,6 +128,7 @@ module EasyTag::Attributes
122
128
  :name => :album_artist_sort_order,
123
129
  :item_ids => ['soaa'],
124
130
  :handler => :read_first_item,
131
+ :type => Type::STRING,
125
132
  },
126
133
 
127
134
  # album
@@ -129,6 +136,7 @@ module EasyTag::Attributes
129
136
  :name => :album,
130
137
  :item_ids => ['©alb'],
131
138
  :handler => :read_first_item,
139
+ :type => Type::STRING,
132
140
  },
133
141
 
134
142
  # album_sort_order
@@ -136,6 +144,7 @@ module EasyTag::Attributes
136
144
  :name => :album_sort_order,
137
145
  :item_ids => ['soal'],
138
146
  :handler => :read_first_item,
147
+ :type => Type::STRING,
139
148
  },
140
149
 
141
150
  # genre
@@ -143,6 +152,7 @@ module EasyTag::Attributes
143
152
  :name => :genre,
144
153
  :item_ids => ['©gen'],
145
154
  :handler => :read_first_item,
155
+ :type => Type::STRING,
146
156
  },
147
157
 
148
158
  # comments
@@ -157,7 +167,8 @@ module EasyTag::Attributes
157
167
  # comment
158
168
  {
159
169
  :name => :comment,
160
- :handler => lambda { |iface| iface.comments.first }
170
+ :handler => lambda { |iface| iface.comments.first },
171
+ :type => Type::STRING,
161
172
  },
162
173
 
163
174
  # lyrics
@@ -165,6 +176,7 @@ module EasyTag::Attributes
165
176
  :name => :lyrics,
166
177
  :item_ids => ['©lyr'],
167
178
  :handler => :read_first_item,
179
+ :type => Type::STRING,
168
180
  },
169
181
 
170
182
  # date
@@ -173,12 +185,13 @@ module EasyTag::Attributes
173
185
  :item_ids => ['©day'],
174
186
  :handler => :read_first_item,
175
187
  :type => Type::DATETIME,
188
+ :default => nil,
176
189
  },
177
190
 
178
191
  # year
179
192
  {
180
- :name => :year,
181
- :handler => lambda { |iface| iface.date.nil? ? 0 : iface.date.year }
193
+ :name => :year,
194
+ :handler => lambda { |iface| iface.date.nil? ? 0 : iface.date.year }
182
195
  },
183
196
 
184
197
  # apple_id
@@ -186,6 +199,7 @@ module EasyTag::Attributes
186
199
  :name => :apple_id,
187
200
  :item_ids => ['apid'],
188
201
  :handler => :read_first_item,
202
+ :type => Type::STRING,
189
203
  },
190
204
 
191
205
  # encoded_by
@@ -193,6 +207,7 @@ module EasyTag::Attributes
193
207
  :name => :encoded_by,
194
208
  :item_ids => ['©enc'],
195
209
  :handler => :read_first_item,
210
+ :type => Type::STRING,
196
211
  },
197
212
 
198
213
  # encoder_settings
@@ -200,6 +215,7 @@ module EasyTag::Attributes
200
215
  :name => :encoder_settings,
201
216
  :item_ids => ['©too'],
202
217
  :handler => :read_first_item,
218
+ :type => Type::STRING,
203
219
  },
204
220
 
205
221
  # group
@@ -207,6 +223,7 @@ module EasyTag::Attributes
207
223
  :name => :group,
208
224
  :item_ids => ['©grp'],
209
225
  :handler => :read_first_item,
226
+ :type => Type::STRING,
210
227
  },
211
228
 
212
229
  # compilation?
@@ -214,8 +231,8 @@ module EasyTag::Attributes
214
231
  :name => :compilation?,
215
232
  :item_ids => ['cpil'],
216
233
  :handler => :read_first_item,
234
+ :type => Type::BOOLEAN,
217
235
  :item_type => ItemType::BOOL,
218
- :default => false,
219
236
  },
220
237
 
221
238
  # bpm
@@ -227,11 +244,21 @@ module EasyTag::Attributes
227
244
  :default => 0,
228
245
  },
229
246
 
247
+ # mood
248
+ {
249
+ :name => :mood,
250
+ :item_ids => ['mood'],
251
+ :handler => :read_first_item,
252
+ :item_type => ItemType::STRING,
253
+ :type => Type::STRING,
254
+ },
255
+
230
256
  # copyright
231
257
  {
232
258
  :name => :copyright,
233
259
  :item_ids => ['cprt'],
234
260
  :handler => :read_first_item,
261
+ :type => Type::STRING,
235
262
  },
236
263
 
237
264
  # track_num
@@ -266,44 +293,209 @@ module EasyTag::Attributes
266
293
  :name => :user_info,
267
294
  :handler => :read_user_info,
268
295
  :default => {},
296
+ },
297
+
298
+ # user_info_normalized
299
+ {
300
+ :name => :user_info_normalized,
301
+ :handler => :read_user_info,
302
+ :default => {},
269
303
  :options => {:normalize => true, :to_sym => true},
270
304
  },
271
305
 
272
306
  # subtitle
273
307
  {
274
308
  :name => :subtitle,
275
- :handler => lambda { |iface| iface.user_info[:subtitle] }
309
+ :handler => :user_info_lookup,
310
+ :handler_opts => {:key => :subtitle},
311
+ :type => Type::STRING,
276
312
  },
277
313
 
278
314
  # disc_subtitle
279
315
  {
280
316
  :name => :disc_subtitle,
281
- :handler => lambda { |iface| iface.user_info[:discsubtitle] }
317
+ :handler => :user_info_lookup,
318
+ :handler_opts => {:key => :discsubtitle},
319
+ :type => Type::STRING,
282
320
  },
283
321
 
284
322
  # media
285
323
  {
286
324
  :name => :media,
287
- :handler => lambda { |iface| iface.user_info[:media] }
325
+ :handler => :user_info_lookup,
326
+ :handler_opts => {:key => :media},
327
+ :type => Type::STRING,
288
328
  },
289
329
 
290
330
  # label
291
331
  {
292
332
  :name => :label,
293
- :handler => lambda { |iface| iface.user_info[:label] }
333
+ :handler => :user_info_lookup,
334
+ :handler_opts => {:key => :label},
335
+ :type => Type::STRING,
294
336
  },
295
337
 
296
338
  # composer
297
339
  {
298
340
  :name => :composer,
299
- :handler => lambda { |iface| iface.user_info[:composer] }
341
+ :handler => :user_info_lookup,
342
+ :handler_opts => {:key => :composer},
343
+ :type => Type::STRING,
344
+ },
345
+
346
+ # conductor
347
+ {
348
+ :name => :conductor,
349
+ :handler => :user_info_lookup,
350
+ :handler_opts => {:key => :conductor},
351
+ :type => Type::STRING,
352
+ },
353
+
354
+ # remixer
355
+ {
356
+ :name => :remixer,
357
+ :handler => :user_info_lookup,
358
+ :handler_opts => {:key => :remixer},
359
+ :type => Type::STRING,
300
360
  },
301
361
 
302
362
  # lyricist
303
363
  {
304
364
  :name => :lyricist,
305
- :handler => lambda { |iface| iface.user_info[:lyricist] }
365
+ :handler => :user_info_lookup,
366
+ :handler_opts => {:key => :lyricist},
367
+ :type => Type::STRING,
368
+ },
369
+
370
+ # asin
371
+ {
372
+ :name => :asin,
373
+ :handler => :user_info_lookup,
374
+ :handler_opts => {:key => :asin},
375
+ :type => Type::STRING,
376
+ },
377
+
378
+ #
379
+ # MusicBrainz Attributes
380
+ #
381
+
382
+ # musicbrainz_track_id
383
+ {
384
+ :name => :musicbrainz_track_id,
385
+ :handler => :user_info_lookup,
386
+ :handler_opts => {:key => :musicbrainz_track_id},
387
+ :type => Type::STRING,
388
+ },
389
+
390
+ # musicbrainz_album_artist_id
391
+ {
392
+ :name => :musicbrainz_album_artist_id,
393
+ :handler => :user_info_lookup,
394
+ :handler_opts => {:key => :musicbrainz_album_artist_id},
395
+ :type => Type::STRING,
396
+ },
397
+
398
+ # musicbrainz_artist_id
399
+ {
400
+ :name => :musicbrainz_artist_id,
401
+ :handler => :user_info_lookup,
402
+ :handler_opts => {:key => :musicbrainz_artist_id},
403
+ :type => Type::LIST,
404
+ },
405
+
406
+ # musicbrainz_album_id
407
+ {
408
+ :name => :musicbrainz_album_id,
409
+ :handler => :user_info_lookup,
410
+ :handler_opts => {:key => :musicbrainz_album_id},
411
+ :type => Type::STRING,
412
+ },
413
+
414
+ # musicbrainz_album_status
415
+ {
416
+ :name => :musicbrainz_album_status,
417
+ :handler => :user_info_lookup,
418
+ :handler_opts => {:key => :musicbrainz_album_status},
419
+ :type => Type::STRING,
420
+ },
421
+
422
+ # musicbrainz_album_type
423
+ {
424
+ :name => :musicbrainz_album_type,
425
+ :handler => :user_info_lookup,
426
+ :handler_opts => {:key => :musicbrainz_album_type},
427
+ :type => Type::LIST,
306
428
  },
307
429
 
430
+
431
+ # musicbrainz_release_group_id
432
+ {
433
+ :name => :musicbrainz_release_group_id,
434
+ :handler => :user_info_lookup,
435
+ :handler_opts => {:key => :musicbrainz_release_group_id},
436
+ :type => Type::STRING,
437
+ },
438
+
439
+ # musicbrainz_album_release_country
440
+ {
441
+ :name => :musicbrainz_album_release_country,
442
+ :handler => :user_info_lookup,
443
+ :handler_opts => {:key => :musicbrainz_album_release_country},
444
+ :type => Type::STRING,
445
+ },
446
+
447
+ #
448
+ # Audio Properties
449
+ #
450
+
451
+ # length
452
+ {
453
+ :name => :length,
454
+ :aliases => [:duration],
455
+ :handler => :read_audio_property,
456
+ :handler_opts => {:key => :length},
457
+ :type => Type::INT,
458
+ },
459
+
460
+ # bitrate
461
+ {
462
+ :name => :bitrate,
463
+ :handler => :read_audio_property,
464
+ :handler_opts => {:key => :bitrate},
465
+ :type => Type::INT,
466
+ },
467
+
468
+ # sample_rate
469
+ {
470
+ :name => :sample_rate,
471
+ :handler => :read_audio_property,
472
+ :handler_opts => {:key => :sample_rate},
473
+ :type => Type::INT,
474
+ },
475
+
476
+ # channels
477
+ {
478
+ :name => :channels,
479
+ :handler => :read_audio_property,
480
+ :handler_opts => {:key => :channels},
481
+ :type => Type::INT,
482
+ },
483
+
484
+ # bits_per_sample
485
+ {
486
+ :name => :bits_per_sample,
487
+ :handler => :read_audio_property,
488
+ :handler_opts => {:key => :bits_per_sample},
489
+ :type => Type::INT,
490
+ },
491
+
492
+ # NOTE: Not supported by ruby-easytag 0.6.0
493
+ ## encrypted?
494
+ #{
495
+ #:name => :encrypted?,
496
+ #:handler => :read_audio_property,
497
+ #:handler_opts => {:key => :encrypted?},
498
+ #:type => Type::BOOLEAN,
499
+ #},
308
500
  ]
309
501
  end
@@ -16,11 +16,11 @@ module EasyTag
16
16
  end
17
17
 
18
18
  def proxy_getter(m)
19
- if @interface.respond_to?(m)
20
- @interface.send(m)
21
- else
19
+ unless @interface.respond_to?(m)
22
20
  warn "#{@interface.class} doesn't support method #{m}"
23
21
  end
22
+
23
+ @interface.send(m)
24
24
  end
25
25
 
26
26
  # dynamic instance method generation
@@ -3,19 +3,22 @@ module EasyTag
3
3
  class Base
4
4
  attr_reader :info
5
5
 
6
- # avoid returing empty objects
7
- def self.obj_or_nil(o)
8
- if o.class == String
9
- ret = o.empty? ? nil : o
10
- else
11
- o
12
- end
13
- end
14
-
15
6
  def close
16
7
  @info.close
17
8
  end
18
9
 
10
+ def self.build_attributes(attrib_class, attrib_args)
11
+ attrib_args.each do |attrib_args|
12
+ attrib = attrib_class.new(attrib_args)
13
+ define_method(attrib.name) do
14
+ instance_variable_get(attrib.ivar) ||
15
+ instance_variable_set(attrib.ivar, attrib.call(self))
16
+ end
17
+
18
+ attrib.aliases.each { |a| alias_method a, attrib.name}
19
+ end
20
+ end
21
+
19
22
  end
20
23
  end
21
24
  end
@@ -1,11 +1,13 @@
1
1
  require 'mp3info'
2
- require 'yaml'
3
2
 
4
3
  require 'easytag/attributes/mp3'
5
4
 
6
5
  module EasyTag::Interfaces
7
6
 
8
7
  class MP3 < Base
8
+ ATTRIB_ARGS = EasyTag::Attributes::MP3_ATTRIB_ARGS
9
+ ATTRIB_CLASS = EasyTag::Attributes::MP3Attribute
10
+
9
11
  def initialize(file)
10
12
  @info = TagLib::MPEG::File.new(file)
11
13
 
@@ -41,13 +43,6 @@ module EasyTag::Interfaces
41
43
  end
42
44
  end
43
45
 
44
- EasyTag::Attributes::MP3_ATTRIB_ARGS.each do |attrib_args|
45
- attrib = EasyTag::Attributes::MP3Attribute.new(attrib_args)
46
- define_method(attrib.name) do
47
- instance_variable_get(attrib.ivar) ||
48
- instance_variable_set(attrib.ivar, attrib.call(self))
49
- end
50
- end
51
-
46
+ self.build_attributes(ATTRIB_CLASS, ATTRIB_ARGS)
52
47
  end
53
48
  end