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 +4 -4
- data/README.md +37 -8
- data/lib/id3tag.rb +10 -7
- data/lib/id3tag/audio_file.rb +3 -3
- data/lib/id3tag/configuration.rb +43 -4
- data/lib/id3tag/configuration_struct.rb +13 -0
- data/lib/id3tag/encoding_util.rb +1 -1
- data/lib/id3tag/frame_id_advisor.rb +3 -0
- data/lib/id3tag/frames/v1/comments_frame.rb +1 -1
- data/lib/id3tag/frames/v1/text_frame.rb +1 -5
- data/lib/id3tag/frames/v2/comments_frame.rb +1 -1
- data/lib/id3tag/frames/v2/text_frame.rb +4 -6
- data/lib/id3tag/id3_v2_frame_parser.rb +1 -1
- data/lib/id3tag/tag.rb +1 -1
- data/lib/id3tag/version.rb +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9b52a546758418d0b992a1635a8e15728454a019bed0916fcbba4d9beb2e904
|
4
|
+
data.tar.gz: 2724b29dd05af9342467fad1f1b225ad09317ebf876582032aa0f5dcf83215d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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.
|
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
|
-
|
47
|
-
yield @configuration if block_given?
|
48
|
-
@configuration
|
47
|
+
def configuration(&blk)
|
48
|
+
ID3Tag::Configuration.configuration(&blk)
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
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
|
data/lib/id3tag/audio_file.rb
CHANGED
@@ -20,14 +20,14 @@ module ID3Tag
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def v2_tag_present?
|
23
|
-
@file.
|
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.
|
114
|
+
@file.seek(0)
|
115
115
|
ID3v2TagHeader.new(@file.read(ID3V2_TAG_HEADER_SIZE))
|
116
116
|
end
|
117
117
|
end
|
data/lib/id3tag/configuration.rb
CHANGED
@@ -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
|
-
@
|
5
|
-
|
41
|
+
@stack = []
|
42
|
+
reset
|
6
43
|
end
|
7
44
|
|
8
|
-
|
9
|
-
|
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
|
data/lib/id3tag/encoding_util.rb
CHANGED
@@ -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
|
}
|
@@ -9,15 +9,11 @@ module ID3Tag
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def content
|
12
|
-
|
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
|
-
|
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
|
-
|
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)
|
29
|
-
|
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
|
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 &&
|
41
|
+
first_existing_id && get_frames(first_existing_id).first
|
42
42
|
end
|
43
43
|
|
44
44
|
def all_frames_by_id(*ids)
|
data/lib/id3tag/version.rb
CHANGED
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.
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
-
|
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
|