-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrandomusicv.alrc.plugin.sh
78 lines (64 loc) · 2.5 KB
/
brandomusicv.alrc.plugin.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
#! bash alrc-termux.module
#BrandomusicV offers a better version of BrandomusicQ at least it doesn't require a change to the export PATH="$PATH:/system/bin" for the input command keyevent but uses an environment variable. Read more (readme.md)
# Copyright (c) 2023 Luisadha, GNU GPLv3
set +o noclobber
function __brandomusicv()
{
# Testing on Musik com.miui.player (6.4.20i)
# Testing on Dialog Music Player phone.vishnu.dialogmusicplayer (v2.1.1)
# is Dialog Music Player
export DMPLAYER=true # phone.vishnu.dialogmusicplayer
#export BRANDO_RESPONSE=
export BRANDO_NO_CACHE=true
# Variabel ini digunakan untuk aplikasi DMP, aktifkan variabel di .bashrc jika anda memutar dengan DMP player
# Direkomendasikan untuk mengaktifkan variabel ini secara setinggan default untuk menghindari error
_TMP=".tmp"
if [[ $BRANDO_NO_CACHE == true ]]; then
export _TMP=""
source ~/.local/share/alrc-termux/plugins/brandomusicv.alrc.plugin.sh
fi
if [[ $DMPLAYER == true ]]; then
hide_soft_keyboard
fi
local format='audio/mp3';
local file="${1:+"${1}/*.mp3"}";
local file2="${1-"${HOME}/downloads/*.mp3"}";
local files=$(busybox ls ${file:-${file2}});
local n="${#files[@]}";
local pick="${files[RANDOM % n]}";
local result="$(printf "${0:+${pick}}" | shuf -n 1)";
local tmp="/sdcard/download/"$(basename "${result}")"$_TMP";
cd "/sdcard/Download" &> /dev/null;
cp -rf "${result}" "${tmp}" &> /dev/null;
answer=$BRANDO_RESPONSE
cat <<-EOF > $ALRC_HOME/cache/answer.txt
${answer}
EOF
read -rd '' content < $ALRC_HOME/cache/answer.txt
case "$answer" in
[Yy]*)
eval `am start -a android.intent.action.VIEW -d file://"${tmp}" -t ${format} ` &> /dev/null;
sleep 2;
echo;
if [ "$_TMP" == ".tmp" ]; then
brandomusic-cache-clear.sh;
else
rm -f "${tmp}";
fi
cd - &> /dev/null
return
;;
*)
rm -f "${tmp}";
termux-toast "brandomusicv: error, 'BRANDO_RESPONSE' variable environment not set yet!";
cd - &> /dev/null;
return 0
;;
esac
return
}
alias brandomusicv='setenv BRANDO_RESPONSE y && __brandomusicv'
plugin_shortname=$(echo "${BASH_SOURCE[0]}" | awk '{gsub(/.*[/]|[.].*/, "", $0)} 1' )
alrc_plugin_enabled+=($plugin_shortname)
readarray -t alrc_plugin_enabled <<< $(printf "%s\n" "${alrc_plugin_enabled[@]}" | sort -u)
unset plugin_shortname