コード例 #1
0
ファイル: indexbuilder.py プロジェクト: nh/imgc
def __get_date(file):
  """expect file to be an open file"""
  date_pos = file.find('_date')
  if date_pos == -1:
    try:
      exif_tags = EXIF.process_file(open(file, 'rb'))
      #we split the exif tag which look like 2004:10:20 10:55:24 to keep only the date info
      if exif_tags.has_key("EXIF DateTimeOriginal"):
        sdate = exif_tags["EXIF DateTimeOriginal"].values.split()[0].split(':')
      else:
        print '[INFO] file %s has no exif DatetimeOriginal' % (file)
        sdate = exif_tags["Image DateTime"].values.split()[0].split(':')
      return date(int(sdate[0]), int(sdate[1]), int(sdate[2]))
    except KeyError:
      #meaning the exif info is no complete, some tinkering may have happened with the image
      print '[WARN] file %s has no valid exif info' % (file)
    except:
      print '[ERR] file %s is not to the taste of EXIF.py...' % (file)
    #if no correct exif then we use the file creation date
    d = time.localtime(os.stat(file)[os.path.stat.ST_MTIME])
    return date(d[0],d[1],d[2])
  else:
    next_pos = file.find('_',date_pos+4)
    if next_pos == -1 : next_pos = file.find('.', date_pos+4)
    file_date = file[date_pos+5:next_pos]
    return date(int(file_date[:4]), int(file_date[4:6]), int(file_date[6:]))
コード例 #2
0
ファイル: indexbuilder.py プロジェクト: nh/imgc
def get_camera(file):
  """expect file to be an open file"""
  try:
    exif_tags = EXIF.process_file(open(file, 'rb'))
    #we split the exif tag which look like 2004:10:20 10:55:24 to keep only the date info
    make = str(exif_tags["Image Make"])
    model = str(exif_tags["Image Model"] )
    if make in config.redundant_model_info:
      return model
    else:
      return make + ' - ' + model
  except KeyError:
    #meaning the exif info is incorrect
    #if no correct exif then we use the file creation date
    print '[WARN] file %s has no valid exif info' % (file)
  except:
    print '[ERR] file %s is not to the taste of EXIF.py...' % (file)
  #if get_author(file) in config.default_author:
    #return config.default_camera 
  #else:
  return None