-
-
Save shoorick/483212 to your computer and use it in GitHub Desktop.
| !Build/ | |
| .last_cover_stats | |
| /META.yml | |
| /META.json | |
| /MYMETA.* | |
| *.o | |
| *.pm.tdy | |
| *.bs | |
| # Devel::Cover | |
| cover_db/ | |
| # Devel::NYTProf | |
| nytprof.out | |
| # Dizt::Zilla | |
| /.build/ | |
| # Module::Build | |
| _build/ | |
| Build | |
| Build.bat | |
| # Module::Install | |
| inc/ | |
| # ExtUtils::MakeMaker | |
| /blib/ | |
| /_eumm/ | |
| /*.gz | |
| /Makefile | |
| /Makefile.old | |
| /MANIFEST.bak | |
| /pm_to_blib | |
| /*.zip | |
| # Komodo IDE | |
| *.komodoproject | |
| .komodotools |
Move images and group them together
Move images from removable memory card to HDD:
- remove leading letters from its names,
- lowercase these names,
- attempt to create subfolder named as
year/month/day - move file into this subfolder
- and then change file mode of moved file.
./move-images.pl [ options ] [ path-to-memory-card ]
-s, --src, --source=PATH
Use PATH for source instead of (first-argument)/DCIM
-d, --dst, --destination=PATH
Use PATH for destination instead of ~/photo/*
-p, --precision=LEVEL
Set precision for grouping of photos.
Allowed values are from 0 for year
through default value 2 for day up to 5 for second.
-r, --retries=NUMBER
Retry reading attempts when error occurs. Disabled by default.
-w, --wait=SECONDS
Waiting time (in seconds) between --retries. Default value is 5.
--chmod=MODE
Change mode of processed files to MODE.
-k, --keep-prefix
Do not remove non-digital prefixes from names of files.
-?, -h, --help
Print a brief help message and exit.
-m, --man, --manual
Prints the manual page and exit.
-v, --verbose
Be verbose. Show names of processed files.
Alexander Sapozhnikov http://shoorick.ru/ shoorick@cpan.org
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| #!/usr/bin/perl -wl | |
| =head1 NAME | |
| move-images - move images and group them together. | |
| =head1 DESCRIPTION | |
| Move images from memory card to HDD: | |
| remove leading letters from its names, lowercase these names, | |
| attempt to create subfolder named as I<year>/I<month>/I<day> | |
| and move file into this subfolder and change file mode of moved file. | |
| =head1 USAGE | |
| ./move-images [ options ] [ path-to-memory-card ] | |
| =head1 OPTIONS | |
| =over 4 | |
| =item B<-s>, B<--src>, B<--source>=C<PATH> | |
| Use C<PATH> for source instead of (first-argument)/DCIM | |
| =item B<-d>, B<--dst>, B<--destination>=C<PATH> | |
| Use C<PATH> for destination instead of ~/photo/* | |
| =item B<-p>, B<--precision>=C<LEVEL> | |
| Set precision for grouping of photos. | |
| Allowed values are from C<0> for year | |
| through default value C<2> for day up to C<5> for second. | |
| =item B<-r>, B<--retries>=C<NUMBER> | |
| Retry reading attempts when error occurs. Disabled by default. | |
| =item B<-w>, B<--wait>=C<SECONDS> | |
| Waiting time (in seconds) between C<--retries>. Default value is C<5>. | |
| =item B<--chmod>=C<MODE> | |
| Change mode of processed files to C<MODE>. | |
| =item B<-k>, B<--keep-prefix> | |
| Do not remove non-digital prefixes from names of files. | |
| =item B<-?>, B<-h>, B<--help> | |
| Print a brief help message and exit. | |
| =item B<-m>, B<--man>, B<--manual> | |
| Prints the manual page and exit. | |
| =item B<-v>, B<--verbose> | |
| Be verbose. Show names of processed files. | |
| =back | |
| =head1 LEGACY TUNING | |
| Tuning by source code editing is B<deprecated> now. | |
| Use options instead (see above). | |
| =head1 AUTHOR | |
| Alexander Sapozhnikov | |
| L<< http://shoorick.ru/ >> | |
| L<< E<lt>shoorick@cpan.orgE<gt> >> | |
| =head1 LICENSE | |
| This program is free software, you can redistribute it and/or modify | |
| it under the same terms as Perl itself. | |
| =cut | |
| use strict; | |
| use File::Find; | |
| use File::Path qw(make_path); | |
| use File::Copy; | |
| use Getopt::Long; | |
| use Image::ExifTool qw(:Public); | |
| use Desktop::Notify; | |
| map { $_ = '' } my ( | |
| $need_help, $need_manual, $verbose, | |
| $path_src, $keep_prefix, $retries, | |
| ); | |
| my $path_dst = $ENV{'HOME'} . '/photo'; # path to destination. Don't use ~ for your homedir | |
| my $precision = 2; # 0 for year .. 5 for second | |
| my $mode = 0644; # for chmod | |
| my $wait = 5; | |
| GetOptions( | |
| 'help|?' => \$need_help, | |
| 'manual' => \$need_manual, | |
| 'verbose' => \$verbose, | |
| 'precision:i' => \$precision, | |
| 'source|src:s' => \$path_src, | |
| 'destination|dst:s' => \$path_dst, | |
| 'chmod:s' => \$mode, | |
| 'keep_prefix' => \$keep_prefix, | |
| ); | |
| use Pod::Usage qw( pod2usage ); | |
| pod2usage('verbose' => 2) | |
| if $need_manual; | |
| # print help message when required arguments are omitted | |
| pod2usage(1) | |
| if $need_help; | |
| unless ( $path_src ) { | |
| $path_src = shift @ARGV || '/media/nikon'; # path to memory card | |
| $path_src .= '/DCIM'; | |
| } | |
| find( \&wanted, $path_src ); | |
| # Say when ended | |
| my $summary = 'Photos was moved'; | |
| my $message = 'You can unmount your memory card'; | |
| if ( $ENV{'DISPLAY'} ) { | |
| my $notify = Desktop::Notify->new(); | |
| my $notification = $notify->create( | |
| 'summary' => $summary, | |
| 'body' => $message, | |
| 'timeout' => 5000, | |
| ); | |
| $notification->show(); | |
| $notification->close(); | |
| } | |
| else { | |
| print STDERR "$summary. $message." if $verbose; | |
| } | |
| exit; | |
| sub wanted { | |
| return unless /\.(3gp|avi|cr2|crw|dng|jpe?g|mov|nef|raf|raw|tiff?)/i; | |
| my $new_name = lc $_; | |
| $new_name =~ s/^\D+// unless $keep_prefix; | |
| my $info = ImageInfo( $File::Find::name ); | |
| print STDERR "$info->{'Error'} - $info->{'Directory'}/$info->{'FileName'}" | |
| if exists $info->{'Error'}; | |
| return unless $info->{'DateTimeOriginal'}; | |
| my @date = split /\D+/, $info->{'DateTimeOriginal'}; | |
| $#date = $precision; | |
| my $new_dir = join '/', $path_dst, @date; | |
| make_path $new_dir | |
| unless -d $new_dir; | |
| my $new_path = "$new_dir/$new_name"; | |
| -d $new_dir | |
| and move $File::Find::name, $new_path | |
| and chmod $mode, $new_path | |
| and $verbose and print STDERR "$File::Find::name => $new_path"; | |
| } # sub wanted |
Documentation in Russian
Описание
Перемещает картинки между каталогами (например, с карты памяти на жёсткий диск):
Использование
Программа запускается с необязательными параметрами, в том числе путём к исходному каталогу, откуда надо забрать файлы:
При монтировании карты памяти в оконной среде GNOME можно запустить эту программу — GNOME передаст в программу путь к точке монтирования в качестве параметра.
Параметры
-s, --src, --source=
ПУТЬКопировать файлы из указанного
ПУТИвместо (первый-аргумент)/DCIM-d, --dst, --destination=
ПУТЬКопировать файлы в папку с указанным
ПУТЁМ, а не в ~/photo/*-p, --precision=
ТОЧНОСТЬЗадаёт точность группировки скопированных файлов.
Допустимые значения — от 0 (все файлы одного года помещаются в общую папку) через 2 (по папке для каждого дня — значение по умолчанию) до 5 (папка для каждой секунды).
--chmod=
ПРАВАЗадаёт
ПРАВАкопируемым файлам.ПРАВАуказываются в восьмеричном виде с ведущим нулём (например,0644соответствует-rw-r--r--).-k, --keep-prefix
Не удалять нецифровые префиксы имён файлов.
-?, -h, --help
Выводит краткую справку и завершает работу.
-m, --man, --manual
Выводит подробное руководство и завершает работу.
-v, --verbose
Выводит имена обрабатываемых файлов. По умолчанию отключено.
Лицензия
Программа является свободным программным обеспечением, вы можете распространять или модифицировать её на тех же условиях, что и Perl.