1st commit

This commit is contained in:
2025-01-30 09:41:48 +01:00
commit 7d023b94fe
4 changed files with 413 additions and 0 deletions

121
flickr.sh Executable file
View File

@@ -0,0 +1,121 @@
#!/usr/bin/env bash
#NO_COLOR=1
# Check if NO_COLOR is set to disable colorization
if [ -z "$NO_COLOR" ]; then
: "${COLOR_GREEN:=$'\e[32m'}"
: "${COLOR_GREEN_BOLD:=$'\e[1;32m'}"
: "${COLOR_RED:=$'\e[31m'}"
: "${COLOR_RED_BOLD:=$'\e[1;31m'}"
: "${COLOR_YELLOW=$'\e[33m'}"
: "${COLOR_YELLOW_BOLD:=$'\e[1;33m'}"
: "${COLOR_SILVER=$'\e[37m'}"
: "${COLOR_LIGHT_GREY=$'\e[249m'}"
: "${COLOR_BRIGHT_PURPLE=$'\e[35;1m'}"
: "${BOLD:=$'\e[1m'}"
: "${ITALIC:=$'\e[3m'}"
: "${COLOR_RESET:=$'\e[00m'}"
else
: "${BOLD:=$'\e[1m'}"
: "${COLOR_RESET:=$'\e[00m'}"
: "${ITALIC:=$'\e[3m'}"
fi
#api_key=
#user_id=
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
dotenv () {
set -a
# shellcheck disable=SC1091
[ -f "$ScriptWorkDir/.env" ] && . "$ScriptWorkDir/.env" || { echo -e "${red}\nNo .env file found ! No API key for Flickr.'.${reset}"; exit 1; }
set +a
}
dotenv
source "$ScriptWorkDir/functions.sh"
perpage=500
pages=
username=
userid=
path_alias=
firstdatetaken=
photosurl=
profileurl=
###################################################
# #
# Get info about the given user. #
# #
###################################################
params_info=("$api_key" "$user_id")
getinfo_people "${params_info[@]}"
echo -e "\n${COLOR_GREEN}Get info about user ($user_id).${COLOR_RESET}"
printf "%15s %50s\n" "Name:" "$username"
printf "%15s %50s\n" "Alias:" "$path_alias"
printf "%15s %50s\n" "UserID:" "$userid"
printf "%15s %50s\n" "Joined:" "$firstdatetaken"
printf "%15s %50s\n" "Gallery:" "$photosurl"
printf "%15s %50s\n" "Profile:" "$profileurl"
###################################################
# #
# Get a list of public photos for the given user. #
# #
###################################################
#photos=$(curl "https://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=$api_key&user_id=$user_id&per_page=500&page=2&format=json&nojsoncallback=1")
echo -e "\n${COLOR_GREEN}Get a list of public photos for the given user ($user_id).${COLOR_RESET}"
echo -e "One request per page..."
#for page in {1..2}
for (( page=1; page <=$pages; page++ ))
do
#echo "Page $page"
curl -s "https://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=$api_key&user_id=$user_id&per_page=500&page=$page&format=json&nojsoncallback=1" | jq '.photos | .photo' > "page${page}.json"
done
echo -e "Concatenate all pages in liste.json"
allpages=$(ls page*.json | tr '\n' ' ')
#jq -s 'add' page1.json page2.json > liste.json
jq -s 'add' ${allpages} > liste.json
echo -e "Display all images list..."
photos=$(cat liste.json)
ID=()
counter=1
while read -r id && read -r title; do
echo -e "${BOLD}Photo ID: ${id}\t Title: ${title}${COLOR_RESET}"
params_info=("$api_key" "$id")
getinfo_photos "${params_info[@]}"
ID+=(${id})
((++counter))
done < <(jq -r -c '.[] | .id, .title' <<< "$photos")
echo -e "${COLOR_GREEN}Found $counter public photos for user ($user_id) on Flickr.${COLOR_RESET}"
#echo ${ID[@]}

80
functions.sh Executable file
View File

@@ -0,0 +1,80 @@
#!/usr/bin/env bash
###################################################
# #
# Get info for the given user. #
# flickr.people.getInfo #
# #
###################################################
getinfo_people() {
params=("$@")
#info_user=$(curl "https://www.flickr.com/services/rest/?method=flickr.people.getInfo&api_key=$api_key&user_id=$user_id&format=json&nojsoncallback=1")
info_user=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.people.getInfo&api_key=$1&user_id=$2&format=json&nojsoncallback=1")
userid=$(echo "$info_user" | jq -r '.person | .id')
username=$(echo "$info_user" | jq -r '.person | .username ._content')
ispro=$(echo "$info_user" | jq -r '.person | .ispro')
path_alias=$(echo "$info_user" | jq -r '.person | .path_alias')
count=$(echo "$info_user" | jq -r '.person .photos | .count ._content')
pages=$(((count / perpage) + 1))
firstdatetaken=$(echo "$info_user" | jq -r '.person .photos | .firstdatetaken ._content')
photosurl=$(echo "$info_user" | jq -r '.person | .photosurl ._content')
profileurl=$(echo "$info_user" | jq -r '.person | .profileurl ._content')
: <<'END_COMMENT2'
echo $userid
echo $username
echo $ispro
echo $path_alias
echo $count
echo $pages
echo $firstdatetaken
echo $photosurl
echo $profileurl
END_COMMENT2
}
###################################################
# #
# Get info for the given photo. #
# flickr.photos.getInfo #
# #
###################################################
getinfo_photos() {
params=("$@")
#info_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=$api_key&photo_id=$photo_id&format=json&nojsoncallback=1")
info_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=$1&photo_id=$2&format=json&nojsoncallback=1")
id=$(echo "$info_photo" | jq -r '.photo .id')
title=$(echo "$info_photo" | jq -r '.photo .title | ._content')
description=$(echo "$info_photo" | jq -r '.photo .description | ._content') ##
p=$(echo "$info_photo" | jq -r '.photo .dates | .posted')
posted=$(LC_ALL=fr_FR.UTF-8 date -d @$p +"%d/%m/%Y %H:%M:%S" 2>/dev/null || LC_ALL=fr_FR.UTF-8 date -r $p +"%d/%m/%Y %H:%M:%S")
t=$(echo "$info_photo" | jq -r '.photo .dates | .taken')
taken=$(LC_ALL=fr_FR.UTF-8 date -d "$t" +"%d/%m/%Y %H:%M:%S" 2>/dev/null || LC_ALL=fr_FR.UTF-8 date -d "$t" +"%d/%m/%Y %H:%M:%S")
view=$(echo "$info_photo" | jq -r '.photo .views')
comments=$(echo "$info_photo" | jq -r '.photo .comments | ._content')
tags=$(echo "$info_photo" | jq -r '.photo .tags | .tag[].raw' | tr '\n' ',')
urls=$(echo "$info_photo" | jq -r '.photo .urls | .url[] | ._content')
#echo "Photo ID: $id - Title: $title"
echo "Description: $description"
echo "Posted: $posted - Taken: $taken"
echo "View: $view - Comments: $comments"
echo "Tags: $tags"
echo
}

152
info_photo.sh Executable file
View File

@@ -0,0 +1,152 @@
#!/usr/bin/env bash
#api_key=
#user_id=
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
dotenv () {
set -a
# shellcheck disable=SC1091
[ -f "$ScriptWorkDir/.env" ] && . "$ScriptWorkDir/.env" || { echo -e "${red}\nNo .env file found ! No API key for Flickr.'.${reset}"; exit 1; }
set +a
}
dotenv
#photo_id=15306150004
#photo_id=54269348549
photo_id=53640846257
perpage=500
url_flickr="https://www.flickr.com/"
: <<'END_COMMENT'
END_COMMENT
###################################################
# #
# Get info for the given photo. #
# flickr.photos.getInfo #
# #
###################################################
getinfo_photos() {
params=("$@")
#info_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=$api_key&photo_id=$photo_id&format=json&nojsoncallback=1")
info_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=$1&photo_id=$2&format=json&nojsoncallback=1")
id=$(echo "$info_photo" | jq -r '.photo .id')
title=$(echo "$info_photo" | jq -r '.photo .title | ._content')
description=$(echo "$info_photo" | jq -r '.photo .description | ._content') ##
p=$(echo "$info_photo" | jq -r '.photo .dates | .posted')
posted=$(LC_ALL=fr_FR.UTF-8 date -d @$p +"%d/%m/%Y %H:%M:%S" 2>/dev/null || LC_ALL=fr_FR.UTF-8 date -r $p +"%d/%m/%Y %H:%M:%S")
t=$(echo "$info_photo" | jq -r '.photo .dates | .taken')
taken=$(LC_ALL=fr_FR.UTF-8 date -d "$t" +"%d/%m/%Y %H:%M:%S" 2>/dev/null || LC_ALL=fr_FR.UTF-8 date -d "$t" +"%d/%m/%Y %H:%M:%S")
view=$(echo "$info_photo" | jq -r '.photo .views')
comments=$(echo "$info_photo" | jq -r '.photo .comments | ._content')
tags=$(echo "$info_photo" | jq -r '.photo .tags | .tag[].raw' | tr '\n' ',')
urls=$(echo "$info_photo" | jq -r '.photo .urls | .url[] | ._content')
echo "Photo ID: $id"
echo "Title: $title - Description: $description"
echo "Posted: $posted - Taken: $taken"
echo "View: $view - Comments: $comments"
echo "Tags: $tags"
echo
}
params_info=("$api_key" "$photo_id")
getinfo_photos "${params_info[@]}"
echo "--------------------------------------------"
###################################################
# #
# Get exif for the given photo. #
# flickr.photos.getExif #
# #
###################################################
getexif_photos() {
params=("$@")
#exif_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getExif&api_key=$api_key&photo_id=$photo_id&format=json&nojsoncallback=1")
exif_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getExif&api_key=$1&photo_id=$2&format=json&nojsoncallback=1")
#id=$(echo "$exif_photo" | jq -r '.photo .id')
#camera=$(echo "$exif_photo" | jq -r '.photo .camera')
exifs=$(echo "$exif_photo" | jq -r '.photo .exif')
model=$(echo "$exifs" | jq -r '.[] | select(.label == "Model") | (.raw ._content)')
software=$(echo "$exifs" | jq -r '.[] | select(.label == "Software") | (.raw ._content)')
date_orig=$(echo "$exifs" | jq -r '.[] | select(.label == "Date and Time (Original)") | (.raw ._content)')
aperture=$(echo "$exifs" | jq -r '.[] | select(.label == "Aperture") | (.raw ._content)')
exposure=$(echo "$exifs" | jq -r '.[] | select(.label == "Exposure") | (.raw ._content)')
iso=$(echo "$exifs" | jq -r '.[] | select(.label == "ISO Speed") | (.raw ._content)')
bias=$(echo "$exifs" | jq -r '.[] | select(.label == "Exposure Bias") | (.raw ._content)')
ep=$(echo "$exifs" | jq -r '.[] | select(.label == "Exposure Program") | (.raw ._content)')
wb=$(echo "$exifs" | jq -r '.[] | select(.label == "White Balance") | (.raw ._content)')
#lens_info=$(echo "$exifs" | jq -r '.[] | select(.label == "Lens Info") | (.raw ._content)')
#lens_model=$(echo "$exifs" | jq -r '.[] | select(.label == "Lens Model") | (.raw ._content)')
lens=$(echo "$exifs" | jq -r '.[] | select(.label == "Lens") | (.raw ._content)')
echo "Model: $model - Software: $software - Date: $date_orig"
echo "Aperture: $aperture - Exposure: $exposure - ISO: $iso"
echo "Exposure Bias: $bias - Exposure Program: $ep - White Balance: $wb"
echo "Lens: $lens"
echo
}
params_exifs=("$api_key" "$photo_id")
getexif_photos "${params_exifs[@]}"
echo "--------------------------------------------"
###################################################
# #
# Get contexts for the given photo. #
# flickr.photos.getAllContexts #
# #
###################################################
getAllContexts_photos() {
params=("$@")
#contexts_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getAllContexts&api_key=$api_key&photo_id=$photo_id&format=json&nojsoncallback=1")
contexts_photo=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.photos.getAllContexts&api_key=$1&photo_id=$2&format=json&nojsoncallback=1")
albums=$(echo "$contexts_photo" | jq -r '.set')
groups=$(echo "$contexts_photo" | jq -r '.pool')
title_album=$(echo "$albums" | jq -r '.[].title' | tr '\n' ' ')
id_album=$(echo "$albums" | jq -r '.[].id' | tr '\n' ' ')
title_group=$(echo "$groups" | jq -r '.[].title' | tr '\n' ' ')
id_group=$(echo "$groups" | jq -r '.[].id' | tr '\n' ' ')
url_group=$(echo "$groups" | jq -r '.[].url' | tr '\n' ' ')
echo "ID: $id_album"
echo "Albums: $title_album"
echo
echo "ID: $id_group"
echo "Groups: $title_group"
echo "URL: $url_flickr$url_group"
}
params_context=("$api_key" "$photo_id")
getAllContexts_photos "${params_context[@]}"

60
info_user.sh Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
#api_key=
#user_id=
### Variables for self updating
ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
dotenv () {
set -a
# shellcheck disable=SC1091
[ -f "$ScriptWorkDir/.env" ] && . "$ScriptWorkDir/.env" || { echo -e "${red}\nNo .env file found ! No API key for Flickr.'.${reset}"; exit 1; }
set +a
}
dotenv
perpage=500
###################################################
# #
# Get info for the given user. #
# flickr.people.getInfo #
# #
###################################################
getinfo_people() {
params=("$@")
#info_user=$(curl "https://www.flickr.com/services/rest/?method=flickr.people.getInfo&api_key=$api_key&user_id=$user_id&format=json&nojsoncallback=1")
info_user=$(curl -s "https://www.flickr.com/services/rest/?method=flickr.people.getInfo&api_key=$1&user_id=$2&format=json&nojsoncallback=1")
id=$(echo "$info_user" | jq -r '.person | .id')
username=$(echo "$info_user" | jq -r '.person | .username ._content')
ispro=$(echo "$info_user" | jq -r '.person | .ispro')
path_alias=$(echo "$info_user" | jq -r '.person | .path_alias')
count=$(echo "$info_user" | jq -r '.person .photos | .count ._content')
q=$(((count / perpage) + 1))
firstdatetaken=$(echo "$info_user" | jq -r '.person .photos | .firstdatetaken ._content')
photosurl=$(echo "$info_user" | jq -r '.person | .photosurl ._content')
profileurl=$(echo "$info_user" | jq -r '.person | .profileurl ._content')
echo $id
echo $username
echo $ispro
echo $path_alias
echo $count
echo $q
echo $firstdatetaken
echo $photosurl
echo $profileurl
}
params_info=("$api_key" "$user_id")
getinfo_people "${params_info[@]}"