Skip to content

Commit

Permalink
Rendering images works with my helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
uriel1998 committed Oct 25, 2024
1 parent 7e0a5a4 commit e43d5b5
Showing 1 changed file with 53 additions and 6 deletions.
59 changes: 53 additions & 6 deletions renderer_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,40 @@ if [ ! -f "${CacheFile}" ];then
fi
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
DEFAULT_COVER="${SCRIPT_DIR}/defaultimage.jpg"

ANTITRACKING=0
MODTIME=0
TMPDIR=$(mktemp)

# Anti-tracking, using a hosts list if present
# place the hosts list in the script directory (NOT where you symlinked it to!)
# https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
# Not needed if you use a pi-hole or the rest, though it saves some time.
hosts_file="${SCRIPT_DIR}/hosts"
if [ -f "${hosts_file}" ];then
ANTITRACKING=1
fi


function show_album_art {
# we might want to use
-i ${CacheFile} to download them all first?

# Function to check if a domain is in the hosts list
check_domain_in_hosts() {
local url=$1
# Extract the domain from the URL
local domain=$(echo "$url" | awk -F[/:] '{print $4}')

# Check if the domain is present in the hosts file
if grep -qw "$domain" "$hosts_file"; then
return 0
else
wget -q -e robots=off -P /${TMPDIR} "$1" 2>/dev/null
# show_image "$1"
fi
}


function show_image {
cols=$(tput cols)
lines=$(tput lines)
if [ "$cols" -gt "$lines" ]; then
Expand All @@ -37,11 +66,17 @@ function show_album_art {
bvalue=78
fi
if [ -f $(which timg) ];then
timg -pq "${1}"
timg -pq --frames=1 "${1}"
if [ $? -eq 0 ];then
rich -u
fi
else
if [ -f $(which jp2a) ];then
# if it looks bad, try removing invert
jp2a --colors --width=${cols} --invert "${1}"
if [ $? -eq 0 ];then
rich -u
fi
fi
fi

Expand All @@ -51,10 +86,21 @@ function show_album_art {
main () {
if [ "$MODTIME" != $(date -r "${CacheFile}" +%s) ];then
MODTIME=$(date -r "${CacheFile}" +%s)
cat "${CacheFile}" | grep -e "^http" | grep -v -e "\/track" -e "sendgrid\." -e "cloudfront\." -e "icon" -e "ICON" | while IFS= read -r line; do
echo "${line}"
show_album_art "${line}"
clear
echo "Checking and grabbing images"
cat "${CacheFile}" | grep -e "^http" | grep -v -e "\/track" -e "sendgrid\." -e "icon" -e "ICON" | while IFS= read -r line; do
if [ $ANTITRACKING == 1 ];then
check_domain_in_hosts "${line}"
else
echo "${line}"
show_image "${line}"
fi
done
if [ $ANTITRACKING == 1 ];then
timg -pq ${TMPDIR}/* 2>/dev/null
rm ${TMPDIR}/* 2>/dev/null
fi
rich -u
fi
}

Expand All @@ -63,3 +109,4 @@ while true; do
main
sleep 2
done
rm ${TMPDIR}

0 comments on commit e43d5b5

Please sign in to comment.