Pastebin
Paste #10513: No description
< previous paste - next paste>
Pasted by Anonymous Coward
#!/bin/zsh
# enable extended globbing required for the folder matching we do here
setopt extendedglob
# Folder in which the low res copies will be created
dest_folder="../view_copy"
# Compression factor: must be between 0.99.
# Higher means higher quality but bigger size
quality="60"
resolution="1920x1920"
# Create folder structure in destination that matches that of source.
# Create only folders matching the following:
# Must be in a year folder (e.g. a folder matching 2???)
# Must be inside an album (e.g. a folder inside a year folder starting with an isodate - matching 2*
# Ignore folders named "private" or "privat".
#
# Match all folders matching 2???/2* and all their subfolders, except if any of those folders are called 'private'
( for x in 2???/2*/(^(private|privat)/)#(/); do mkdir -p $dest_folder/$x; done )
# Create folder structure for "in" folders
( for x in 2???/in/(^(private|privat)/)#(/); do mkdir -p $dest_folder/$x; done )
# Delete files in destination that do not exist in the source
for x in $dest_folder/**/*(.); do
orig=${x#$dest_folder/}
[[ -e $orig ]] || delete_candidates+=($x)
done
(( $#delete_candidates > 0 )) && rmdir $delete_candidates
rm -fv $delete_candidates
# Delete folders in destination that do not exist in the source
for folder in $dest_folder/**/*(/); do
orig=${folder#$dest_folder/}
[[ -e $orig ]] || delete_candidates+=($folder)
done
# Delete the delete candidates unless the list is empty
(( $#delete_candidates > 0 )) && rmdir $delete_candidates
# TODO: Save patterns for private folders and photo extensions in variables
private_folders="(private|privat)"
photo_extensions="(jpg|JPG|jpeg)"
#for x in $year/2*/(^($~private_folders)/)#/*.($~photo_extensions)(N) ; do
# TODO: Support video files: for all *.(mov|mp4|avi) files: create hardlinks in $destination
# Generate low res copies of photos in YYYY/YY-MM-DD-album
for year in 20??; do
time (
echo $year STARTING
for x in $year/2*/(^($~private_folders)/)#/*.($~photo_extensions)(N) ; do
echo $x
exit 0
# Check if $dest_folder/$x older than $x
if [[ ! -e "$dest_folder/$x" ]] || [[ "$x" -nt "$dest_folder/$x" ]] ; then
#echo Updating $x
nice convert -quiet -quality $quality -resize $resolution $x $dest_folder/$x
echo -n .
else
#echo Skipping $x
#echo -n _
fi
done
echo
echo $year DONE
) &
#exit
exit 0
done
exit 0
# Generate low res copies of photos in YYYY/in/YY-MM-DD-album
for year in 20??; do
time (
echo $year STARTING
for x in $year/in/(^(private|privat)/)#/*.(jpg|JPG)(N) ; do
# Check if $dest_folder/$x older than $x
if [[ ! -e "$dest_folder/$x" ]] || [[ "$x" -nt "$dest_folder/$x" ]] ; then
#echo Updating $x
nice convert -quiet -quality $quality -resize $resolution $x $dest_folder/$x
echo -n :
else
#echo Skipping $x
#echo -n _
fi
done
echo
echo $year DONE
) &
#exit
done
echo "Waiting for processes to complete"
wait
echo "DONE"
New Paste
Go to most recent paste.