Created
October 20, 2011 11:47
-
-
Save ACUVE/1300949 to your computer and use it in GitHub Desktop.
写真の撮影日を読み込んで日付ごとに何枚撮ったか調べる何か。 ExifTool必須
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 | |
# 写真の撮影日を読み込んで適当に出力 | |
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 = /Date\/Time Original\t(\d+:\d+:\d+).+$/.match(line) | |
date = m[1] | |
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| | |
m = /(\d+):(\d+):(\d+)/.match(key) | |
puts "#{m[1]}年#{m[2]}月#{m[3]}日, #{hash[key]}".encode('Shift_JIS') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment