id3tag 0.11.0 → 0.14.1

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
  SHA256:
3
- metadata.gz: 03c00ecdfdd2c6e53e5664831502753b5210a67098223bcfdb2805b9ab7958cd
4
- data.tar.gz: aba76b6019b3be742ddd51a2a024b90fefc59dfd1f645589f5f4a18b4da0dc60
3
+ metadata.gz: f9b52a546758418d0b992a1635a8e15728454a019bed0916fcbba4d9beb2e904
4
+ data.tar.gz: 2724b29dd05af9342467fad1f1b225ad09317ebf876582032aa0f5dcf83215d8
5
5
  SHA512:
6
- metadata.gz: 85af215ef04e69deac371b5e9dea9c1bf401f01763794ae3f319be55ce09b6aa7fd67228fca0d62bfd956d4e8a445d173d985eecd4177462fa0b7a8aeae6aa3e
7
- data.tar.gz: d3fdb4e68b97b3dfffb013d544b6feeeb56b1d9277d5ec6407fa3327837e1e8b5148c849e419ab0b18bccd8b003e5e2d01b0cca437a6216b8c3f55b88634d559
6
+ metadata.gz: 9fb5a81dcd96455512acd17ba94e458d39b2fe099acd9f57cfc58b1d4d18ff8df6979e6887876870066844dab70e0ca99bfd7d71bc694624b80a1fa31b05fc42
7
+ data.tar.gz: aac944d393fb8cbbae901e0cc5b4a2c3eb763cc30533c5fdefc979fa4b20e14d5308c985a2b9ffa4b7630ff60904ace7c94773fa7d03fd1cd264bf0a805cb0fd
data/README.md CHANGED
@@ -12,7 +12,7 @@ gem install id3tag
12
12
 
13
13
  Or add the gem to your Gemfile:
14
14
  ```
15
- gem 'id3tag', '~> 0.11.0'
15
+ gem 'id3tag', '~> 0.14.0'
16
16
  ```
17
17
 
18
18
  ## How to use
@@ -60,22 +60,51 @@ You can inspect tag by calling `frame_ids` to see available frame ids or `frames
60
60
 
61
61
  ## Configuration
62
62
 
63
- It is also possible to provide configuration and overwrite default behaviour.
64
-
63
+
65
64
  ```ruby
65
+ # Configuration could be set using a block syntax.
66
66
  ID3Tag.configuration do |c|
67
67
 
68
68
  # This way you can avoid Encoding::InvalidByteSequenceError when tag contains invalid data.
69
69
  # Currently only for String#encode which is used in TextFrames.
70
- # default: {}
70
+ # default: {}
71
71
  c.string_encode_options = { :invalid => :replace, :undef => :replace }
72
-
72
+
73
73
  # You might want to set v2.x tag read limit in bytes to avoid reading too much data into memory
74
74
  # v2 tags will be extracted until end of tag or limit is reached.
75
- # default: 0 (There are no limit)
75
+ # default: 0 (There are no limit)
76
76
  c.v2_tag_read_limit = 1048576 # 1 megabyte
77
-
77
+
78
+ # In some situations, it's not possible to recognize what is the encoding of a
79
+ # text frame. The default behavior is to raise UnsupportedTextEncoding, but
80
+ # it's possible to set a fallback to avoid it.
81
+ # default: nil
82
+ c.source_encoding_fallback = Encoding::UTF_8
83
+
84
+ end
85
+
86
+ ID3Tag.configuration.v2_tag_read_limit # 1048576
87
+
88
+ ID3Tag.configuration.v2_tag_read_limit = 1024
89
+
90
+ ID3Tag.configuration.v2_tag_read_limit # 1024
91
+
92
+
93
+ # In case you would like to set configuration temporally you could use `local_configuration` method.
94
+ # Within this block you can read and modify configuration and it wont affect global or layers above.
95
+
96
+ ID3Tag.local_configuration do
97
+ ID3Tag.configuration.v2_tag_read_limit # 1024
98
+ ID3Tag.configuration.v2_tag_read_limit = 9999
99
+ # ...
100
+ ID3Tag.configuration.v2_tag_read_limit # 9999
78
101
  end
102
+
103
+ ID3Tag.configuration.v2_tag_read_limit # 1024
104
+
105
+ ID3Tag.reset_configuration # Resets global configuration to defaults
106
+
107
+ ID3Tag.configuration.v2_tag_read_limit # 0
79
108
  ```
80
109
 
81
110
 
@@ -96,7 +125,7 @@ end
96
125
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
97
126
 
98
127
  ## Code Status
99
- [![Code Climate](https://codeclimate.com/github/krists/id3tag.png)](https://codeclimate.com/github/krists/id3tag) [![Build Status](https://travis-ci.org/krists/id3tag.png?branch=master)](https://travis-ci.org/krists/id3tag) [![Coverage Status](https://coveralls.io/repos/krists/id3tag/badge.png?branch=master)](https://coveralls.io/r/krists/id3tag) [![Gem Version](https://badge.fury.io/rb/id3tag.png)](http://badge.fury.io/rb/id3tag)
128
+ [![Code Climate](https://codeclimate.com/github/krists/id3tag.svg)](https://codeclimate.com/github/krists/id3tag) [![Build Status](https://travis-ci.org/krists/id3tag.svg?branch=master)](https://travis-ci.org/krists/id3tag) [![Coverage Status](https://coveralls.io/repos/krists/id3tag/badge.svg?branch=master)](https://coveralls.io/r/krists/id3tag) [![Gem Version](https://badge.fury.io/rb/id3tag.svg)](http://badge.fury.io/rb/id3tag)
100
129
  ## Copyright
101
130
 
102
131
  Copyright (c) 2018 Krists Ozols. See LICENSE.txt for
data/lib/id3tag.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "stringio"
2
+ require "singleton"
3
+ require "id3tag/configuration_struct"
2
4
  require "id3tag/configuration"
3
5
  require "id3tag/synchsafe_integer"
4
6
  require "id3tag/audio_file"
@@ -42,15 +44,16 @@ module ID3Tag
42
44
  end
43
45
 
44
46
  class << self
45
- def configuration
46
- @configuration ||= reset_configuration
47
- yield @configuration if block_given?
48
- @configuration
47
+ def configuration(&blk)
48
+ ID3Tag::Configuration.configuration(&blk)
49
49
  end
50
50
 
51
- def reset_configuration(configuration = ID3Tag::Configuration.new)
52
- raise ArgumentError, "Passed argument must be a ID3Tag::Configuration class object" unless configuration.is_a?(ID3Tag::Configuration)
53
- @configuration = configuration
51
+ def local_configuration(&blk)
52
+ ID3Tag::Configuration.local_configuration(&blk)
53
+ end
54
+
55
+ def reset_configuration
56
+ ID3Tag::Configuration.reset
54
57
  end
55
58
  end
56
59
  end
@@ -20,14 +20,14 @@ module ID3Tag
20
20
  end
21
21
 
22
22
  def v2_tag_present?
23
- @file.rewind
23
+ @file.seek(0)
24
24
  @file.read(3) == IDV2_TAG_IDENTIFIER
25
25
  end
26
26
 
27
27
  def v1_tag_body
28
28
  if v1_tag_present?
29
29
  @file.seek(-v1_tag_size, IO::SEEK_END)
30
- @file.read
30
+ @file.read(v1_tag_size)
31
31
  else
32
32
  nil
33
33
  end
@@ -111,7 +111,7 @@ module ID3Tag
111
111
  end
112
112
 
113
113
  def get_v2_tag_header
114
- @file.rewind
114
+ @file.seek(0)
115
115
  ID3v2TagHeader.new(@file.read(ID3V2_TAG_HEADER_SIZE))
116
116
  end
117
117
  end
@@ -1,11 +1,50 @@
1
1
  module ID3Tag
2
2
  class Configuration
3
+ include Singleton
4
+ ResetError = Class.new(StandardError)
5
+ StackItem = Struct.new(:configuration)
6
+
7
+ class << self
8
+ def local_configuration(&blk)
9
+ instance.send(:local_configuration, &blk)
10
+ end
11
+
12
+ def configuration
13
+ value_from_stack = instance.instance_variable_get(:@stack).last
14
+ value = value_from_stack && value_from_stack.configuration
15
+ value ||= instance.instance_variable_get(:@global_configuration)
16
+ yield value if block_given?
17
+ value
18
+ end
19
+
20
+ def reset
21
+ instance.send(:reset)
22
+ end
23
+ end
24
+
25
+ def local_configuration
26
+ instance_to_copy = @stack.last && @stack.last.configuration
27
+ instance_to_copy ||= @global_configuration
28
+ stack_item = StackItem.new(instance_to_copy.dup)
29
+ stack_backup = @stack.dup
30
+ @stack << stack_item
31
+ begin
32
+ yield stack_item.configuration
33
+ ensure
34
+ @stack.replace stack_backup
35
+ end
36
+ end
37
+
38
+ private
39
+
3
40
  def initialize
4
- @string_encode_options = {}
5
- @v2_tag_read_limit = 0
41
+ @stack = []
42
+ reset
6
43
  end
7
44
 
8
- attr_accessor :string_encode_options
9
- attr_accessor :v2_tag_read_limit
45
+ def reset
46
+ raise ResetError, "Configuration cannot be reset within local_configuration block" if @stack.size > 0
47
+ @global_configuration = ConfigurationStruct.new
48
+ end
10
49
  end
11
50
  end
@@ -0,0 +1,13 @@
1
+ module ID3Tag
2
+ class ConfigurationStruct
3
+ def initialize
4
+ @string_encode_options = {}
5
+ @v2_tag_read_limit = 0
6
+ @source_encoding_fallback = nil
7
+ end
8
+
9
+ attr_accessor :string_encode_options
10
+ attr_accessor :v2_tag_read_limit
11
+ attr_accessor :source_encoding_fallback
12
+ end
13
+ end
@@ -27,7 +27,7 @@ module ID3Tag
27
27
  end
28
28
 
29
29
  def self.encode(text, source_encoding)
30
- text.encode(DESTINATION_ENCODING, source_encoding, ID3Tag.configuration.string_encode_options)
30
+ text.encode(DESTINATION_ENCODING, source_encoding, **ID3Tag.configuration.string_encode_options)
31
31
  end
32
32
  end
33
33
  end
@@ -20,6 +20,7 @@ module ID3Tag
20
20
  :comments => :COM,
21
21
  :genre => :TCO,
22
22
  :track_nr => :TRK,
23
+ :disc_nr => :TPA,
23
24
  :unsychronized_transcription => :ULT,
24
25
  :image => :PIC
25
26
  },
@@ -31,6 +32,7 @@ module ID3Tag
31
32
  :comments => :COMM,
32
33
  :genre => :TCON,
33
34
  :track_nr => :TRCK,
35
+ :disc_nr => :TPOS,
34
36
  :unsychronized_transcription => :USLT,
35
37
  :image => :APIC
36
38
  },
@@ -42,6 +44,7 @@ module ID3Tag
42
44
  :comments => :COMM,
43
45
  :genre => :TCON,
44
46
  :track_nr => :TRCK,
47
+ :disc_nr => :TPOS,
45
48
  :unsychronized_transcription => :USLT,
46
49
  :image => :APIC
47
50
  }
@@ -15,7 +15,7 @@ module ID3Tag
15
15
  end
16
16
 
17
17
  def content
18
- @content.encode(destination_encoding, source_encoding)
18
+ EncodingUtil.encode(@content, source_encoding)
19
19
  end
20
20
  end
21
21
  end
@@ -9,15 +9,11 @@ module ID3Tag
9
9
  end
10
10
 
11
11
  def content
12
- @content.encode(destination_encoding, source_encoding)
12
+ EncodingUtil.encode(@content, source_encoding)
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- def destination_encoding
18
- Encoding::UTF_8
19
- end
20
-
21
17
  def source_encoding
22
18
  Encoding::ISO8859_1
23
19
  end
@@ -32,7 +32,7 @@ module ID3Tag
32
32
  end
33
33
 
34
34
  def encoded_content
35
- content_without_encoding_byte_and_language.encode(destination_encoding, source_encoding)
35
+ EncodingUtil.encode(content_without_encoding_byte_and_language, source_encoding)
36
36
  end
37
37
 
38
38
  def content_without_encoding_byte_and_language
@@ -21,15 +21,13 @@ module ID3Tag
21
21
  private
22
22
 
23
23
  def encoded_content
24
- content_without_encoding_byte.encode(destination_encoding, source_encoding, ID3Tag.configuration.string_encode_options)
24
+ EncodingUtil.encode(content_without_encoding_byte, source_encoding)
25
25
  end
26
26
 
27
27
  def source_encoding
28
- ENCODING_MAP.fetch(get_encoding_byte) { raise UnsupportedTextEncoding }.to_s
29
- end
30
-
31
- def destination_encoding
32
- Encoding::UTF_8.to_s
28
+ ENCODING_MAP.fetch(get_encoding_byte) do
29
+ ID3Tag.configuration.source_encoding_fallback || raise(UnsupportedTextEncoding)
30
+ end.to_s
33
31
  end
34
32
 
35
33
  def get_encoding_byte
@@ -60,7 +60,7 @@ module ID3Tag
60
60
  end
61
61
 
62
62
  def rewind_input
63
- @input.rewind
63
+ @input.seek(0)
64
64
  end
65
65
 
66
66
  def padding_or_eof_reached?
data/lib/id3tag/tag.rb CHANGED
@@ -38,7 +38,7 @@ module ID3Tag
38
38
 
39
39
  def first_frame_by_id(*ids)
40
40
  first_existing_id = ids.find { |id| frame_ids.include?(id) }
41
- first_existing_id && get_frame(first_existing_id)
41
+ first_existing_id && get_frames(first_existing_id).first
42
42
  end
43
43
 
44
44
  def all_frames_by_id(*ids)
@@ -1,3 +1,3 @@
1
1
  module ID3Tag
2
- VERSION = "0.11.0"
2
+ VERSION = "0.14.1"
3
3
  end
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.11.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krists Ozols
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-16 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,84 +30,84 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 12.1.0
33
+ version: 13.0.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 12.1.0
40
+ version: 13.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 5.1.0
47
+ version: 6.2.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 5.1.0
54
+ version: 6.2.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.6.0
61
+ version: 3.9.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.6.0
68
+ version: 3.9.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.14.1
75
+ version: 0.16.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.14.1
82
+ version: 0.16.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coveralls
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.21
89
+ version: 0.8.23
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.21
96
+ version: 0.8.23
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.11.1
103
+ version: 0.13.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.11.1
110
+ version: 0.13.1
111
111
  description: Native Ruby ID3 tag reader that aims for 100% coverage of ID3v2.x and
112
112
  ID3v1.x standards
113
113
  email: krists.ozols@gmail.com
@@ -122,6 +122,7 @@ files:
122
122
  - lib/id3tag.rb
123
123
  - lib/id3tag/audio_file.rb
124
124
  - lib/id3tag/configuration.rb
125
+ - lib/id3tag/configuration_struct.rb
125
126
  - lib/id3tag/encoding_util.rb
126
127
  - lib/id3tag/frame_id_advisor.rb
127
128
  - lib/id3tag/frames/util/genre_names.rb
@@ -174,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
175
  - !ruby/object:Gem::Version
175
176
  version: '0'
176
177
  requirements: []
177
- rubyforge_project:
178
- rubygems_version: 2.7.3
178
+ rubygems_version: 3.2.3
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Native Ruby ID3 tag reader that aims for 100% coverage of ID3v2.x and ID3v1.x