@@ -25,6 +25,7 @@ class RbPhoto
25
25
[ '--datedir' , '-D' , GetoptLong ::NO_ARGUMENT ] ,
26
26
[ '--move' , '-m' , GetoptLong ::NO_ARGUMENT ] ,
27
27
[ '--without-rename' , '-N' , GetoptLong ::NO_ARGUMENT ] ,
28
+ [ '--with-movie' , '-M' , GetoptLong ::NO_ARGUMENT ] ,
28
29
[ '--photographer' , '-p' , GetoptLong ::REQUIRED_ARGUMENT ] ,
29
30
[ '--no-act' , '-n' , GetoptLong ::NO_ARGUMENT ] ,
30
31
[ '--force' , '-f' , GetoptLong ::NO_ARGUMENT ] ,
@@ -67,6 +68,7 @@ class RbPhoto
67
68
args . each do |arg |
68
69
if ( File . directory? ( arg ) )
69
70
ret . concat ( Dir . glob ( "#{ arg } /*.{jpg,jpeg,JPG,JPEG}" ) )
71
+ ret . concat ( Dir . glob ( "#{ arg } /*.{avi,AVI,mpg,MPG}" ) ) if ( @args [ 'with_movie' ] )
70
72
else
71
73
ret . push ( arg )
72
74
end
@@ -118,16 +120,30 @@ class RbPhoto
118
120
119
121
def rename ( filename )
120
122
datedir = ''
123
+ suffix = ''
121
124
time = Time . at ( 0 )
122
- begin
123
- exif = Exif . new ( filename )
124
- time = Time . local ( *exif . datetime . split ( /[:\s ]/ ) )
125
- rescue
126
- STDERR . print "Cannot read exif data correctly: #{ filename } \n "
127
- return @dstdir + "/#{ File . basename ( filename , '.*' ) } #{ @postfix } .jpg"
125
+ case File . extname ( filename )
126
+ when /^\. avi$/i
127
+ suffix = 'avi'
128
+ time = File . mtime ( filename )
129
+ when /^\. mpe?g$/i
130
+ suffix = 'mpg'
131
+ time = File . mtime ( filename )
132
+ when /^\. jpe?g$/i
133
+ suffix = 'jpg'
134
+ begin
135
+ exif = Exif . new ( filename )
136
+ time = Time . local ( *exif . datetime . split ( /[:\s ]/ ) )
137
+ rescue
138
+ STDERR . print "Cannot read exif data correctly: #{ filename } \n "
139
+ return @dstdir + "/#{ File . basename ( filename , '.*' ) } #{ @postfix } .#{ suffix } "
140
+ end
141
+ else
142
+ STDERR . print "Unsupported filetype: #{ filename } \n "
143
+ return @dstdir + "/#{ filename } "
128
144
end
129
145
datedir = '/' + time . strftime ( '%Y-%m-%d' ) if ( @args [ 'datedir' ] )
130
- return @dstdir + datedir + "/#{ time . strftime ( '%Y%m%d-%H%M%S' ) } #{ @postfix } .jpg "
146
+ return @dstdir + datedir + "/#{ time . strftime ( '%Y%m%d-%H%M%S' ) } #{ @postfix } .#{ suffix } "
131
147
end
132
148
133
149
def help
@@ -140,6 +156,7 @@ Options:
140
156
-D, --datedir copy/move photos with datedir
141
157
-f, --force force to overwrite when move
142
158
-m, --move move photos instead of copy
159
+ -M, --with-movie process not only images but also movies
143
160
-N, --without-rename do not rename photo files
144
161
-p, --photographer=id set photographer id (default: $USER)
145
162
-n, --no-act do not copy/move only test
0 commit comments