Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

jpg2xml: Added '--recursive' option; better error handling.

  • Loading branch information...
commit fe2596003b867800712990c2d590a94dd668cf1c 1 parent 459f2ba
@blackwinter authored
Showing with 22 additions and 7 deletions.
  1. +22 −7 jpg2xml
View
29 jpg2xml
@@ -16,15 +16,20 @@ rescue LoadError => err
end
end
-jfile = java.io.File
-reader = com.drew.imaging.jpeg.JpegMetadataReader
-
-puts '<root>'
+JavaFile = java.io.File
+JavaJpeg = com.drew.imaging.jpeg
+
+def print_row(file)
+ metadata = begin
+ JavaJpeg.JpegMetadataReader.read_metadata(JavaFile.new(file))
+ rescue JavaJpeg.JpegProcessingException => err
+ warn "#{err}: #{file}"
+ return
+ end
-ARGV.each { |file|
puts '<row>'
- reader.read_metadata(jfile.new(file)).directory_iterator.each { |directory|
+ metadata.directory_iterator.each { |directory|
directory.tag_iterator.each { |tag|
name = "#{directory.name}_#{tag.tag_name}".gsub(/[^\w:.-]/, '_')
puts ' <%s>%s</%s>' % [name, tag.description, name]
@@ -32,6 +37,16 @@ ARGV.each { |file|
}
puts '</row>'
-}
+end
+
+puts '<root>'
+
+if ARGV.delete('-r') || ARGV.delete('--recursive')
+ require 'find'
+
+ Find.find(*ARGV) { |file| print_row(file) if File.file?(file) }
+else
+ ARGV.each { |file| print_row(file) }
+end
puts '</root>'
Please sign in to comment.
Something went wrong with that request. Please try again.