Created
December 13, 2011 12:53
-
-
Save ACUVE/1472036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# 写真の焦点距離を読み込んで適当に出力(ExifTools必須) | |
THREAD_NUM = 4 | |
dirname = (ARGV.length < 1 ? '.' : ARGV[0]) + '/**/*' | |
filereg = ARGV.length < 2 ? /\.jpe?g$/i : Regexp.new(ARGV[1], Regexp::IGNORECASE) | |
filelist = Dir.glob(dirname).reject{|name| !(File.file?(name) && File.basename(name) =~ filereg)} | |
hash = Hash.new | |
mutex1 = Mutex.new | |
count = 0 | |
Array.new(THREAD_NUM) do |i| | |
Thread.new do | |
for j in (filelist.size / THREAD_NUM * i + [i, filelist.size % THREAD_NUM].min)...(filelist.size / THREAD_NUM * (i + 1) + [i + 1, filelist.size % THREAD_NUM].min) | |
filename = filelist[j] | |
IO.popen(('ExifTool "' + File.realpath(filename) + '" -t').encode('Shift_JIS'), 'r+') do |io| | |
while line = io.gets | |
begin | |
if m = /Focal Length\t[^(]+\(35 mm equivalent: (\d+(?:\.\d+)?).+$/.match(line) | |
date = m[1].to_f | |
mutex1.synchronize do | |
if hash[date] | |
hash[date] += 1 | |
else | |
hash[date] = 1 | |
end | |
count += 1 | |
$stderr.puts "#{count} / #{filelist.size}" | |
end | |
end | |
rescue | |
end | |
end | |
end | |
end | |
end | |
end.each{|t| t.join} | |
hash.keys.sort.each do |key| | |
puts "#{key}mm: #{hash[key]}".encode('Shift_JIS') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment