Advertisement
Guest User

Set EXIF dates based on filename on selected pictures

a guest
Sep 19th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.31 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function readdates {
  4.     output=$( exiftool "-TAG" "-createdate" "-modifydate" "-metadatadate" "-datetime" "-datetimeoriginal" "-dateutc" "-modificationdate" "-datecreated" "-datetimecreated" "$i" )
  5. }
  6.  
  7.  
  8. echo "$# arguments"
  9. if [ "$#" -lt 1 ]
  10. then
  11.     echo "Not enough arguments."
  12.     exit 1
  13. fi
  14.  
  15. arguments=( "$@" )
  16.  
  17. for i in "${arguments[@]}"
  18. do
  19.     echo "$i"
  20.     readdates
  21.     echo "Current EXIF date info: "
  22.     echo -e "$output"
  23.     if [ -z "$output" ]
  24.     then
  25.         # output is empty - success - leave the loop:
  26.         echo "The pictures currently do not have any dates."
  27.         # Desem la data
  28.         echo "Saving date..."
  29.         exiftool "-alldates<"filename "-overwrite_original" "$i"
  30.         echo "...done."
  31.         readdates
  32.         echo "New EXIF date info: "
  33.         echo -e "$output"
  34.     else
  35.         # output is non-empty - continue:
  36.         echo "The picture already has date information."
  37.         read -p "Do you want to remove it and set it again? [y/n] " -n 1 -r
  38.         echo
  39.         if [[ $REPLY =~ ^[Yy]$ ]]
  40.         then
  41.             echo  "Ok. Let's update the date..."
  42.             exiftool "-alldates=" "-overwrite_original" "$i" # remove dates
  43.             exiftool "-alldates<"filename "-overwrite_original" "$i"
  44.             echo "...done."
  45.             readdates
  46.             echo "New EXIF date info: "
  47.             echo -e "$output"
  48.         else
  49.             echo "Ok. Nothing was changed."
  50.         fi
  51.     fi
  52.     echo ""
  53. done
  54. sleep 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement