-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer_images.sh
executable file
·112 lines (98 loc) · 2.88 KB
/
renderer_images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
##############################################################################
#
# Gettting, displaying images in a tmux panel
# (c) Steven Saus 2024
# Licensed under the MIT license
#
##############################################################################
CacheDir=${XDG_CACHE_HOME:-$HOME/.local/state}
if [ -z "${XDG_CACHE_HOME}" ];then
export XDG_CACHE_HOME="${HOME}/.config"
fi
CacheFile=${CacheDir}/newsboat_img_links
if [ ! -f "${CacheFile}" ];then
touch "${CacheFile}"
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
# 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
gvalue="$cols"
lvalue="$lines"
else
gvalue="$lines"
lvalue="$cols"
fi
bvalue=$(echo "scale=4; $gvalue-3" | bc)
if [ "$bvalue" -gt 78 ];then
bvalue=78
fi
if [ -f $(which timg) ];then
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
}
main () {
if [ "$MODTIME" != $(date -r "${CacheFile}" +%s) ];then
MODTIME=$(date -r "${CacheFile}" +%s)
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 --loops=1 -pq ${TMPDIR}/* 2>/dev/null
rm ${TMPDIR}/* 2>/dev/null
fi
rich -u
fi
}
while true; do
main
sleep 2
done
rm ${TMPDIR}