Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.6 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
12 years ago
13 years ago
  1. #!/usr/bin/env perl
  2. =pod
  3. =head1 NAME
  4. photocp - copy files from digital camera media to my home dir
  5. =head1 SYNOPSIS
  6. # try a couple of defaults
  7. photocp
  8. # look in source_directory
  9. photocp [source_directory]
  10. =head1 AUTHOR
  11. Brennen Bearnes <bbearnes@gmail.com>
  12. =cut
  13. use strict;
  14. use warnings;
  15. use 5.10.0;
  16. use POSIX qw(strftime);
  17. use File::Basename;
  18. use File::Copy;
  19. use File::Find;
  20. use File::HomeDir;
  21. my $home = File::HomeDir->my_home;
  22. my @sources = (
  23. '/media/' . $ENV{'USER'} . '/EOS_DIGITAL',
  24. '/media/' . $ENV{'USER'} . '/CANON_DC',
  25. '/media/' . $ENV{'USER'} . '/NIKON D600',
  26. '/media/CANON_DC',
  27. '/media/EOS_DIGITAL',
  28. '/media/disk/DCIM',
  29. '/media/NIKON D600'
  30. );
  31. # strftime doesn't have a non-zero-padded month/day?
  32. # am i an idiot?
  33. my @t = localtime;
  34. my $daydir = strftime("%Y-%m-%e", @t);
  35. $daydir =~ s{-[0 ]}{-}g;
  36. my $src;
  37. if ((defined $ARGV[0]) && (-d $ARGV[0])) {
  38. $src = $ARGV[0];
  39. } else {
  40. foreach my $source (@sources) {
  41. if (-d $source) {
  42. $src = $source;
  43. last;
  44. }
  45. }
  46. unless ($src) {
  47. die 'source not mounted? tried ' . join(' ', @sources);
  48. }
  49. }
  50. my $dest = $home . '/photos/' . $daydir;
  51. if ((-e $dest) && (! -d $dest)) {
  52. die 'target exists but is not a directory';
  53. }
  54. if (! -d $dest) {
  55. say "creating $dest";
  56. mkdir($dest);
  57. } else {
  58. say "$dest exists";
  59. }
  60. my $count = 0;
  61. find(
  62. sub {
  63. if ( /[.] (jpe?g | mpe?g | avi | raw | cr2 | tiff? | bmp | gif | mov) $/ix ) {
  64. $count++;
  65. say "copying $File::Find::name to $dest/$_";
  66. copy($File::Find::name, "$dest/$_")
  67. or die "Copy failed: $!";
  68. }
  69. },
  70. $src
  71. );
  72. say "$count files copied";