Skip to content

Commit 26236cb

Browse files
committed
Add to rename and copy/move also movies not only images
1 parent 38eb39d commit 26236cb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

bin/rbphoto-import

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class RbPhoto
2525
['--datedir', '-D', GetoptLong::NO_ARGUMENT],
2626
['--move', '-m', GetoptLong::NO_ARGUMENT],
2727
['--without-rename', '-N', GetoptLong::NO_ARGUMENT],
28+
['--with-movie', '-M', GetoptLong::NO_ARGUMENT],
2829
['--photographer', '-p', GetoptLong::REQUIRED_ARGUMENT],
2930
['--no-act', '-n', GetoptLong::NO_ARGUMENT],
3031
['--force', '-f', GetoptLong::NO_ARGUMENT],
@@ -67,6 +68,7 @@ class RbPhoto
6768
args.each do |arg|
6869
if (File.directory?(arg))
6970
ret.concat(Dir.glob("#{arg}/*.{jpg,jpeg,JPG,JPEG}"))
71+
ret.concat(Dir.glob("#{arg}/*.{avi,AVI,mpg,MPG}")) if ( @args['with_movie'] )
7072
else
7173
ret.push(arg)
7274
end
@@ -118,16 +120,30 @@ class RbPhoto
118120

119121
def rename(filename)
120122
datedir = ''
123+
suffix = ''
121124
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}"
128144
end
129145
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}"
131147
end
132148

133149
def help
@@ -140,6 +156,7 @@ Options:
140156
-D, --datedir copy/move photos with datedir
141157
-f, --force force to overwrite when move
142158
-m, --move move photos instead of copy
159+
-M, --with-movie process not only images but also movies
143160
-N, --without-rename do not rename photo files
144161
-p, --photographer=id set photographer id (default: $USER)
145162
-n, --no-act do not copy/move only test

debian/changelog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ rbphoto (0.1.4) unstable; urgency=low
44
- Use fileutils feature to show verbose output
55
* Add "--force" option to overwrite when the file exists
66
* Show more errors
7+
* Add to rename and copy/move also movies not only images
78

8-
-- Taku YASUI <[email protected]> Thu, 19 Jun 2008 04:25:08 +0900
9+
-- Taku YASUI <[email protected]> Thu, 19 Jun 2008 05:03:37 +0900
910

1011
rbphoto (0.1.3) unstable; urgency=low
1112

0 commit comments

Comments
 (0)