#!/usr/bin/env bash red="\033[1;31m" bold="\033[1m" reset="\033[0m" file=$1 # Tags automatically added # You can add tags to this 4 arrays wild=("wildlife" "wildlifephoto" "wildlifephotographer") nat=("naturelovers" "natureshot" "naturephotography") reg=("Bourgogne" "Burgundy" "Bourgogne Franche-Comté" "Côte d'or") others=("tag" "keu") #trans fr:en -b "renard" #fox if ! command -v exiftool &> /dev/null; then echo -e "${bold}exiftool${reset} could not be found !\n" echo -e "You should install ${bold}exiftool${reset}:\n" echo -e " - brew install exiftool" echo -e "" exit 1 fi [ ! -f "$file" ] && echo -e "${bold}${red}No input file !${reset}" && exit 1 # dico français / anglais fr=() en=() array=() declare -A dico if [ -f ./keywords.csv ]; then while IFS=';' read -ra array; do fr+=("${array[0]}") en+=("${array[1]}") done < keywords.csv j=0 for i in "${fr[@]}" do x="${en[$j]}" dico+=( ["$i"]="$x" ) ((j=j+1)) done fi echo -e "\n${bold}Reading $file exif...${reset}" exif=$(exiftool -Canon -s -Keywords "$file") # The exiftool application exits with a status of 0 on success, or 1 if an # error occurred, or 2 if all files failed the -if condition (for any of # the commands if -execute was used). # keywords k=$(echo "$exif" | sed -n '/^Keywords/p' | awk -F":" '{print $2}' | sed 's/^ *//g') # _vert_, accouplement, brocard, capreolus capreolus, chevrette, chevreuil, rut if [ -z "$k" ]; then echo -e "${bold}${red}No Keywords found !${reset}" echo "Quit." exit 1 fi IFS="," read -a key <<< "$k" for i in "${key[@]}" do ii=$(echo "$i" | xargs) # trim $i if [[ ! "$ii" =~ ^_ ]]; then if [[ ${dico["$ii"]} ]] ; then k_en=${dico["$ii"]} else k_en="" fi k_fr="$ii" if [ -n "$k_en" ]; then [[ "$k_fr" = *" "* ]] && keyword_flickr+="\"${k_fr}\" " || keyword_flickr+="${k_fr} " [[ "$k_en" = *" "* ]] && keyword_flickr+="\"${k_en}\" " || keyword_flickr+="${k_en} " keyword_insta+="#${k_fr// /} #${k_en// /} " else [[ "$k_fr" = *" "* ]] && keyword_flickr+="\"${k_fr}\" " || keyword_flickr+="${k_fr} " keyword_insta+="#${k_fr// /} " fi fi done # model # Canon EOS R6 Canon EOS 5D Mark III Canon EOS-1D Mark IV Canon EOS 20D m=$(echo "$exif" | sed -n '/^Model/p' | awk -F":" '{print $2}' | xargs) mod=("${m}") # Canon EOS R6 if [[ "$m" =~ ^Canon ]]; then mod+=("Canon") mod+=("canonphotography") [[ "$m" = *EOS* ]] || mod+=("EOS") # EOS z=$(echo "$m" | sed 's/Canon\ //g' | xargs) y=$(echo "$m" | sed 's/EOS//g' | sed 's/[ ][ ]*/ /g' | xargs) mod+=("${z}") # EOS R6 mod+=("${y}") # Canon R6 fi for i in "${mod[@]}" do model+="${i} " if [[ "$i" = *" "* ]]; then model_flickr+="\"${i}\" " else model_flickr+="${i} " fi model_insta+="#${i// /} " # supprime tous les espaces et ajoute le # done #lens l=$(echo "$exif" | sed -n '/^Lens/p' | awk -F":" '{print $2}' | sed 's/\///g' | xargs) lens_flickr="\"${l}\" " lens_insta="$(echo "$l" | sed 's/ //g' | sed -r 's/[^ ]+/#&/g') " for i in "${wild[@]}" do if [[ "$i" = *" "* ]]; then wildlife_flickr+="\"${i}\" " else wildlife_flickr+="${i} " fi #wildlife_insta+="#"$(echo "${i}" | iconv -f UTF-8-MAC -t ascii//translit | sed 's/[^a-zA-Z 0-9]//g' | sed 's/ //g')" " wildlife_insta+="#$(echo "${i}" | iconv -f UTF-8-MAC -t ascii//translit | sed 's/[^a-zA-Z 0-9]//g' | sed 's/ //g') " done for i in "${nat[@]}" do if [[ "$i" = *" "* ]]; then nature_flickr+="\"${i}\" " else nature_flickr+="${i} " fi nature_insta+="#$(echo "${i}" | iconv -f UTF-8-MAC -t ascii//translit | sed 's/[^a-zA-Z 0-9]//g' | sed 's/ //g') " done for i in "${reg[@]}" do if [[ "$i" = *" "* ]]; then region_flickr+="\"${i}\" " else region_flickr+="${i} " fi region_insta+="#$(echo "${i}" | iconv -f UTF-8-MAC -t ascii//translit | sed 's/[^a-zA-Z 0-9]//g' | sed 's/ //g') " done echo "Model flickr: $model_flickr" echo "Model insta: $model_insta" echo : <<'END_COMMENT' echo "Keywords flickr: $keyword_flickr" echo "Keywords insta: $keyword_insta" echo echo "Lens flick: $lens_flickr" echo "Lens_insta: $lens_insta" echo echo "Wildlife flickr: $wildlife_flickr" echo "Wildlife insta: $wildlife_insta" echo echo "Nature flickr: $nature_flickr" echo "Nature insta: $nature_insta" echo echo "Region flickr: $region_flickr" echo "Region insta: $region_insta" echo END_COMMENT keywords_flickr="$keyword_flickr$model_flickr$lens_flickr$wildlife_flickr$nature_flickr$region_flickr" keywords_insta=$(echo "$keyword_insta$model_insta$lens_insta$wildlife_insta$nature_insta$region_insta" | awk '{print tolower($0)}') if [ ${#others[@]} -gt 0 ]; then for i in "${others[@]}" do if [[ "$i" = *" "* ]]; then others_flickr+="\"${i}\" " else others_flickr+="${i} " fi others_insta+="#$(echo "${i}" | iconv -f UTF-8-MAC -t ascii//translit | sed 's/[^a-zA-Z 0-9]//g' | sed 's/ //g') " done keywords_flickr+="$others_flickr" keywords_insta+="$others_insta" fi : <<'END_COMMENT' echo "$keywords_flickr" echo echo "$keywords_insta" echo END_COMMENT # suppress accent (bug in macos) => add sed => suppress punctuation too # https://stackoverflow.com/questions/806199/how-to-fix-weird-issue-with-iconv-on-mac-os-x if ! command -v iconv &> /dev/null; then echo -e "\n${bold}iconv${reset} could not be found !\n" echo -e "It's required for suppress accents." echo -e "You should install ${bold}icon${reset}:" echo -e " - brew install iconv" echo -e "" else keywords_insta=$(echo "$keywords_insta" | iconv -f UTF-8-MAC -t ascii//translit | sed 's/[^a-zA-Z 0-9 \#]//g') fi # suppress duplicates (gawk) if ! command -v gawk &> /dev/null; then echo -e "\n${bold}gawk${reset} could not be found !\n" echo -e "It's required for suppress duplicates." echo -e "You should install ${bold}gawk${reset}:" echo -e " - brew install gawk" echo -e "" else #keywords_flickr=$(echo "$keywords_flickr" | gawk -v RS="[ \n]" -v ORS=" " '!($0 in a){print;a[$0]}') keywords_insta=$(echo "$keywords_insta" | gawk -v RS="[ \n]" -v ORS=" " '!($0 in a){print;a[$0]}') fi if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v xsel)" ]; then xsel -b <<< "$keywords_insta" elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then pbcopy <<< "$keywords_insta" fi echo -e "\n${bold}The Instagram's tags are available in your clipboard !${reset}" echo "$keywords_insta" echo -e "\n${bold}Here the Flickr's tags too !${reset}" echo "$keywords_flickr"