id3tag 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92be9c2e14829993e4b5605e5e223a153ec95553
4
- data.tar.gz: bc8c97ed113fe62aa18de8731c65c518527790e8
3
+ metadata.gz: 89941a8621dd5eec4f0ae322c2bf9615496d52ff
4
+ data.tar.gz: 65994561b1424f4c4101bc65080454566f86ce7f
5
5
  SHA512:
6
- metadata.gz: dea74a6d210076823b9705db4a5caadaaef41e78e375918f167ea29a5d6e428fcacb48736450110f022e46869255b1dcc20a97b17ec91dba814876e0a57cebc3
7
- data.tar.gz: dd001f998fa99acaa2edd9088d9e36c5967625b4bbafeb99201d12edafe0cf1712577aa6ff1b1f33edcb209ca190322e84d54df511a0e7afe24d86d7c0756951
6
+ metadata.gz: 7e7017566d378958d0bd534768854ff477d480f608baa4cb6839b1a1aa3856bd7697dabe016de3d60e084d3162dd3966a4a2228a4c1e16e2654740374462024a
7
+ data.tar.gz: f7e6b73b353b26d5fc9d03de31a63683579191823ec7695c66562634d8aacc1d209e74ac128765553461efc791be1cc1339a041399a85cd1d988476829108e6e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
data/id3tag.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: id3tag 0.5.2 ruby lib
5
+ # stub: id3tag 0.5.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "id3tag"
9
- s.version = "0.5.2"
9
+ s.version = "0.5.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Krists Ozols"]
13
- s.date = "2013-11-12"
13
+ s.date = "2013-11-13"
14
14
  s.description = "Native Ruby ID3 tag reader that aims for 100% covarage of ID3v2.x and ID3v1.x standards"
15
15
  s.email = "krists@iesals.lv"
16
16
  s.extra_rdoc_files = [
@@ -85,6 +85,7 @@ Gem::Specification.new do |s|
85
85
  "spec/lib/id3tag/frames/v2/genre_frame_spec.rb",
86
86
  "spec/lib/id3tag/frames/v2/text_frame_spec.rb",
87
87
  "spec/lib/id3tag/frames/v2/unique_file_id_frame_spec.rb",
88
+ "spec/lib/id3tag/frames/v2/user_text_frame_spec.rb",
88
89
  "spec/lib/id3tag/id3_v1_frame_parser_spec.rb",
89
90
  "spec/lib/id3tag/id3_v2_frame_parser_spec.rb",
90
91
  "spec/lib/id3tag/id3_v2_tag_header_spec.rb",
@@ -20,7 +20,7 @@ module ID3Tag
20
20
  case @id
21
21
  when /^(TCON|TCO)$/
22
22
  GenreFrame
23
- when /^TXX$/
23
+ when /^TXX/
24
24
  UserTextFrame
25
25
  when /^T/
26
26
  TextFrame
data/lib/id3tag/tag.rb CHANGED
@@ -16,19 +16,26 @@ module ID3Tag
16
16
 
17
17
  [:artist, :title, :album, :year, :track_nr, :genre].each do |name|
18
18
  define_method(name) do
19
- frame = first_frame_by_id(*possible_frame_ids_by_name(name))
20
- frame && frame.content
19
+ content_of_first_frame(name)
21
20
  end
22
21
  end
23
22
 
24
- # TODO: Add Terms of use frame and Synchronised lyrics/text frame
23
+ def content_of_first_frame(name)
24
+ frame = first_frame_by_id(*possible_frame_ids_by_name(name))
25
+ frame && frame.content
26
+ end
27
+
25
28
  [:comments, :unsychronized_transcription].each do |name|
26
29
  define_method(name) do |lang = :eng|
27
- frame = all_frames_by_id(*possible_frame_ids_by_name(name)).find { |x| x.language == lang.to_s }
28
- frame && frame.content
30
+ content_of_first_frame_with_language(name, lang)
29
31
  end
30
32
  end
31
33
 
34
+ def content_of_first_frame_with_language(name, lang)
35
+ frame = all_frames_by_id(*possible_frame_ids_by_name(name)).find { |x| x.language == lang.to_s }
36
+ frame && frame.content
37
+ end
38
+
32
39
  def first_frame_by_id(*ids)
33
40
  first_existing_id = ids.find { |id| frame_ids.include?(id) }
34
41
  first_existing_id && get_frame(first_existing_id)
@@ -62,7 +69,7 @@ module ID3Tag
62
69
  end
63
70
 
64
71
  def v2_frames
65
- if audio_file.v2_tag_present? && scope.include?(:v2)
72
+ if should_and_could_read_v2_frames?
66
73
  ID3V2FrameParser.new(audio_file.v2_tag_body, audio_file.v2_tag_major_version_number).frames
67
74
  else
68
75
  []
@@ -70,7 +77,7 @@ module ID3Tag
70
77
  end
71
78
 
72
79
  def v1_frames
73
- if audio_file.v1_tag_present? && scope.include?(:v1)
80
+ if should_and_could_read_v1_frames?
74
81
  ID3V1FrameParser.new(audio_file.v1_tag_body).frames
75
82
  else
76
83
  []
@@ -81,17 +88,35 @@ module ID3Tag
81
88
  @audio_file ||= AudioFile.new(@source)
82
89
  end
83
90
 
91
+ private
92
+
84
93
  def possible_frame_ids_by_name(name)
85
94
  ids = []
86
- if scope.include?(:v2) && audio_file.v2_tag_present?
87
- id = FrameIdAdvisor.new(2, audio_file.v2_tag_major_version_number).advise(name)
88
- ids << id if id
95
+ id = possible_v1_frame_id_by_name(name)
96
+ ids << id if id
97
+ id = possible_v2_frame_id_by_name(name)
98
+ ids << id if id
99
+ ids
100
+ end
101
+
102
+ def possible_v2_frame_id_by_name(name)
103
+ if should_and_could_read_v2_frames?
104
+ FrameIdAdvisor.new(2, audio_file.v2_tag_major_version_number).advise(name)
89
105
  end
90
- if scope.include?(:v1) && audio_file.v1_tag_present?
91
- id = FrameIdAdvisor.new(1, FrameIdAdvisor::ANY_MAJOR_VERSION).advise(name)
92
- ids << id if id
106
+ end
107
+
108
+ def possible_v1_frame_id_by_name(name)
109
+ if should_and_could_read_v1_frames?
110
+ FrameIdAdvisor.new(1, FrameIdAdvisor::ANY_MAJOR_VERSION).advise(name)
93
111
  end
94
- ids
112
+ end
113
+
114
+ def should_and_could_read_v1_frames?
115
+ scope.include?(:v1) && audio_file.v1_tag_present?
116
+ end
117
+
118
+ def should_and_could_read_v2_frames?
119
+ scope.include?(:v2) && audio_file.v2_tag_present?
95
120
  end
96
121
  end
97
122
  end
@@ -43,6 +43,12 @@ describe ID3Tag::AudioFile do
43
43
  it "should return frame and padding bytes" do
44
44
  subject.v2_tag_body.should == "ABC"
45
45
  end
46
+ context "when tag verison is v.2.4 and extended header size is calculated differently" do
47
+ subject { described_class.new(StringIO.new("ID3\u0004\u0000\u0040\u0000\u0000\u0000\u0011" + "\u0000\u0000\u0000\u000A" + ("\u0000" * 6) + "ABC")) }
48
+ it "should return frame and padding bytes" do
49
+ subject.v2_tag_body.should == "ABC"
50
+ end
51
+ end
46
52
  end
47
53
  end
48
54
 
@@ -30,6 +30,13 @@ describe ID3Tag::Frames::V2::FrameFabricator do
30
30
  subject
31
31
  end
32
32
  end
33
+ context "when frame is a user text frame" do
34
+ let(:id) { "TXX" }
35
+ it "fabricates user text frame" do
36
+ ID3Tag::Frames::V2::UserTextFrame.should_receive(:new).with(id, content, flags, major_version_number)
37
+ subject
38
+ end
39
+ end
33
40
  context "when frame is a comment frame COM" do
34
41
  let(:id) { "COMM" }
35
42
  it "fabricates comment frame" do
@@ -44,6 +51,13 @@ describe ID3Tag::Frames::V2::FrameFabricator do
44
51
  subject
45
52
  end
46
53
  end
54
+ context "when frame is a unique id" do
55
+ let(:id) { "IPLS" }
56
+ it "fabricates involved people list frame" do
57
+ ID3Tag::Frames::V2::InvolvedPeopleListFrame.should_receive(:new).with(id, content, flags, major_version_number)
58
+ subject
59
+ end
60
+ end
47
61
  context "when frame is a unknown" do
48
62
  let(:id) { "unknown" }
49
63
  it "fabricates basic frame" do
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe ID3Tag::Frames::V2::UserTextFrame do
5
+ let(:id) { "TXX" }
6
+ let(:raw_content) { text.encode(target_encoding).prepend(encoding_byte.force_encoding(target_encoding)) }
7
+ let(:flags) { nil }
8
+ let(:major_version_number) { 4 }
9
+
10
+ let(:target_encoding) { Encoding::UTF_8 }
11
+ let(:encoding_byte) { "\x03" }
12
+ let(:text) { "SUPER_FRAME\x00Glāzšķūņrūķīši" }
13
+ subject { described_class.new(id, raw_content, flags, major_version_number) }
14
+
15
+ its(:id) { should == :TXX }
16
+ its(:content) { should == 'Glāzšķūņrūķīši' }
17
+ its(:description) { should == 'SUPER_FRAME' }
18
+ its(:inspect) { should eq('<ID3Tag::Frames::V2::UserTextFrame TXX: Glāzšķūņrūķīši>') }
19
+ end
data/tags CHANGED
@@ -138,6 +138,8 @@ content lib/id3tag/frames/v2/genre_frame.rb /^ def content$/;" f class:ID
138
138
  content lib/id3tag/frames/v2/text_frame.rb /^ def content$/;" f class:ID3Tag.Frames.V2.TextFrame
139
139
  content lib/id3tag/frames/v2/unique_file_id_frame.rb /^ def content$/;" f class:ID3Tag.Frames.V2.UniqueFileIdFrame
140
140
  content lib/id3tag/frames/v2/user_text_frame.rb /^ def content$/;" f class:ID3Tag.Frames.V2.UserTextFrame
141
+ content_of_first_frame lib/id3tag/tag.rb /^ def content_of_first_frame(name)$/;" f class:ID3Tag
142
+ content_of_first_frame_with_language lib/id3tag/tag.rb /^ def content_of_first_frame_with_language(name, lang)$/;" f class:ID3Tag
141
143
  content_parts lib/id3tag/frames/v2/user_text_frame.rb /^ def content_parts$/;" f class:ID3Tag.Frames.V2.UserTextFrame
142
144
  content_split_apart_by_null_byte lib/id3tag/frames/v2/unique_file_id_frame.rb /^ def content_split_apart_by_null_byte$/;" f class:ID3Tag.Frames.V2.UniqueFileIdFrame
143
145
  content_without_encoding_byte lib/id3tag/frames/v2/text_frame.rb /^ def content_without_encoding_byte$/;" f class:ID3Tag.Frames.V2.TextFrame
@@ -262,6 +264,8 @@ position_and_count_of_encryption_id_bytes lib/id3tag/frames/v2/frame_flags.rb /^
262
264
  position_and_count_of_group_id_bytes lib/id3tag/frames/v2/basic_frame.rb /^ def position_and_count_of_group_id_bytes$/;" f class:ID3Tag.Frames.V2.BasicFrame
263
265
  position_and_count_of_group_id_bytes lib/id3tag/frames/v2/frame_flags.rb /^ def position_and_count_of_group_id_bytes$/;" f class:ID3Tag.Frames.V2.FrameFlags
264
266
  possible_frame_ids_by_name lib/id3tag/tag.rb /^ def possible_frame_ids_by_name(name)$/;" f class:ID3Tag
267
+ possible_v1_frame_id_by_name lib/id3tag/tag.rb /^ def possible_v1_frame_id_by_name(name)$/;" f class:ID3Tag
268
+ possible_v2_frame_id_by_name lib/id3tag/tag.rb /^ def possible_v2_frame_id_by_name(name)$/;" f class:ID3Tag
265
269
  preserve_on_file_alteration? lib/id3tag/frames/v2/basic_frame.rb /^ def preserve_on_file_alteration?$/;" f class:ID3Tag.Frames.V2.BasicFrame
266
270
  preserve_on_file_alteration? lib/id3tag/frames/v2/frame_flags.rb /^ def preserve_on_file_alteration?$/;" f class:ID3Tag.Frames.V2.FrameFlags
267
271
  preserve_on_file_alteration? lib/id3tag/frames/v2/frame_header_flags.rb /^ def preserve_on_file_alteration?$/;" f class:ID3Tag.Frames.V2.FrameFlags
@@ -283,6 +287,8 @@ read_only? lib/id3tag/frames/v2/frame_flags.rb /^ def read_only?$/;" f cl
283
287
  read_only? lib/id3tag/frames/v2/frame_header_flags.rb /^ def read_only?$/;" f class:ID3Tag.Frames.V2.FrameFlags
284
288
  remove lib/id3tag/unsynchronization.rb /^ def remove$/;" f class:ID3Tag.Unsynchronization
285
289
  rewind_input lib/id3tag/id3_v2_frame_parser.rb /^ def rewind_input$/;" f class:ID3Tag.ID3V2FrameParser
290
+ should_and_could_read_v1_frames? lib/id3tag/tag.rb /^ def should_and_could_read_v1_frames?$/;" f class:ID3Tag
291
+ should_and_could_read_v2_frames? lib/id3tag/tag.rb /^ def should_and_could_read_v2_frames?$/;" f class:ID3Tag
286
292
  source_encoding lib/id3tag/frames/v1/text_frame.rb /^ def source_encoding$/;" f class:ID3Tag.Frames.V1.TextFrame
287
293
  source_encoding lib/id3tag/frames/v2/text_frame.rb /^ def source_encoding$/;" f class:ID3Tag.Frames.V2.TextFrame
288
294
  split_by_null_byte lib/id3tag/string_util.rb /^ def self.split_by_null_byte(string)$/;" F class:ID3Tag.StringUtil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id3tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krists Ozols
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-12 00:00:00.000000000 Z
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler
@@ -170,6 +170,7 @@ files:
170
170
  - spec/lib/id3tag/frames/v2/genre_frame_spec.rb
171
171
  - spec/lib/id3tag/frames/v2/text_frame_spec.rb
172
172
  - spec/lib/id3tag/frames/v2/unique_file_id_frame_spec.rb
173
+ - spec/lib/id3tag/frames/v2/user_text_frame_spec.rb
173
174
  - spec/lib/id3tag/id3_v1_frame_parser_spec.rb
174
175
  - spec/lib/id3tag/id3_v2_frame_parser_spec.rb
175
176
  - spec/lib/id3tag/id3_v2_tag_header_spec.rb