class File
Constants
- IMAGE_EXTENSIONS
- VIDEO_EXTENSIONS
Public Class Methods
date_taken(file)
click to toggle source
# File lib/flickru/file.rb, line 50 def File.date_taken file attempt = 1 begin case attempt when 1 then EXIFR::JPEG.new(file).date_time_original.strftime "%y-%m-%d %H:%M:%S" when 2 then EXIFR::TIFF.new(file).date_time_original.strftime "%y-%m-%d %H:%M:%S" else nil end rescue attempt += 1 retry end end
duration(video)
click to toggle source
# File lib/flickru/file.rb, line 36 def File.duration video s = `#{Escape.shell_command ["ffmpeg", "-i", video]} 2>&1` if s =~ /Duration: ([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/ hours = $1.to_i mins = $2.to_i seconds = $3.to_i # fractions = ("." + $4).to_f hours * 60 * 60 + mins * 60 + seconds else 0 end end
find(dir) { |file| ... }
click to toggle source
# File lib/flickru/file.rb, line 10 def File.find dir found = Array.new Find.find dir do |file| if File.directory? file if File.basename(file)[0] == ?. Find.prune # don't look any further into this directory else next end else if yield file found << file end end end found end
geotagged?(file)
click to toggle source
# File lib/flickru/file.rb, line 64 def File.geotagged? file attempt = 1 begin case attempt when 1 then hash = EXIFR::JPEG.new(file).to_hash when 2 then hash = EXIFR::TIFF.new(file).to_hash else return false end rescue puts $! attempt += 1 retry end lat = hash.key? :gps_latitude lon = hash.key? :gps_longitude lat_ref = hash.key? :gps_latitude_ref lon_ref = hash.key? :gps_longitude_ref lat and lon and lat_ref and lon_ref end
human_readable_size(file_size)
click to toggle source
# File lib/flickru/file.rb, line 88 def File.human_readable_size file_size if file_size < 1024 ** 1 (file_size / 1024 ** 0).to_s + " bytes" elsif file_size < 1024 ** 2 (file_size / 1024 ** 1).to_s + "KB" elsif file_size < 1024 ** 3 (file_size / 1024 ** 2).to_s + "MB" else (file_size / 1024.0 ** 3).round.to_s + "GB" # with float division end end
image?(file)
click to toggle source
# File lib/flickru/file.rb, line 28 def File.image? file IMAGE_EXTENSIONS.include? File.extname(file).downcase end
video?(file)
click to toggle source
# File lib/flickru/file.rb, line 32 def File.video? file VIDEO_EXTENSIONS.include? File.extname(file).downcase end