1st commit

This commit is contained in:
2022-08-19 15:00:19 +02:00
commit 9239e28269
2 changed files with 259 additions and 0 deletions

20
keywords.csv Normal file
View File

@@ -0,0 +1,20 @@
FR;EN
renard;fox
renard roux;red fox
cerf;deer
cerf élaphe;red deer
chevreuil;roe deer
brocard;buck
chevrette;doe
sanglier;wild boer
laie;saw
faon;fawn
chat;cat
chat forestier;wildcat
lièvre;hare
lièvre d'europe;european hare
blaireau;badger
blaireau d'europe;european badger
martre;marten
martre des pins;pine marten
bouquetin;ibex
1 FR EN
2 renard fox
3 renard roux red fox
4 cerf deer
5 cerf élaphe red deer
6 chevreuil roe deer
7 brocard buck
8 chevrette doe
9 sanglier wild boer
10 laie saw
11 faon fawn
12 chat cat
13 chat forestier wildcat
14 lièvre hare
15 lièvre d'europe european hare
16 blaireau badger
17 blaireau d'europe european badger
18 martre marten
19 martre des pins pine marten
20 bouquetin ibex

239
keywords2insta.sh Executable file
View File

@@ -0,0 +1,239 @@
#!/usr/bin/env bash
italic="\033[3m"
#underline="\033[4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
bold="\033[1m"
bold_under="\033[1;4m"
reset="\033[0m"
file=$1
#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
# 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).
#echo "$exif"
# Keywords : Anemone pulsatilla, Anemone pulsatille, _bleu_
# keywords
k=$(echo "$exif" | sed -n '/^Keywords/p' | awk -F":" '{print $2}' | sed 's/^ *//g')
# _vert_, accouplement, brocard, capreolus capreolus, chevrette, chevreuil, rut
echo "$k"
# Anemone pulsatilla, Anemone pulsatille, _bleu_
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=$(echo ${dico["$ii"]})
else
k_en=""
fi
k_fr=$(echo "$ii")
echo "k_fr: $k_fr long: "${#k_fr}
echo "k_en: $k_en long: "${#k_en}
if [ -n "$k_en" ]; then
echo "fr & en"
[[ "$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
mod=("canonphotography")
m=$(echo "$exif" | sed -n '/^Model/p' | awk -F":" '{print $2}' | xargs)
mod+=("${m}") # Canon EOS R6
if [[ "$m" =~ ^Canon ]]; then
mod+=("Canon") # Canon
[[ "$m" =~ *EOS* ]] || mod+=("EOS") # EOS
#mod+=($(echo "$m" | sed 's/Canon\ //g' | sed 's/ //g')) # EOSR6
#mod+=($(echo "$m" | sed 's/EOS//g' | sed 's/ //g') ) # CanonR6
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') "
#fixes
# #wildlifephotography
wild=("wildlife" "wildlifephoto" "wildlifephotographer")
# #natureshots #naturelover #nature
nat=("naturelovers" "natureshot" "naturephotography")
# #jura franchecomte
reg=("Bourgogne" "Burgundy" "Bourgogne Franche-Comté" "Côte d'or" "cotedor")
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')" "
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
: <<'END_COMMENT'
echo "Keywords flickr: $keyword_flickr"
echo "Keywords insta: $keyword_insta"
echo
echo "Model flickr: $model_flickr"
echo "Model insta: $model_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=$(echo "$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)}')
: <<'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_insta=$(echo "$keywords_insta" | gawk -v RS="[ \n]" -v ORS=" " '!($0 in a){print;a[$0]}')
fi
# flick: éléphant "tic toc" demi-deuil ok
if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v xsel)" ]; then
xsel -b <<< "$keywords_insta"
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then
#pbcopy <<< "$insta"
#echo "$insta"
echo "Insta tag's OK !"
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"