photo-helpers

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/photo-helpers.git
Log | Files | Refs | README | LICENSE

commit 5ed5d9dd14dc39f1b277e42d0b5bf2678caa9d5b
parent 797bb9957956112a8ae19e1538261e3e3c436823
Author: René Wagner <apollo@rw-net.de>
Date:   Mon, 30 Dec 2019 11:48:39 +0100

update repo and file names

Diffstat:
MREADME.md | 32++++++++++++++++++++++++++------
Mjpegdivider.pl | 4++--
Dmultiversion_sidecar_cleaner.pl | 122-------------------------------------------------------------------------------
Dorphaned_sidecar_cleaner.pl | 103-------------------------------------------------------------------------------
Asilkypix_multiversion_sidecar_cleaner.pl | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asilkypix_orphaned_sidecar_cleaner.pl | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 253 insertions(+), 233 deletions(-)

diff --git a/README.md b/README.md @@ -1,8 +1,13 @@ -# Silkypix Helper Scripts -This rather small scripts written in [Perl](https://perl.org) provide useful function for managing the sidecar data files created by [Silkypix Developer Studio](https://silkypix.isl.co.jp/en/). +# About +This rather small scripts written in [Perl](https://perl.org) provide useful function for managing For bug reports or feature requests please visit [our bugtracker](https://tracker.codewolke.net). +# Prerequisites + +- Perl 5.30 (or newer) +- Exiftool + ## required perl modules The following perl modules are required for running the scripts. @@ -14,13 +19,28 @@ The following perl modules are required for running the scripts. - File::Spec::Functions - Switch -## description +# usage +All scripts are commandline / shell tools which should run on *n*x and Windows when the prerequistes are met. + +To run a script, open a shell and invoke `perl script.pl`, on most systems it should be sufficient to just invoke `script.pl`. + +For information about parameters and usage call `script.pl -h` -### jpeg divider +# generic scripts + +## jpeg divider +Filename: `jpegdivider.pl` Moves all jpeg files (suffixes .jpg and .jpeg) in a folder to the subfolder JPEG. -### orphaned sidecar cleaner +# Silkypix helper scripts +Helper scripts to manage the sidecar data files created by [Silkypix Developer Studio](https://silkypix.isl.co.jp/en/). + +## orphaned sidecar cleaner +Filename: `silkypix_orphaned_sidecar_cleaner.pl` + Deletes all sidecar files in the given directory or alternatively in the current working directory when the associated raw file is missing. -### multiversion sidecar cleaner +## multiversion sidecar cleaner +Filename: `silkypix_multiversion_sidecar_cleaner.pl` + Deletes Silkypix Sidecar files when newer versions of the files are available. This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific. diff --git a/jpegdivider.pl b/jpegdivider.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Copyright(c) René Wagner 2019 # published under BSD 3-Clause License -# https://www.codewolke.net/silkypix-helper/ +# https://www.codewolke.net/photo-helpers/ use warnings; use strict; @@ -81,7 +81,7 @@ sub show_help say $PROGRAM . ' - version ' . $VERSION; say 'published under BSD 3 - Clause License'; say 'Copyright(c) 2019 René Wagner'; - say 'https://www.codewolke.net/silkypix-helper/'; + say 'https://www.codewolke.net/photo-helpers/'; say ''; say 'Moves JPEG files to a designated subfolder, by default "JPEG"'; say ''; diff --git a/multiversion_sidecar_cleaner.pl b/multiversion_sidecar_cleaner.pl @@ -1,122 +0,0 @@ -#!/usr/bin/perl -# Copyright(c) René Wagner 2019 -# published under BSD 3-Clause License -# https://www.codewolke.net/silkypix-helper/ - -use warnings; -use strict; -use feature qw(say); -use Cwd; -use File::Basename; -use File::Find::Rule; -use File::Find; -use Switch; - -my $VERSION = '0.2'; -my $PROGRAM = 'Multiversion Sidecar Cleaner'; - -my $delete_flag = 0; -my $delete_dir = getcwd; - -foreach my $arg ( @ARGV ) -{ - switch ( $arg ) - { - case '-h' { show_help(); exit; } - case '-d' { $delete_flag = 1; } - else { if ( -d $arg ) { $delete_dir = $arg } } - } -} - -main($delete_dir, $delete_flag); - -exit 0; - -sub main -{ - my ( $dir, $delete ) = @_; - my ( $delcounter ) = 0; - - say "working directory: $delete_dir"; - say 'action : '. ($delete_flag ? 'delete' : 'list only') . "\r\n"; - say 'files with newer versions:'; - - # alle Dateien in allen Unterordnern *.spd *.spf suchen - - my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); - - foreach my $file ( @files ) - { - if ( exist_newer_file($file) ) - { - print $file .'...'; - $delcounter++; - if ( $delete ) - { - if ( unlink $file ) - { - print 'deleted.' - } - else - { - print " deletion failed: $!"; - } - } - say ''; - } - } - - say "\r\nfound $delcounter duplicate file versions."; -} - -sub exist_newer_file -{ - my ( $original_file ) = @_; - - if ( -f $original_file ) - { - # build the regex for newer versions - # the version must be atleast 1 above the current version - my $filename = basename($original_file); - my @fileparts = split /\./, $filename; - - my $version_regex; - # HACK: file versions greater 8 will not be checked as the regex can't handle that atm - if ( $fileparts[2] > 8 ) - { - return 0; - } - else - { - $version_regex = '['. ($fileparts[2] + 1) .'-9]'; - } - - my $filefinder_regex = "$fileparts[0]\\.$fileparts[1]\\.$version_regex\\.$fileparts[3]"; - my @version_files = File::Find::Rule->file->name( qr/$filefinder_regex/i )->in( dirname($original_file) ); - - if ( scalar @version_files ) - { - return 1; - } - } - - return 0; -} - -sub show_help -{ - say $PROGRAM . ' - version ' . $VERSION; - say 'published under BSD 3 - Clause License'; - say 'Copyright(c) 2019 René Wagner'; - say 'https://www.codewolke.net/silkypix-helper/'; - say ''; - say 'Deletes Silkypix Sidecar files when newer versions of the files are available.'; - say 'This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific.'; - say ''; - say 'commandline parameters:'; - say 'duplicate_sidecar_cleaner.pl - list duplicate sidecar file versions in current working directory and subfolders'; - say 'duplicate_sidecar_cleaner.pl -d - delete duplicate sidecar file versions in given directory and subfolders'; - say 'duplicate_sidecar_cleaner.pl <folder> - list duplicate sidecar file versions in given directory and subfolders'; - say 'duplicate_sidecar_cleaner.pl -d <folder> - delete duplicate sidecar file versions in given directory and subfolders'; - say 'duplicate_sidecar_cleaner.pl -h - show this help'; -} diff --git a/orphaned_sidecar_cleaner.pl b/orphaned_sidecar_cleaner.pl @@ -1,103 +0,0 @@ -#!/usr/bin/perl -# Copyright(c) René Wagner 2019 -# published under BSD 3-Clause License -# https://www.codewolke.net/silkypix-helper/ - -use warnings; -use strict; -use feature qw(say); -use Cwd; -use File::Basename; -use File::Find::Rule; -use File::Find; -use File::Spec::Functions; -use Switch; - -my $VERSION = '0.3'; -my $PROGRAM = 'Orphaned Sidecar Cleaner'; - -# parse commandline args -# last dir will win -my $delete_flag = 0; -my $delete_dir = getcwd; - -foreach my $arg ( @ARGV ) -{ - switch ( $arg ) - { - case '-h' { show_help(); exit; } - case '-d' { $delete_flag = 1; } - else { if ( -d $arg ) { $delete_dir = $arg } } - } -} - -main($delete_dir, $delete_flag); - -exit 0; - -sub main -{ - my ( $dir, $delete ) = @_; - my ( $delcounter ) = 0; - - say "working directory: $delete_dir"; - say 'action : '. ($delete_flag ? 'delete' : 'list only') ."\r\n"; - say 'files with missing raw:'; - - # alle Dateien in allen Unterordnern *.spd *.spf suchen - my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); - - foreach my $file ( @files ) - { - if ( ! exists_raw_filename($file) ) - { - print $file .'...'; - $delcounter++; - if ( $delete ) - { - if ( unlink $file ) - { - print 'deleted.'; - } - else - { - print " deletion failed: $!"; - } - } - say ''; - } - } - - say "\r\nfound $delcounter orphaned sidecar files found."; -} - -sub exists_raw_filename -{ - my ( $original_file ) = @_; - - my ( $filename, $dirs ) = fileparse($original_file); - # Silkypix Sidecar files reside in a "SILKYPIX_DS" folder, so we need to search in the parent folder - $filename =~ s/\.\d+\.sp.$//g; - if ( -f catfile(dirname($dirs), $filename) ) - { - return 1; - } - return 0; -} - -sub show_help -{ - say $PROGRAM . ' - version ' . $VERSION; - say 'published under BSD 3 - Clause License'; - say 'Copyright(c) 2019 René Wagner'; - say 'https://www.codewolke.net/silkypix-helper/ '; - say ''; - say 'Deletes Silkypix Sidecar files when corresponding RAW files are missing.'; - say ''; - say 'commandline parameters:'; - say 'orphaned_sidecar_cleaner.pl - list orphaned sidecar file in current working directory and subfolders'; - say 'orphaned_sidecar_cleaner.pl -d - delete orphaned sidecar file in current working directory and subfolders'; - say 'orphaned_sidecar_cleaner.pl <folder> - list orphaned sidecar file in given directory and subfolders'; - say 'orphaned_sidecar_cleaner.pl -d <folder> - delete orphaned sidecar file in given directory and subfolders'; - say 'orphaned_sidecar_cleaner.pl -h - show this help'; -} diff --git a/silkypix_multiversion_sidecar_cleaner.pl b/silkypix_multiversion_sidecar_cleaner.pl @@ -0,0 +1,122 @@ +#!/usr/bin/perl +# Copyright(c) René Wagner 2019 +# published under BSD 3-Clause License +# https://www.codewolke.net/photo-helpers/ + +use warnings; +use strict; +use feature qw(say); +use Cwd; +use File::Basename; +use File::Find::Rule; +use File::Find; +use Switch; + +my $VERSION = '0.2'; +my $PROGRAM = 'Multiversion Sidecar Cleaner'; + +my $delete_flag = 0; +my $delete_dir = getcwd; + +foreach my $arg ( @ARGV ) +{ + switch ( $arg ) + { + case '-h' { show_help(); exit; } + case '-d' { $delete_flag = 1; } + else { if ( -d $arg ) { $delete_dir = $arg } } + } +} + +main($delete_dir, $delete_flag); + +exit 0; + +sub main +{ + my ( $dir, $delete ) = @_; + my ( $delcounter ) = 0; + + say "working directory: $delete_dir"; + say 'action : '. ($delete_flag ? 'delete' : 'list only') . "\r\n"; + say 'files with newer versions:'; + + # alle Dateien in allen Unterordnern *.spd *.spf suchen + + my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); + + foreach my $file ( @files ) + { + if ( exist_newer_file($file) ) + { + print $file .'...'; + $delcounter++; + if ( $delete ) + { + if ( unlink $file ) + { + print 'deleted.' + } + else + { + print " deletion failed: $!"; + } + } + say ''; + } + } + + say "\r\nfound $delcounter duplicate file versions."; +} + +sub exist_newer_file +{ + my ( $original_file ) = @_; + + if ( -f $original_file ) + { + # build the regex for newer versions + # the version must be atleast 1 above the current version + my $filename = basename($original_file); + my @fileparts = split /\./, $filename; + + my $version_regex; + # HACK: file versions greater 8 will not be checked as the regex can't handle that atm + if ( $fileparts[2] > 8 ) + { + return 0; + } + else + { + $version_regex = '['. ($fileparts[2] + 1) .'-9]'; + } + + my $filefinder_regex = "$fileparts[0]\\.$fileparts[1]\\.$version_regex\\.$fileparts[3]"; + my @version_files = File::Find::Rule->file->name( qr/$filefinder_regex/i )->in( dirname($original_file) ); + + if ( scalar @version_files ) + { + return 1; + } + } + + return 0; +} + +sub show_help +{ + say $PROGRAM . ' - version ' . $VERSION; + say 'published under BSD 3 - Clause License'; + say 'Copyright(c) 2019 René Wagner'; + say 'https://www.codewolke.net/photo-helpers/'; + say ''; + say 'Deletes Silkypix Sidecar files when newer versions of the files are available.'; + say 'This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific.'; + say ''; + say 'commandline parameters:'; + say 'duplicate_sidecar_cleaner.pl - list duplicate sidecar file versions in current working directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl -d - delete duplicate sidecar file versions in given directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl <folder> - list duplicate sidecar file versions in given directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl -d <folder> - delete duplicate sidecar file versions in given directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl -h - show this help'; +} diff --git a/silkypix_orphaned_sidecar_cleaner.pl b/silkypix_orphaned_sidecar_cleaner.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl +# Copyright(c) René Wagner 2019 +# published under BSD 3-Clause License +# https://www.codewolke.net/photo-helpers/ + +use warnings; +use strict; +use feature qw(say); +use Cwd; +use File::Basename; +use File::Find::Rule; +use File::Find; +use File::Spec::Functions; +use Switch; + +my $VERSION = '0.3'; +my $PROGRAM = 'Orphaned Sidecar Cleaner'; + +# parse commandline args +# last dir will win +my $delete_flag = 0; +my $delete_dir = getcwd; + +foreach my $arg ( @ARGV ) +{ + switch ( $arg ) + { + case '-h' { show_help(); exit; } + case '-d' { $delete_flag = 1; } + else { if ( -d $arg ) { $delete_dir = $arg } } + } +} + +main($delete_dir, $delete_flag); + +exit 0; + +sub main +{ + my ( $dir, $delete ) = @_; + my ( $delcounter ) = 0; + + say "working directory: $delete_dir"; + say 'action : '. ($delete_flag ? 'delete' : 'list only') ."\r\n"; + say 'files with missing raw:'; + + # alle Dateien in allen Unterordnern *.spd *.spf suchen + my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); + + foreach my $file ( @files ) + { + if ( ! exists_raw_filename($file) ) + { + print $file .'...'; + $delcounter++; + if ( $delete ) + { + if ( unlink $file ) + { + print 'deleted.'; + } + else + { + print " deletion failed: $!"; + } + } + say ''; + } + } + + say "\r\nfound $delcounter orphaned sidecar files found."; +} + +sub exists_raw_filename +{ + my ( $original_file ) = @_; + + my ( $filename, $dirs ) = fileparse($original_file); + # Silkypix Sidecar files reside in a "SILKYPIX_DS" folder, so we need to search in the parent folder + $filename =~ s/\.\d+\.sp.$//g; + if ( -f catfile(dirname($dirs), $filename) ) + { + return 1; + } + return 0; +} + +sub show_help +{ + say $PROGRAM . ' - version ' . $VERSION; + say 'published under BSD 3 - Clause License'; + say 'Copyright(c) 2019 René Wagner'; + say 'https://www.codewolke.net/photo-helpers/'; + say ''; + say 'Deletes Silkypix Sidecar files when corresponding RAW files are missing.'; + say ''; + say 'commandline parameters:'; + say 'orphaned_sidecar_cleaner.pl - list orphaned sidecar file in current working directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl -d - delete orphaned sidecar file in current working directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl <folder> - list orphaned sidecar file in given directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl -d <folder> - delete orphaned sidecar file in given directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl -h - show this help'; +}