-
Notifications
You must be signed in to change notification settings - Fork 11
/
file-exif-datetimeoriginal-timeshift
executable file
·59 lines (51 loc) · 1.53 KB
/
file-exif-datetimeoriginal-timeshift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env perl
use v5.18;
use strict;
use warnings;
use File::Next;
use Getopt::Long;
use Digest::SHA1;
use File::Touch;
use Image::ExifTool qw(:Public);
use Time::Moment;
sub main {
my ($opts, $args) = @_;
my ($seconds, @files) = @$args;
@files = grep { /\.(jpg|mpo)\z/i } @files;
my %plan;
for my $file (@files) {
my $exifTool = Image::ExifTool->new;
my $info = $exifTool->ExtractInfo($file);
my $dto = $exifTool->GetValue('DateTimeOriginal');
if (! $dto) {
say "SKIP: no DateTimeOriginal\t$file";
next;
}
next unless $dto =~ /\A [12][0-9]{3}:[0-9]{2}:[0-9]{2} \s [0-9]{2}:[0-9]{2}:[0-9]{2} \z/x;
my @exif_dto = split /[ :]/, $dto;
my $tm_dto = Time::Moment->new(
year => $exif_dto[0],
month => $exif_dto[1],
day => $exif_dto[2],
hour => $exif_dto[3],
minute => $exif_dto[4],
second => $exif_dto[5],
# nanosecond => 0,
# offset => 480, # UTC+0800
);
my $tm_dto_with_offset = $tm_dto->plus_seconds($seconds);
my $dto2 = $tm_dto_with_offset->strftime('%Y:%m:%d %H:%M:%S');
if ($opts->{y}) {
$exifTool->SetNewValue(DateTimeOriginal => $dto2);
$exifTool->WriteInfo($file);
} else {
say join("\t", $file, $dto, $tm_dto, $tm_dto_with_offset, $dto2);
}
}
}
my %opts;
GetOptions(
\%opts,
'y',
);
main(\%opts, [@ARGV]);