file_data 5.2.0 → 6.0.0

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: 57a1747c7962bc51b2333ae0037e9736437190f0c98dce5d77810bc81df22152
4
- data.tar.gz: 88f5ddc362b309d14c3c5e8f3c463191dc448fb48901b9afae5b942bf5595745
3
+ metadata.gz: 4f9ac51b8c0f2d6388b07ab1f6614de4a1fac558c21689fa61d198d70c18a8b4
4
+ data.tar.gz: 4da0fada39336b0346d0846ee6c04a6962c0c4f34909463ded2c0aa2c97511fe
5
5
  SHA512:
6
- metadata.gz: 89d98f94f872872ad3a59b84fdc42612d82db860ccac2769f8ebcce5b2b5715b44847dad125a3f6ca6a6811715866aebc2c0558550c4ff06f478119726937190
7
- data.tar.gz: 54d2e8defca7b5dd1447c7bb0de238d4a70f662a99afa9f9b9d8647b0c8152a73b58cb536e45064cc96091be571e3bcafa5910a88e9dd1b5baa800a114b679f6
6
+ metadata.gz: 74284cdbc2af387ad6e0b058d25ec38ade9bb5021eaec62be513b923ad6a38398ae199698d1aa78226306e3a60856a1c1658b59fe4d460fe7e600345ef555dba
7
+ data.tar.gz: 3f7a040e99bc6a47da21c759c687f831014ba7e1823f7b63d8e8af2bfb1ab79fb8abbfd5f49059fdb9ad77aa0c0358585f1a935204104597ea580786a46ee6ec
data/.coveralls.yml CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- file_data (5.0.0)
4
+ file_data (6.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,7 +17,7 @@ GEM
17
17
  term-ansicolor (~> 1.3)
18
18
  thor (~> 0.19.1)
19
19
  tins (~> 1.6)
20
- debug_inspector (0.0.3)
20
+ debug_inspector (1.1.0)
21
21
  deep-cover (0.6.2)
22
22
  backports (>= 3.11.0)
23
23
  binding_of_caller
@@ -34,16 +34,15 @@ GEM
34
34
  docile (1.1.5)
35
35
  fakefs (0.10.2)
36
36
  ffi (1.9.25)
37
- ffi (1.9.25-x64-mingw32)
38
37
  highline (2.0.0)
39
- json (2.0.3)
38
+ json (2.6.0)
40
39
  method_source (0.9.0)
41
40
  parser (2.5.1.0)
42
41
  ast (~> 2.4.0)
43
42
  pry (0.11.3)
44
43
  coderay (~> 1.1.0)
45
44
  method_source (~> 0.9.0)
46
- rake (10.5.0)
45
+ rake (13.0.6)
47
46
  rb-fsevent (0.10.3)
48
47
  rb-inotify (0.9.10)
49
48
  ffi (>= 0.5.0, < 2)
@@ -87,13 +86,13 @@ PLATFORMS
87
86
  x64-mingw32
88
87
 
89
88
  DEPENDENCIES
90
- bundler (~> 1.14)
89
+ bundler (~> 2.2)
91
90
  coveralls (~> 0.8)
92
91
  deep-cover (~> 0.6)
93
92
  fakefs (~> 0.10)
94
93
  file_data!
95
- rake (~> 10.0)
94
+ rake (~> 13.0)
96
95
  rspec (~> 3.0)
97
96
 
98
97
  BUNDLED WITH
99
- 1.16.1
98
+ 2.2.29
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -8,69 +8,42 @@ file_data
8
8
 
9
9
  Ruby library that reads file metadata.
10
10
 
11
- The api provides a basic usage and an advanced usage. The basic usage will reopen and reparse the file every time it is called which is no problem when reading a single value but can be a performance drain for multiple values. The advanced usage allows the user to grab more than one value without having to read the file more than once.
12
-
13
- ## Basic Usage
11
+ ## Basic Usage for an Exif File
14
12
 
15
13
  ```ruby
16
- filepath = '...' # Path to a jpeg or mpeg4 file
17
-
18
- # Get the date when the file content originated. When a photo was taken, when a movie was recorded, etc
19
- FileData::FileInfo.origin_date(filepath)
20
-
21
- # Get the date when the file was considered to be created. This is usually tied in some way to when the file itself was created on a disk somewhere (not usually as useful as origin date)
22
- FileData::FileInfo.creation_date(filepath)
23
- ```
24
-
25
- ## Advanced Usage
14
+ require 'file_data'
26
15
 
27
- Varies by file format type. Currently there are low level classes for parsing exif and mpeg4 metadata
16
+ ## Step 1: Read in the exif data using either a file path or a stream
28
17
 
29
- ## Exif documentation
18
+ # Using a file path...
19
+ file_path = '/home/user/desktop/my_file.jpg' # Path to an exif file
20
+ exif_data = FileData::Exif.all_data(file_path) # read in all of the exif data from the file path
30
21
 
31
- Exif data is hierarchical and consists of tag/value pairs. The first level is whether or not the tag applies to the image or the image's thumbnail. Next a tag may be one of several sections and within the section it will have a unique numeric value. So given this terminology a unique key for an exif tag would be something like image/section1/123 for a tag that applies to the image in section 1 with a tag id of 123.
32
-
33
- To read exif data a stream of the jpeg data should be used as input. For performance reasons all of the data that is desired should be extracted in a single method from FileData::Exif. All methods will manipulate the stream position after they are called and the user should not count on the stream position being at a specific location after a FileData::Exif method call.
22
+ # Or using a stream...
23
+ exif_data = File.open(file_path, 'rb') do |f|
24
+ FileData::Exif.all_data(f)
25
+ end
34
26
 
35
- Examples:
27
+ ## Step 2: Data is divided into image data and thumbnail data. Pick which you want to work with.
36
28
 
37
- ```ruby
38
- ## Get Exif data from a file path or stream
29
+ # Both objects are hash-like and should respond to all hash method except .length which instead will return the value of :Image_Structure_Length,
30
+ image_data = exif_data.image
31
+ thumbnail_data = exif_data.thumbnail
39
32
 
40
- # The file path or stream is passed as a parameter to class methods on FileData::Exif
41
- # rather than having the file path or stream set in the constructor and the methods
42
- # be instance methods to ensure that the user falls into a "pit of success" by only
43
- # opening the file once to get tag values rather than potentially multiple times
33
+ ## Step 3: Extract the tag values
44
34
 
45
- # Get image exif data from a file path...
46
- hash = FileData::Exif.image_data_only('/path/to/file.jpg')
47
-
48
- # Get thumbnail exif data from a file stream...
49
- File.open('/path/to/file.jpg', 'rb') do |f|
50
- hash = FileData::Exif.thumbnail_data_only(f)
51
- end
35
+ ### Step 3A: Extract tags with a known name (ones that are listed in the "Known Tag Keys" section below)
52
36
 
53
- ## Extract values depending on how much data is returned
37
+ # Convenience methods are added for the names after the last underscore in the known tag names (casing and underscores are ignored in the convenince method names)
54
38
 
55
- # Image and thumbnail data are returned as a hash with keys
56
- # being the full tag name if it exists in FileData::ExifTags (see below listing)
57
- # or "#{ifd_id}-#{tag_id}" if there is no existing name for the tag in FileData::ExifTags
58
- image_hash = FileData::Exif.image_data_only(file_path_or_stream)
59
- image_description_value = image_hash[:Other_ImageDescription]
60
- unknown_gps_tag_value = image_hash["34853-99999"]
39
+ bits_per_sample = image_data.BitsPerSample # Gets :Image_Structure_BitsPerSample from the :Tiff section
40
+ bits_per_sample = image_data.bits_per_sample # Also gets :Image_Structure_BitsPerSample from the :Tiff section
61
41
 
62
- thumbnail_hash = FileData::Exif.thumbnail_data_only(file_path_or_stream)
63
- image_width_tag_value = thumbnail_hash[:Image_Structure_Width]
64
- unknown_gps_tag_value = thumbnail_hash["Tiff-99999"]
42
+ ### Step 3B: Extract tags without a known name (ones NOT listed in the "Known Tag Keys" section below)
65
43
 
66
- all_data = FileData::Exif.all_data(file_path_or_stream)
67
- image_hash = all_data.image
68
- thumbnail_hash = all_data.thumbnail
44
+ # Use the format "#{ifd_id}-#{tag_id}" for the unknown tag to key into the data
45
+ unknown_gps_tag_value = image_data["34853-99999"]
69
46
 
70
- # For extracting only a specific tag the value is returned and the search key must be
71
- # an array matching the keys needed to get traverse FileData:ExifTags (see below listing)
72
- image_description_value = FileData::Exif.only_image_tag(file_path_or_stream, [:Tiff, 270])
73
- unknown_exif_tag_value = FileData::Exif.only_thumbnail_tag(file_path_or_stream, [34665, 2])
74
47
  ```
75
48
 
76
49
  ## Known Tag Keys
data/Rakefile CHANGED
File without changes
data/dockerfile ADDED
@@ -0,0 +1,13 @@
1
+ FROM ruby:3.0.2-alpine3.13
2
+
3
+ RUN gem install bundler
4
+
5
+ RUN apk update && apk upgrade && \
6
+ apk add --no-cache bash git openssh && \
7
+ apk add --update make && \
8
+ apk add --update gcc && \
9
+ apk add libc-dev
10
+
11
+ WORKDIR /tmp/code
12
+
13
+ CMD [ "/bin/sh" ]
data/file_data.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Scott"]
10
10
  spec.email = [""]
11
11
 
12
- spec.summary = %q{Extracts file metadata information (currently only supports exif metadata for jpeg files)}
13
- spec.description = %q{Extracts file metadata information (currently only supports exif metadata for jpeg files)}
14
- spec.homepage = ""
12
+ spec.summary = %q{Provides apis for extracting common metadata out of files as well as low level apis for advanced metadata parsing. Currently exif (jpeg/jpg) is almost entirely supported and mpeg4 (mp4,m4v,moov...) has limited support}
13
+ spec.description = %q{Provides apis for extracting common metadata out of files as well as low level apis for advanced metadata parsing. Currently exif (jpeg/jpg) is almost entirely supported and mpeg4 (mp4,m4v,moov...) has limited support. For common metadata the FileInfo class provides methods names after the metadata items taking a filename. As an example, to get the origin date of a file you would call FileData::FileInfo.origin_date(filename). Advanced apis are provided via specific classes for each metadata type. For example, Exif for exif data and Mpeg4 for mpeg4 data. These can be used to improve the performance of gathering multiple metadata values from a file}
14
+ spec.homepage = "https://github.com/ScottHaney/file_data"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.14"
34
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "bundler", "~> 2.2"
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  spec.add_development_dependency "coveralls", "~> 0.8"
37
37
  spec.add_development_dependency "fakefs", "~> 0.10"
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module FileData
2
4
  # Container for Exif tag values
3
5
  class ExifData
@@ -5,12 +7,52 @@ module FileData
5
7
  SECTIONS.each { |section| define_method(section[1]) { @hash[section[0]] } }
6
8
 
7
9
  def initialize
8
- @hash = SECTIONS.each_with_object({}) { |pair, hash| hash[pair[0]] = {} }
10
+ @hash = SECTIONS.each_with_object({}) { |pair, hash| hash[pair[0]] = ExifHash.new }
9
11
  end
10
12
 
11
13
  def add_tag(index, ifd_id, tag_id, tag_value)
12
- name = ExifTags.get_tag_name(ifd_id, tag_id)
13
- @hash[index][name] = tag_value
14
+ name_info = ExifTags.get_tag_name(ifd_id, tag_id)
15
+ @hash[index][name_info.name] = tag_value
16
+ end
17
+ end
18
+
19
+ # Hash with convenience methods for accessing known Exif tag values by name
20
+ class ExifHash < BasicObject
21
+ all_tags = ExifTags.tag_groups.values.map{|x| x.values}.flatten
22
+ tags_map = all_tags.each_with_object({}) do |tag, hash|
23
+ hash[tag.to_s.split('_').last.upcase] = tag
24
+ end
25
+
26
+ define_method(:method_missing) do |method_name, *args, &block|
27
+ known_name = tags_map[method_name.to_s.tr('_', '').upcase]
28
+
29
+ if known_name.nil?
30
+ @hash.send(method_name, *args, &block)
31
+ else
32
+ @hash[known_name]
33
+ end
34
+ end
35
+
36
+ define_method(:respond_to_missing?) do |method_name, include_private|
37
+ known_name = tags_map[method_name.to_s.tr('_', '').upcase]
38
+
39
+ if known_name.nil?
40
+ @hash.respond_to?(known_name) || super
41
+ else
42
+ true
43
+ end
44
+ end
45
+
46
+ def initialize
47
+ @hash = {}
48
+ end
49
+
50
+ def [](key)
51
+ @hash[key]
52
+ end
53
+
54
+ def []=(key, value)
55
+ @hash[key] = value
14
56
  end
15
57
  end
16
58
  end
@@ -1,11 +1,14 @@
1
1
  module FileData
2
+ TagNameInfo = Struct.new(:name, :is_known);
3
+
2
4
  # Contains tag number to name information taken from the exif spec
3
5
  class ExifTags
4
6
  singleton_class.class_eval { attr_accessor :tag_groups }
5
7
  @tag_groups = {}
6
8
 
7
9
  def self.get_tag_name(ifd_id, tag_id)
8
- get_known_name(ifd_id, tag_id) || "#{ifd_id}-#{tag_id}".to_sym
10
+ known_name = get_known_name(ifd_id, tag_id)
11
+ TagNameInfo.new(known_name || "#{ifd_id}-#{tag_id}".to_sym, known_name != nil)
9
12
  end
10
13
 
11
14
  def self.get_known_name(ifd_id, tag_id)
@@ -1,3 +1,3 @@
1
1
  module FileData
2
- VERSION = '5.2.0'.freeze
2
+ VERSION = '6.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-21 00:00:00.000000000 Z
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
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: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,8 +94,14 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.6'
97
- description: Extracts file metadata information (currently only supports exif metadata
98
- for jpeg files)
97
+ description: Provides apis for extracting common metadata out of files as well as
98
+ low level apis for advanced metadata parsing. Currently exif (jpeg/jpg) is almost
99
+ entirely supported and mpeg4 (mp4,m4v,moov...) has limited support. For common metadata
100
+ the FileInfo class provides methods names after the metadata items taking a filename.
101
+ As an example, to get the origin date of a file you would call FileData::FileInfo.origin_date(filename).
102
+ Advanced apis are provided via specific classes for each metadata type. For example,
103
+ Exif for exif data and Mpeg4 for mpeg4 data. These can be used to improve the performance
104
+ of gathering multiple metadata values from a file
99
105
  email:
100
106
  - ''
101
107
  executables: []
@@ -112,6 +118,7 @@ files:
112
118
  - LICENSE.txt
113
119
  - README.md
114
120
  - Rakefile
121
+ - dockerfile
115
122
  - file_data.gemspec
116
123
  - lib/file_data.rb
117
124
  - lib/file_data/core_extensions/binary_extensions.rb
@@ -140,12 +147,12 @@ files:
140
147
  - lib/file_data/helpers/sized_field.rb
141
148
  - lib/file_data/helpers/stream_view.rb
142
149
  - lib/file_data/version.rb
143
- homepage: ''
150
+ homepage: https://github.com/ScottHaney/file_data
144
151
  licenses:
145
152
  - MIT
146
153
  metadata:
147
154
  allowed_push_host: https://rubygems.org
148
- post_install_message:
155
+ post_install_message:
149
156
  rdoc_options: []
150
157
  require_paths:
151
158
  - lib
@@ -160,10 +167,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
167
  - !ruby/object:Gem::Version
161
168
  version: '0'
162
169
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.7.6
165
- signing_key:
170
+ rubygems_version: 3.2.22
171
+ signing_key:
166
172
  specification_version: 4
167
- summary: Extracts file metadata information (currently only supports exif metadata
168
- for jpeg files)
173
+ summary: Provides apis for extracting common metadata out of files as well as low
174
+ level apis for advanced metadata parsing. Currently exif (jpeg/jpg) is almost entirely
175
+ supported and mpeg4 (mp4,m4v,moov...) has limited support
169
176
  test_files: []