janfri / mini_exiftool

This library is a wrapper for the Exiftool command-line application (https://exiftool.org) written by Phil Harvey. It provides the full power of Exiftool to Ruby: reading and writing of EXIF-data, IPTC-data and XMP-data. Branch master is for actual development and branch compatibility-version is for compatibility with Ruby 1.8 and exiftool versions prior 7.65.
GNU Lesser General Public License v2.1
213 stars 52 forks source link

Add support to get tags from network files using -fast option #15

Closed fcy closed 8 years ago

fcy commented 10 years ago

ExifTool supports a very awesome option to load Exif data from slow network connections without the need to download a big photo file. I'd like to implement support for this option in MiniExifTool.

This is the CLI to use the -fast option:

wget -qO - http://farm6.staticflickr.com/5015/5458914734_8fd3f33278_o.jpg | exiftool -fast -

My idea if to create an initializer that receives the URL to the file and pipes it to exiftool -fast and then uses the already existing parse_output.

I've a few implementation questions:

  1. wget is not available in every SO. Any ideas on how to do the "download pipe" using pure Ruby classes? Any other command that is more widely available?
  2. I don't know the code base. Any tips on how to implement this?

What do you think?

fcy commented 10 years ago

In case, there's no good way to replace wget or you think it should get in the project because it would increase complexity. I just found the following way of achieving the goal:

json_str = `wget -qO - http://farm6.staticflickr.com/5015/5458914734_8fd3f33278_o.jpg | exiftool -fast2 -`
exif = MiniExiftool.from_json(json_str)
exif.datetimeoriginal
# => 2011-02-15 08:27:51 -0200

It works for me. But I'd be interested in a discussion what other ways it could be done.

janfri commented 10 years ago

Interesting idea. Didn't know the -fast option until now. ;-)

At the moment I don't see a simple solution that is universally applicable.

janfri commented 8 years ago

@fcy MiniExiftool now supports es well as IO instances as the options fast and fast2. Checkout version 2.7.0.

Use Ruby standard lib

require 'mini_exiftool'
require 'net/http'
require 'open3'

uri = URI('http://farm6.staticflickr.com/5015/5458914734_8fd3f33278_o.jpg')
output, input = IO.pipe

# Reading asynchron
Thread.new do
  Net::HTTP.start(uri.host, uri.port) do |http|
    request = Net::HTTP::Get.new uri
    http.request request do |response|
      response.read_body do |chunk|
        input.write chunk
      end
    end
  end
  io.close
end

exif = MiniExiftool.new output, fast2: true
puts exif.datetimeoriginal

Use curl

require 'mini_exiftool'
require 'open3'

input, output = Open3.popen3('curl -s http://farm6.staticflickr.com/5015/5458914734_8fd3f33278_o.jpg')
input.close

exif = MiniExiftool.new output, fast2: true
puts exif.datetimeoriginal