jmathai / elodie

An EXIF-based photo assistant, organizer and workflow automation tool.
https://bit.ly/introducing-elodie
Apache License 2.0
1.25k stars 137 forks source link

Unexpected int returned instead of string from metadata[part] in filesystem.py #454

Open muxketeer opened 1 year ago

muxketeer commented 1 year ago

On select images receiving this error:

  main()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 716, in __call_
  return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 696, in main
  rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
  return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
  return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
  return callback(*args, **kwargs)
File "./elodie.py", line 141, in _import
  trash, allow_duplicates)
File "./elodie.py", line 68, in import_file
  media, allowDuplicate=allow_duplicates, move=False)
File "/opt/elodie/elodie/filesystem.py", line 545, in process_file
  file_name = self.get_file_name(metadata)
File "/opt/elodie/elodie/filesystem.py", line 173, in get_file_name
  this_value = re.sub(self.whitespace_regex, '-', metadata[part].strip())
tributeError: 'int' object has no attribute 'strip'

Further debugging indicates that is it is due to the value of metadata[part] returning an integer, such as 106499463. Where this field typically, with other images, returns something like: jpg or mov etc..

Possibly related to #400

muxketeer commented 1 year ago

My current "fix"/hack to get around this is to change line 173 in elodie\filesystem.py from this:

 elif part in ('album', 'extension', 'title'):
                    if metadata[part]:
                        this_value = re.sub(self.whitespace_regex, '-', metadata[part].strip())
                        break

into this:

 elif part in ('album', 'extension', 'title'):
                    if metadata[part]:
                        this_value = re.sub(self.whitespace_regex, '-', str(metadata[part]).strip())
                        break

I.e. Preemptively casting the returned value of metadata[part] to always be interpreted as a string (ie. str).

However, this may not be best way to deal with whatever the root of the issue is.