-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolder-thumbnailer
executable file
·89 lines (75 loc) · 2.28 KB
/
folder-thumbnailer
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
#!/bin/bash
basename() {
# Usage: basename "path" ["suffix"]
dir=${1%${1##*[!/]}}
dir=${dir##*/}
dir=${dir%"$2"}
printf '%s\n' "${dir:-/}"
}
[[ $# -lt 4 ]] && exit 1
for subdirectory in "normal" "large"; do
rm -f "$HOME/.cache/thumbnails/$subdirectory/$(echo -n "$4" | md5sum | cut -d " " -f1).png"
done
# only if folder is not a symlink
if [ ! -h "$2" ] ; then
if [ -f "$2/.folder.svg" ]; then
inkscape --export-type=png --export-dpi=500 "$2/.folder.svg" --export-filename="$3" 1>/dev/null 2>&1
convert -thumbnail "$1" "$3" "$3" 1>/dev/null 2>&1
exit 0
fi
[ -f "$2/c001_001.jpg" ] && cp "$2/c001_001.jpg" "$2/.folder.jpg" 1>/dev/null 2>&1
for name in "folder" "cover"; do
for extension in png jpg jpeg webp; do
if [ -f "$2/${name}.${extension}" ]; then
mv -f "$2/${name}.${extension}" "$2/.${name}.${extension}" 1>/dev/null 2>&1
fi
done
done
for name in ".folder" ".cover"; do
for extension in png jpg jpeg webp; do
if [ -f "$2/${name}.${extension}" ]; then
convert -thumbnail "$1" "$2/${name}.${extension}" "$3" 1>/dev/null 2>&1
exit 0
fi
done
done
fi
case "$2" in
*"/Sites/Documents")
cp "$HOME/.config/thumbnails/Cloud_Documents.png" "$3" 1>/dev/null 2>&1
exit 0
;;
*"/Sites/Audio")
cp "$HOME/.config/thumbnails/Cloud_Audio.png" "$3" 1>/dev/null 2>&1
exit 0
;;
*"/Sites/Pictures")
cp "$HOME/.config/thumbnails/Cloud_Pictures.png" "$3" 1>/dev/null 2>&1
exit 0
;;
*"/Sites/Videos")
cp "$HOME/.config/thumbnails/Cloud_Videos.png" "$3" 1>/dev/null 2>&1
exit 0
;;
*"/Anime/"*"(Not yet aired)"*|*"/Audio Book/"*"(Not yet aired)"*)
cp "$HOME/.config/thumbnails/Waiting for.png" "$3" 1>/dev/null 2>&1
exit 0
;;
"/home/"*)
if [ -f "$HOME/.config/thumbnails/$(basename "$2").png" ]; then
cp "$HOME/.config/thumbnails/$(basename "$2").png" "$3" 1>/dev/null 2>&1
exit 0
else
for extension in png jpg jpeg; do
imgs="$(shopt -s nullglob;shopt -s dotglob;echo "$2"/*.${extension})"
if [ ${#imgs[@]} == 1 ]; then
convert -thumbnail "$1" "$2/"*.${extension} "$3" 1>/dev/null 2>&1
exit 0
fi
done
fi
;;
esac
gdbus call --session --dest=org.freedesktop.thumbnails.Cache1 --object-path /org/freedesktop/thumbnails/Cache1 \
--method org.freedesktop.thumbnails.Cache1.Delete "['$4']" >/dev/null
exit 0