format_parser 0.25.6 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +4 -0
- data/lib/format_parser.rb +1 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/parsers/m3u_parser.rb +21 -0
- data/lib/text.rb +18 -0
- data/spec/parsers/m3u_parser_spec.rb +40 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1074a8172a2830a11df0fb7874936c2b8abab8d74fd39985f9c9f7b72d5b348c
|
4
|
+
data.tar.gz: 5eafd2d610cd30bc85a056bd1c31331bcb49e8ce6b5b538cd13e280b138be7db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ce396a71fedd82b8041bcb6c833e559c7eef74886e73095eaf0b3d21e0c0d49b1620a83aba9796a8134dd5a7fc679156cd967cf82cba95b5941941be73d70c4
|
7
|
+
data.tar.gz: '0395e5a8fb35e860060e9c3b040b788aaad97eb5883f2d662b418156f1f3986bc4a26a814b9a8552ce7dcbd271da27e977cfb77a5e5b155ebd35db6a49a97719'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,7 @@ and [dimensions,](https://github.com/sstephenson/dimensions) borrowing from them
|
|
32
32
|
* DOCX, PPTX, XLSX
|
33
33
|
* OGG
|
34
34
|
* MPEG, MPG
|
35
|
+
* M3U
|
35
36
|
|
36
37
|
...with [more](https://github.com/WeTransfer/format_parser/issues?q=is%3Aissue+is%3Aopen+label%3Aformats) on the way!
|
37
38
|
|
@@ -194,6 +195,9 @@ Unless specified otherwise in this section the fixture files are MIT licensed an
|
|
194
195
|
manipulated using the [https://github.com/recurser/exif-orientation-examples](exif-orientation-examples)
|
195
196
|
script.
|
196
197
|
|
198
|
+
### M3U
|
199
|
+
- The M3U fixture files were created by one of the project maintainers
|
200
|
+
|
197
201
|
### .key
|
198
202
|
- The `keynote_recognized_as_jpeg.key` file was created by the project maintainers
|
199
203
|
|
data/lib/format_parser.rb
CHANGED
@@ -19,6 +19,7 @@ module FormatParser
|
|
19
19
|
require_relative 'io_constraint'
|
20
20
|
require_relative 'care'
|
21
21
|
require_relative 'active_storage/blob_analyzer'
|
22
|
+
require_relative 'text'
|
22
23
|
|
23
24
|
# Define Measurometer in the internal namespace as well
|
24
25
|
# so that we stay compatible for the applications that use it
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class FormatParser::M3UParser
|
2
|
+
include FormatParser::IOUtils
|
3
|
+
|
4
|
+
HEADER = '#EXTM3U'
|
5
|
+
|
6
|
+
def likely_match?(filename)
|
7
|
+
filename =~ /\.m3u8?$/i
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(io)
|
11
|
+
io = FormatParser::IOConstraint.new(io)
|
12
|
+
|
13
|
+
header = safe_read(io, 7)
|
14
|
+
return unless HEADER.eql?(header)
|
15
|
+
|
16
|
+
FormatParser::Text.new(
|
17
|
+
format: :m3u
|
18
|
+
)
|
19
|
+
end
|
20
|
+
FormatParser.register_parser new, natures: :text, formats: :m3u
|
21
|
+
end
|
data/lib/text.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module FormatParser
|
2
|
+
class Text
|
3
|
+
include FormatParser::AttributesJSON
|
4
|
+
|
5
|
+
NATURE = :text
|
6
|
+
|
7
|
+
attr_accessor :format
|
8
|
+
|
9
|
+
# Only permits assignments via defined accessors
|
10
|
+
def initialize(**attributes)
|
11
|
+
attributes.map { |(k, v)| public_send("#{k}=", v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def nature
|
15
|
+
NATURE
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FormatParser::M3UParser do
|
4
|
+
let(:parsed_m3u) do
|
5
|
+
subject.call(
|
6
|
+
File.open(
|
7
|
+
Pathname.new(fixtures_dir).join('M3U').join(m3u_file),
|
8
|
+
'rb'
|
9
|
+
)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'an m3u file with missing header' do
|
14
|
+
let(:m3u_file) { 'plain_text.m3u' }
|
15
|
+
|
16
|
+
it 'does not parse the file successfully' do
|
17
|
+
expect(parsed_m3u).to be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'an m3u file with valid header' do
|
22
|
+
let(:m3u_file) { 'sample.m3u' }
|
23
|
+
|
24
|
+
it 'parses the file successfully' do
|
25
|
+
expect(parsed_m3u).not_to be_nil
|
26
|
+
expect(parsed_m3u.nature).to eq(:text)
|
27
|
+
expect(parsed_m3u.format).to eq(:m3u)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'an m3u8 file with valid header' do
|
32
|
+
let(:m3u_file) { 'sample.m3u8' }
|
33
|
+
|
34
|
+
it 'parses the file successfully' do
|
35
|
+
expect(parsed_m3u).not_to be_nil
|
36
|
+
expect(parsed_m3u.nature).to eq(:text)
|
37
|
+
expect(parsed_m3u.format).to eq(:m3u)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Berman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- lib/parsers/flac_parser.rb
|
220
220
|
- lib/parsers/gif_parser.rb
|
221
221
|
- lib/parsers/jpeg_parser.rb
|
222
|
+
- lib/parsers/m3u_parser.rb
|
222
223
|
- lib/parsers/moov_parser.rb
|
223
224
|
- lib/parsers/moov_parser/decoder.rb
|
224
225
|
- lib/parsers/mp3_parser.rb
|
@@ -236,6 +237,7 @@ files:
|
|
236
237
|
- lib/read_limiter.rb
|
237
238
|
- lib/read_limits_config.rb
|
238
239
|
- lib/remote_io.rb
|
240
|
+
- lib/text.rb
|
239
241
|
- lib/video.rb
|
240
242
|
- spec/active_storage/blob_io_spec.rb
|
241
243
|
- spec/active_storage/rails_app_spec.rb
|
@@ -257,6 +259,7 @@ files:
|
|
257
259
|
- spec/parsers/flac_parser_spec.rb
|
258
260
|
- spec/parsers/gif_parser_spec.rb
|
259
261
|
- spec/parsers/jpeg_parser_spec.rb
|
262
|
+
- spec/parsers/m3u_parser_spec.rb
|
260
263
|
- spec/parsers/moov_parser_spec.rb
|
261
264
|
- spec/parsers/mp3_parser_spec.rb
|
262
265
|
- spec/parsers/mpeg_parser_spec.rb
|
@@ -292,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
295
|
- !ruby/object:Gem::Version
|
293
296
|
version: '0'
|
294
297
|
requirements: []
|
295
|
-
rubygems_version: 3.
|
298
|
+
rubygems_version: 3.0.3
|
296
299
|
signing_key:
|
297
300
|
specification_version: 4
|
298
301
|
summary: A library for efficient parsing of file metadata
|