shownotes-w3m-rice/diana-mui

171 lines
7.4 KiB
Plaintext
Raw Normal View History

2019-06-14 07:27:48 +00:00
#!/usr/bin/env bash
### _ _ _ _
### __ _ ___ | |_| |__ | | ___| |_ _ _
### / _` |/ _ \| __| '_ \| |/ _ \ __| | | |
###| (_| | (_) | |_| |_) | | __/ |_| |_| |
### \__, |\___/ \__|_.__/|_|\___|\__|\__,_|
### |___/
### https://www.youtube.com/user/gotbletu
### https://twitter.com/gotbletu
### https://github.com/gotbletu
### gotbletu@gmail.com
###
### Author : gotbletu
### Name : diana-mui
### Version : 0.2.3
### Date : 2020-05-05
2019-06-14 07:27:48 +00:00
### 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
2019-07-21 05:37:38 +00:00
2019-06-14 07:27:48 +00:00
# download path
2020-05-06 03:57:06 +00:00
DIANA_DOWNLOAD_DIR="$HOME/Downloads"
2019-06-14 07:27:48 +00:00
main_program () {
while true; do
clear
2019-07-21 05:37:38 +00:00
pidof tmux >/dev/null && tmux clear-history
printf '%s\n' '======== Diana MUI ========'
2019-06-14 07:27:48 +00:00
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'
2019-06-14 07:27:48 +00:00
printf '%s\n' ' s|S) Start Aria2c Daemon <==> STOP Daemon'
printf '%s\n' ' h|q) Help <==> Quit'
printf '\n'
2019-06-18 20:13:24 +00:00
printf '%s\n' ' * Tab:select-single Ctrl-A:select-all'
printf '%s\n' ' Ctrl-T:toggle-all Ctrl-D:deselect-all'
printf '\n'
2019-06-14 07:27:48 +00:00
printf ' Enter Your Choice: '
read -r INPUT
2019-06-14 07:27:48 +00:00
case "$INPUT" in
l) # List all (Ctrl+c to exit)
watch -t diana-progress
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
;;
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 &
2019-06-14 07:27:48 +00:00
# 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"
2019-06-14 07:27:48 +00:00
;;
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"
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
;;
P) # Pause All The Active Downloads (aka Sleep)
diana sleep
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
;;
C) # Resume All The Paused Downloads (aka Wake)
diana wake
2019-06-14 07:27:48 +00:00
;;
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"
2019-06-14 07:27:48 +00:00
;;
T) # Stop Seeding Completed Downloads (aka Clean)
diana clean
2019-06-14 07:27:48 +00:00
;;
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
2019-06-14 07:27:48 +00:00
sleep 3
;;
S) printf '%s\n' "Stopping Aria2c Daemon..."
dad stop
2019-06-14 07:27:48 +00:00
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'
2019-06-14 07:27:48 +00:00
printf '%s\n' 'Optional: aria2c addon (https://chrome.google.com/webstore/detail/aria2c-integration/edcakfpjaobkpdfpicldlccdffkhpbfk)'
printf '\n'
2019-06-14 07:27:48 +00:00
printf '%s\n' 'Author: gotbletu <gotbletu@gmail.com>'
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
2019-06-14 07:27:48 +00:00
;;
q|Q) # Quit/Exit
clear && break
;;
*) printf '%s\n' "Invalid Option... Try Again"
sleep 2
;;
esac
done
}
# run program
main_program