#./add_file_to_media_library.sh <filename>
- export PREFIX = "/ Volumes / Elements /" # is the path to the photo archive. This folder contains ORIG
- export FILENAME = " ` pwd` / $ 1 " # Add the full path to the file name.
- export OUT = ` exiftool " $ FILENAME " | grep "Create Date | head -n 1« ` ; # get the date the photos were created from EXIF
- echo $ OUT | grep "Create Date" ;
- # further we create from the date a path of the form ORIG / 2013/05/01 / - where ultimately we place the file
- export FOLDER = ` echo $ OUT | perl -i -npe "s /^(.*?): (\ d +) \: (\ d +) \: (\ d +) (. *?) $ / ORIG \ / \ 2 \ / \ 3 \ / \ 4 \ // g “ `
- # if there is no such way, create it
- echo mkdir -p " $ PREFIX $ FOLDER "
- mkdir -p " $ PREFIX $ FOLDER "
- echo -n $ FILENAME
- # since the path can be relative in the parameter, we pull out only the file name
- export NEWFILENAME = ` echo $ FILENAME | perl -i -npe "s / ^ (. *?) \ / ([^ \ /] +?) \. JPG $ / \ 2.JPG / g" ; `
- # check if there is already a file in the ORIG / 2013/05/01 / path
- if [ -f " $ PREFIX $ FOLDER $ NEWFILENAME " ]
- then
- # eat, then delete
- echo "exist ... $ PREFIX $ FOLDER $ NEWFILENAME "
- # here if necessary, we can enable removal from the IMPORT folder
- # but this business is dangerous, because the target file can be broken, zero size, etc. Then you can lose the photo. You can transfer the file somewhere, but I did not bother with it
- #rm $ FILENAME
- else
- # if there is no file, then move the file from the IMPORT folder to the ORIG / YYYY / MM / DD / folder
- echo mv \ " $ FILENAME \" \ " $ PREFIX $ FOLDER \"
- mv " $ FILENAME " " $ PREFIX $ FOLDER "
- fi
# find . -name «*.JPG» | perl -i -npe "s/^(.*?)[\n\r]+$/\.\/add_file_to_media_library.sh \"\1\"\n/g" ./add_file_to_media_library.sh «.//IMG_5790.JPG» ./add_file_to_media_library.sh «.//IMG_5802.JPG» ./add_file_to_media_library.sh «.//IMG_5794.JPG»
#!/bin/bash find . -name «*.JPG» | perl -i -npe "s/^(.*?)[\n\r]+$/\.\/add_file_to_media_library.sh \"\1\"\n/g" > /tmp/run.sh bash /tmp/run.sh rm /tmp/run.sh
- #! / bin / bash
- # add to the file passed in the parameter path to the current directory
- export FILENAME = " ` pwd` / $ 1 ″
- # folder where PREVIEW directory is created. In my case, this is an external drive, you can use a local
- export PREFIX = "/ Volumes / Elements /"
- # since all the files in ORIG are already laid out on the shelves, we will believe the date from the hierarchy and once again not to contact exiftool
- export FOLDER = ` echo $ 1 | perl -i -npe "s / ^ (. *?) \ / (\ d \ d \ d \ d) \ / (\ d \ d) \ / (\ d \ d) \ / (. *?) $ / PREVIEW \ / \ 2 \ / \ 3 \ / \ 4 \ // g “ ` ;
- mkdir -p " $ PREFIX $ FOLDER "
- # pulling the file name out of the path
- export NEWFILENAME = ` echo $ FILENAME | perl -i -npe "s / ^ (. *?) \ / ([^ \ /] +?) \. JPG $ / \ 2.JPG / g" ; `
- echo $ {PREFIX} $ {FOLDER} $ {NEWFILENAME}
- # was a thumbnail created before?
- if [ -f " $ {PREFIX} $ {FOLDER} $ {NEWFILENAME} " ]
- then
- # yes, it was created. Nothing to do
- echo "... skipped (exist) $ {PREFIX} $ {FOLDER} $ {NEWFILENAME} " ;
- else
- # no, it was not created. Need to convert
- echo "... convert" ;
- convert " $ infile " -auto-orient -resize 1024 -quality 85 " $ {PREFIX} $ {FOLDER} $ {NEWFILENAME} "
- fi
Source: https://habr.com/ru/post/188094/
All Articles