forked from brablc/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
photos-rename-export-dirs
executable file
·71 lines (58 loc) · 1.52 KB
/
photos-rename-export-dirs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
use strict;
my $importdir = shift @ARGV || ".";
chdir $importdir;
my %months = (
'January' => 1,
'February' => 2,
'March' => 3,
'April' => 4,
'May' => 5,
'June' => 6,
'July' => 7,
'August' => 8,
'September' => 9,
'October' => 10,
'November' => 11,
'December' => 12,
'ledna' => 1,
'února' => 2,
'března' => 3,
'dubna' => 4,
'května' => 5,
'června' => 6,
'července' => 7,
'srpna' => 8,
'září' => 9,
'října' => 10,
'listopadu' => 11,
'prosince' => 12,
);
my @DIRS = sort grep { chop; /.{2,}/ } `gfind -type d`;
for my $dir (@DIRS) {
if ($dir =~ /((?<name>.*), )?(?<day>\d+) (?<month>\w+) (?<year>\d+)/) {
}
elsif ( $dir =~ /((?<name>.*), )?(?<day>\d+)\. (?<month>\w+) (?<year>\d+)/ ) {
}
else {
print STDERR "-W|Directory '$dir' not matching export format from Apple Photos!\n";
next;
}
my $name = '';
if ($+{name}) {
$name = $+{name};
$name =~ s@^\./@@;
$name =~ s/(.*),\1/$1/;
$name = ' ' . $name;
}
my $targetDir = sprintf '%04d-%02d-%02d%s', ($+{year}, $months{ $+{month} }, $+{day}, $name);
if (! -d $targetDir) {
$dir =~ s/'/'\\''/g;
$targetDir =~ s/'/'\\''/g;
printf "mv -v '%s' '%s'\n", ($dir, $targetDir);
}
else {
print STDERR "-W|Directory '$targetDir' exists!. Skipping '$dir'.\n";
}
}
print STDERR "-I|Process the output as shell commands.\n";