-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallset
executable file
·279 lines (246 loc) · 9.79 KB
/
wallset
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env bash
# vim: noai:ts=4:sw=4:expandtab
#
# wallset: This program customizes images and videos for wallpaper
# website: http://terminalroot.com.br/
# author: Marcos Oliveira
# dependencies: feh, ffmpeg, imagemagick(convert), xrandr, sed, bash, xdg-utils
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
shopt -s extglob
if [[ $(echo $LANG | cut -c 1-2) == 'pt' ]]; then
_lang=("uso" "opções" "Altera o Wallpaper para o número informado. Use imagens com 3 dígitos, exemplo: 014,003,099" "Adiciona imagens" "Use antes do parâmetro -a,--add quando quiser adicionar já alterar" "Finaliza o loop" "Cria um loop de imagem com o tempo informado em segundos" "Abre a última imagem adicionada" "Informa quantas imagens há" "Mostra a atual imagem" "Adiciona um vídeo como Wallpaper" "Lista os vídeos que já foram utilizados" "Utiliza o vídeo pelo número listado em --list-videos" "Remove a última imagem adicionada" "Exibe essa ajuda" "Exibe a versão desse programa" "Exemplos" "Adiciona uma imagem" "Adiciona e já define como Wallpaper" "Altera para imagem com esse número" "Adiciona o vídeo" "Usa o vídeo já utilizado e listado" "Significa que precisa usar um número" "Somente vídeos nos formato .mp4" "Somente será exibido 10 segundos iniciais do vídeo" "Use imagens com 3 dígitos, exemplo: 011" "Não há nenhuma imagem." "Preparando o vídeo" "Use números indicados por" "Use números de 1 até" "Tempo inválido" "Tipo inválido" "Use números de 001 até" "Formato inválido." "Somente formato MP4" "Número inválido. Use" "Informe o vídeo" "Não há imagens." "Não há vídeos.")
else
_lang=("usage" "options" "Change the Wallpaper to the number entered. Use images with 3 digits, example: 014,003,099" "Add images" "Use before the -a, --add parameter when you want to add already change" "Ends the loop" "Creates an image loop with the time reported in seconds" "Opens the last image added" "Informs how many images there are" "Shows the current image" "Add a video as Wallpaper" "Lists the videos that have already been used" "Use the video by the number listed in --list-videos" "Remove the last image added" "Display this help" "Display the version of this program" "Examples" "Add an image" "Add and set it as Wallpaper" "Change to image with this number" "Add the video" "Use the video already used and listed" "Means that you need to use a number" "Only videos in .mp4 format" "Only the first 10 seconds of the video will be displayed" "Use 3-digit images, example: 011" "There is no image." "Preparing the video..." "Use numbers indicated by" "Use numbers numbers from 1 to" "Invalid time" "Invalid type" "Use numbers from 001 to" "Invalid format." "MP4 format only" "Invalid number. Use" "Report Video" "No images." "No videos.")
fi
_usage(){
cat <<EOF
${_lang[0]}: ${0##*/} [${_lang[1]}]
Options:
-u,--use [N] ${_lang[2]}
-a,--add img.jpg ... ${_lang[3]}
-S,--set ${_lang[4]}
-q,--quit ${_lang[5]}
-t,--time [N] ${_lang[6]}
-d,--display ${_lang[7]}
-c,--count ${_lang[8]}
-s,--show ${_lang[9]}
-V,--video [video] ${_lang[10]}
-L,--list-videos ${_lang[11]}
-I,--set-video [N] ${_lang[12]}
-r,--remove ${_lang[13]}
-h,--help ${_lang[14]}
-v,--version ${_lang[15]}
${_lang[16]}:
${_lang[17]} → '${0##*/} -a img.jpg'
${_lang[18]} → '${0##*/} --set --add img.jpg'
${_lang[19]} → '${0##*/} -u 001'
${_lang[20]} → '${0##*/} -V video.mp4'
${_lang[21]} → '${0##*/} -I 3'
* [N] ${_lang[22]}
** ${_lang[23]}
*** ${_lang[24]}
**** ${_lang[25]}
EOF
exit
}
_dir_img="${XDG_CONFIG_HOME}/.wallpapers"
_dir_vid="${_dir_img}/video"
pid="$$"
[[ ! -d "${_dir_img}" ]] && mkdir -p "${_dir_img}"
[[ ! -d "${_dir_vid}" ]] && mkdir -p "${_dir_vid}"
ctrl_c(){
exit 127
}
_get_resolution_screen(){
xrandr | grep '*' | awk '{print $1}' | cut -dx -f1
}
_last_wall(){
ls ${_dir_img}/*.jpg 2>/dev/null >/dev/null
if [[ "$?" != "0" ]]; then
printf "%s" "0"
else
_n=$(ls -1 ${_dir_img}/*.jpg | tail -n 1 | tr -d 'a-z\.\-\/')
printf "%s" "${_n}"
fi
}
_new_number(){
_n=$(echo $(_last_wall) + 1 | bc)
[[ $(expr length ${_n}) == 1 ]] && _n="00${_n}" || _n="0${_n}"
printf "%s" "${_n}"
}
_resize_img(){
_n=$(_new_number)
_w=$(_get_resolution_screen)
convert -resize "3840" "${1}" "${_dir_img}/wallpaper-${_n}.jpg"
if [[ "${add}" == 1 ]]; then
feh --no-fehbg --bg-fill "${_dir_img}/wallpaper-${_n}.jpg"
[[ $(which gsettings >&- 2>&-) ]] && \
gsettings set org.gnome.desktop.background picture-uri file:///"${_dir_img}/wallpaper-${_n}.jpg"
fi
}
_count(){
ls ${_dir_img}/*.jpg 2>/dev/null | wc -l
}
_current(){
xdg-open "${_dir_img}/wallpaper-$(_last_wall).jpg"
}
_loop(){
if [[ $(_count) < 1 ]]; then
printf "%s\n" "${_lang[26]}"
exit 1
fi
i=1;
while : ; do
[[ "${i}" -ge "$(_count)" ]] && i=1
if [[ $(expr length $i) == 1 ]]; then
feh --no-fehbg --bg-fill "${_dir_img}/wallpaper-00${i}.jpg"
else
feh --no-fehbg --bg-fill "${_dir_img}/wallpaper-0${i}.jpg"
fi
sleep $1
let i=i+1
done &
}
_quit_loop(){
#kill -9 $$
killall -q bash 2>/dev/null >/dev/null
}
_set_img(){
ls "${_dir_img}/wallpaper-${1}.jpg" >/dev/null 2>/dev/null
if [[ "$?" == 0 ]]; then
feh --no-fehbg --bg-fill "${_dir_img}/wallpaper-$1.jpg"
if [[ $(which gsettings >&- 2>&-) && "$XDG_CURRENT_DESKTOP" == "GNOME" ]]; then
gsettings set org.gnome.desktop.background picture-uri file:///"${_dir_img}/wallpaper-$1.jpg"
fi
else
_t=$(_count)
[[ "${_t}" -lt 100 ]] && _t="0${_t}"
echo "$1 - ${_lang[35]}: "$(ls ${_dir_img} | sed 's/wallpaper-//;s/\.jpg/ /g')
fi
}
_show(){
egrep -o '[0-9]{3}' "${HOME}/.fehbg"
}
_video(){
a=1
for i in $(ls -d $_dir_vid/*/ 2>/dev/null); do
if [[ -d "$_dir_vid/$a" ]]; then
let a=a+1
fi
done
mkdir -p "$_dir_vid/$a"
echo -e "${_lang[27]}...\r"
ffmpeg -y -ss 00:00 -i ${1} -t 10 "${_dir_vid}/${a}/filename%05d.jpg" > ${_dir_vid}/${a}/video.info 2>&1
t=$(ls ${_dir_vid}/${a}/* | wc -l)
let t=t-1
echo ${1} > ${_dir_vid}/${a}/video.info
i=1
# ctrl_c
while : ; do
feh --no-fehbg --bg-fill $(ls -1 ${_dir_vid}/${a}/* | sed -n "${i}p")
sleep 0.01
let i=i+1
[[ "${i}" -gt "${t}" ]] && i=1
done &
}
_list_vid(){
ls -d ${_dir_vid}/* 2>/dev/null >/dev/null
if [[ "$?" != "0" ]]; then
echo ${_lang[38]}
exit 1
fi
for i in $(ls -1 ${_dir_vid}/*/video.info); do
echo $i | awk 'BEGIN { FS = "/" } ; { print $6 }'
cat $i
done | paste - - | sed 's/\t/ → /g'
}
_set_video(){
ls -d ${_dir_vid}/* 2>/dev/null >/dev/null
if [[ "$?" != "0" ]]; then
echo ${_lang[38]}
exit 1
fi
if [[ $(echo "$1" | sed -n -r '/^[0-9]+$/p') == "" ]]; then
echo "${_lang[28]} '${0##*/} --list-videos'."
else
if [[ "$1" -gt "$(ls -d1 ${_dir_vid}/* | wc -l)" ]]; then
echo "${_lang[29]} $(ls -d1 ${_dir_vid}/* | wc -l)"
exit 1
else
t=$(ls ${_dir_vid}/${1}/* | wc -l)
let t=t-1
i=1
# ctrl_c
while : ; do
feh --no-fehbg --bg-fill $(ls -1 ${_dir_vid}/${1}/* | sed -n "${i}p")
sleep 0.01
let i=i+1
[[ "${i}" -gt "${t}" ]] && i=1
done &
fi
fi
}
while [[ "$1" ]]; do
case "${1}" in
-h|--help) _usage;;
-v|--version) echo "${0##*/} 0.0.1-beta";;
-s|--show) _show && exit;;
-c|--count) _count;;
-d|--display) _current;;
-t|--time) shift
if [[ $(echo "$1" | sed -n -r '/^[0-9]+$/p') == "" ]]; then
echo "${_lang[30]}"
else
_loop "$1"
fi
;;
-q|--quit) _quit_loop;;
-S|--set) export add=1;;
-a|--add) shift
while [[ -f "${1}" ]]; do
if [[ "$(file ${1} | awk '{print $2}')" == @(PNG|JPEG) ]]; then
_resize_img $1
else
echo "${_lang[31]}: $1"
fi
shift
done
;;
-u|--use) shift
ls ${_dir_img}/*.jpg 2>/dev/null >/dev/null
if [[ "$?" != "0" ]]; then
echo "${_lang[37]}"
exit 1
fi
if [[ $(echo "$1" | sed -n -r '/^[0-9]+$/p') == "" ]]; then
echo "${_lang[32]} $(_last_wall)"
else
if [[ "$1" > "$(_last_wall)" ]]; then
echo "${_lang[32]} $(_last_wall)"
else
_set_img "$1"
fi
fi
;;
-r|--remove-last) rm "${_dir_img}/wallpaper-$(_last_wall).jpg";;
--video|-V) shift;
[[ -z "$1" ]] && { echo "${_lang[36]}"; exit 1; }
[[ $(file -b --mime-type ${1} | cut -d"/" -f1) != 'video' ]] && { echo "${_lang[33]}"; exit 1; }
[[ $(file -b --mime-type ${1} | cut -d"/" -f2) != @(mp4|x-m4v) ]] && { echo "${_lang[34]}"; exit 1; }
_video "${1}"
;;
-L|--list-videos) _list_vid ;;
-I|--set-video) shift; _set_video "${1}";;
esac
shift
done