forked from gotbletu/shownotes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
diana-mui
executable file
·170 lines (162 loc) · 7.43 KB
/
diana-mui
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
#!/usr/bin/env bash
### _ _ _ _
### __ _ ___ | |_| |__ | | ___| |_ _ _
### / _` |/ _ \| __| '_ \| |/ _ \ __| | | |
###| (_| | (_) | |_| |_) | | __/ |_| |_| |
### \__, |\___/ \__|_.__/|_|\___|\__|\__,_|
### |___/
### https://www.youtube.com/user/gotbletu
### https://twitter.com/gotbletu
### https://github.com/gotbletu
###
### Author : gotbletu
### Name : diana-mui
### Version : 0.2.3
### Date : 2020-05-05
### Description : diana-mui is a Menu User Interface to the diana program. Diana is a commandline interface to aria2 daemon
### Depends On : bash aria2 coreutils fzf gawk procps-ng xdg-utils diana (https://github.com/baskerville/diana)
### Video Demo : https://www.youtube.com/watch?v=y59JwlYsrAE
### References : https://github.com/baskerville/diana/blob/87c5b1b57425585b4c0f543edcf7e9038cf793c5/diana#L427-L429
# 2020-05-05 v0.2.3 added d,D,M hotkeys for changing config, download path, show path. shellcheck passes 99%-ignore expand warning
# 2019-07-20 v0.2.2 added tmux clear scrollback
# 2019-06-07 v0.2.1 added extra hotkeys
# download path
DIANA_DOWNLOAD_DIR="$HOME/Downloads"
main_program () {
while true; do
clear
pidof tmux >/dev/null && tmux clear-history
printf '%s\n' '======== Diana MUI ========'
printf '%s\n' ' o|l) Open File <==> List All Downloads'
printf '%s\n' ' a|A) Add <==> Add Paused'
printf '%s\n' ' i|f) File Info <==> Show Filename'
printf '%s\n' ' r|R) Remove * <==> Force Remove *'
printf '%s\n' ' p|P) Pause * <==> Pause All Active'
printf '%s\n' ' c|C) Resume * <==> Resume All Paused'
printf '%s\n' ' T) Stop Seeding Completed Torrents'
printf '%s\n' ' E) Clear Completed Downloads & Errors'
printf '%s\n' ' M) Modify Aria2 Configuration'
printf '%s\n' ' d|D) Show Path <==> Change Download Path'
printf '%s\n' ' s|S) Start Aria2c Daemon <==> STOP Daemon'
printf '%s\n' ' h|q) Help <==> Quit'
printf '\n'
printf '%s\n' ' * Tab:select-single Ctrl-A:select-all'
printf '%s\n' ' Ctrl-T:toggle-all Ctrl-D:deselect-all'
printf '\n'
printf ' Enter Your Choice: '
read -r INPUT
case "$INPUT" in
l) # List all (Ctrl+c to exit)
watch -t diana-progress
;;
i) # Show File Info
# GID=`(diana list && diana paused && diana stopped && diana errors) | fzf | awk '{print $1}'`
GID=$( (diana list && diana paused && diana stopped && diana errors) | fzf | awk '{print $1}')
diana info "$GID"
read -rsp $'Press any key to return to main menu\n' -n1
;;
f) # Show Filename
# GID=`(diana list && diana paused && diana stopped && diana errors) | fzf | awk '{print $1}'`
GID=$( (diana list && diana paused && diana stopped && diana errors) | fzf | awk '{print $1}')
diana files "$GID"
read -rsp $'Press any key to return to main menu\n' -n1
;;
o) # Open File
# GID=`(diana list && diana paused && diana stopped && diana errors) | fzf | awk '{print $1}'`
GID=$( (diana list && diana paused && diana stopped && diana errors) | fzf | awk '{print $1}')
nohup xdg-open "$(diana files "$GID" | cut -d'%' -f2- | awk '{$1=$1};1')" >/dev/null 2>&1 &
# read -rsp $'Press any key to return to main menu\n' -n1 key
;;
a) # Add
printf '%s\n' ">>> Add [<URI>|<MAGNET>|<TORRENT_FILE>|<METALINK_FILE] To Active Downloads"
read -r -e -p ">>> " URI
diana add "$URI"
;;
A) # Add Paused
printf '%s\n' ">>> Add [<URI>|<MAGNET>|<TORRENT_FILE>|<METALINK_FILE] To Paused Downloads"
read -r -e -p ">>> " URI
diana --pause add "$URI"
;;
r) # Removing Download
(diana list && diana paused ) | fzf -m --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all | awk '{print $1}' | while read -r GID; do diana remove "$GID"; done
;;
R) # Force Removing Download
(diana list && diana paused ) | fzf -m --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all | awk '{print $1}' | while read -r GID; do diana forcerm "$GID"; done
;;
p) # Pausing Download
diana list | fzf -m --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all | awk '{print $1}' | while read -r GID; do diana pause "$GID"; done
;;
P) # Pause All The Active Downloads (aka Sleep)
diana sleep
;;
c) # Resuming Download
diana paused | fzf -m --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all | awk '{print $1}' | while read -r GID; do diana resume "$GID"; done
;;
C) # Resume All The Paused Downloads (aka Wake)
diana wake
;;
E) # Clear The List Of Stopped Downloads And Errors (aka Purge)
diana purge
;;
d) # show current aria2 download location
printf '\n'
printf "%s\n" "Current Download Path: $DIANA_DOWNLOAD_DIR"
printf '\n'
read -rsp $'Press any key to return to main menu\n' -n1
;;
D) # change aria2 download location
printf '%s\n' ">>> Set Your Default Download Directory"
read -r -e -p ">>> " DIR
DIR=$(printf '%s' "$DIR" | sed 's/^~/$HOME/g')
sed -i 's:^DIANA_DOWNLOAD_DIR=.*:DIANA_DOWNLOAD_DIR='\""$DIR"\"':g' "$0"
printf '\n'
printf "%s\n" "Restart Daemon And Script To Apply Changes"
printf '\n'
read -rsp $'Press any key to return to main menu\n' -n1
;;
M) # modify edit aria2 configuration
if [ ! -d "$HOME/.config/aria2" ]; then mkdir -p "$HOME/.config/aria2" ; fi
$EDITOR "$HOME/.config/aria2/aria2.conf"
;;
T) # Stop Seeding Completed Downloads (aka Clean)
diana clean
;;
s) printf '%s\n' "Starting Aria2c Daemon..."
printf '%s\n' "Download To: $DIANA_DOWNLOAD_DIR"
mkdir -p "$DIANA_DOWNLOAD_DIR"
dad -d "$DIANA_DOWNLOAD_DIR" start
sleep 3
;;
S) printf '%s\n' "Stopping Aria2c Daemon..."
dad stop
sleep 3
;;
h|H) # Help page
clear
printf '%s\n' 'Diana-MUI is a Menu User Interface to the diana program.'
printf '%s\n' 'Diana is a commandline interface to aria2 daemon.'
printf '%s\n' 'Aria2 is a download utility that supports HTTP(S), FTP, BitTorrent, and Metalink.'
printf '\n'
printf '%s\n' 'Requirements: bash aria2 coreutils sed fzf gawk procps-ng xdg-utils diana (https://github.com/baskerville/diana)'
printf '\n'
printf '%s\n' 'Optional: aria2c addon (https://chrome.google.com/webstore/detail/aria2c-integration/edcakfpjaobkpdfpicldlccdffkhpbfk)'
printf '\n'
printf '%s\n' 'Author: gotbletu <[email protected]>'
printf '%s\n' ' https://www.youtube.com/user/gotbletu'
printf '%s\n' ' https://twitter.com/gotbletu'
printf '%s\n' ' https://github.com/gotbletu'
printf '\n'
read -rsp $'Press any key to return to main menu\n' -n1
;;
q|Q) # Quit/Exit
clear && break
;;
*) printf '%s\n' "Invalid Option... Try Again"
sleep 2
;;
esac
done
}
# run program
main_program