class Mediafile
  def initialize(filename)
    @filename = filename
  end

  def date
    if(is_jpeg?)
      puts "*** found a jpeg: #{@filename}"
      exifr_date
    elsif(is_mp4?)
      puts "*** found an mp4: #{@filename}"
      mini_exif_tool_date
    else
      puts "file isn't supported: #{@filename}"
    end
  end

  def is_jpeg?
    extension = File.extname(@filename).downcase
    extension == '.jpg' || extension == '.jpeg'
  end

  def is_mp4?
    extension = File.extname(@filename).downcase
    extension == '.mp4'
  end

  private
  def exifr_date
    # GoSMS photos don't have date_time_original, but they do seem to have modification date/time. maybe I can use that?
    # date_time = exif_data.file_modification_date_time if date_time.nil? || date_time.blank? # File Modification Date/Time
    exif_data = EXIFR::JPEG.new(@filename)
    exif_data.date_time_original
  end

  def mini_exif_tool_date
    exif_data = MiniExiftool.new @filename
    exif_data['mediacreatedate']
  end
end
