Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We don't need to implement a save mechanism: aria2c already has --save-session.
- Loading branch information
1 parent
7be447f
commit 2dbbe4d
Showing
5 changed files
with
82 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,51 @@ | ||
![diana] (https://github.com/baskerville/diana/raw/master/preview/diana_logo.jpg) | ||
![diana] (https://github.com/baskerville/diana/raw/master/logo/diana-logo.jpg) | ||
|
||
SYNOPSIS | ||
diana <action> [arguments] | ||
## Usage | ||
|
||
ACTIONS | ||
list | ||
Show the list of active downloads. | ||
dad [-h|-d DOWNLOAD_DIR] start|stop | ||
diana ACTION [ARGUMENTS] | ||
|
||
paused | ||
Show the list of paused downloads. | ||
## Actions | ||
|
||
stopped | ||
Show the list of stopped downloads. | ||
- `list` — Output the list of active downloads. | ||
|
||
errors | ||
Show the list of encountered errors. | ||
- `paused` — Output the list of paused downloads. | ||
|
||
stats | ||
Show download bandwidth statistics. | ||
- `stopped` — Output the list of stopped downloads. | ||
|
||
sleep | ||
Pause all the active downloads. | ||
- `info [--select-file=...] GID ...` — Output informations regarding the given GIDs. | ||
|
||
wake | ||
Resume all the paused downloads. | ||
- `files GID ...` — Output the files owned by the downloads corresponding to the given GIDs. | ||
|
||
purge | ||
Clear the list of stopped downloads and errors. | ||
- `errors` — Output the list of errors. | ||
|
||
clean | ||
Stop seeding completed downloads. | ||
- `stats` — Output download bandwidth statistics. | ||
|
||
kill | ||
Kill the daemon. | ||
- `add [--select-file=...] ITEM ...` — Download the given items (local or remote URLs to torrents, etc.). | ||
|
||
add [--select-file=...] ITEM ... | ||
Download the given items (local or remote URLs to torrents, etc.). | ||
- `remove GID ...` — Remove the downloads corresponding to the given GIDs. | ||
|
||
remove GID ... | ||
Remove the downloads corresponding to the given GIDs. | ||
- `forcerm GID ...` — Forcibly remove the downloads corresponding to the given GIDs. | ||
|
||
forcerm GID ... | ||
Forcibly remove the downloads corresponding to the given GIDs. | ||
- `pause GID ...` — Pause the downloads corresponding to the given GIDs. | ||
|
||
pause GID ... | ||
Pause the downloads corresponding to the given GIDs. | ||
- `resume GID ...` — Resume the downloads corresponding to the given GIDs. | ||
|
||
resume GID ... | ||
Resume the downloads corresponding to the given GIDs. | ||
- `preview [--select-file=...] GID ...` — Preview all the files from all the downloads corresponding to the given GIDs. | ||
|
||
files GID ... | ||
Show the files owned by the downloads corresponding to the given GIDs. | ||
- `sleep` — Pause all the active downloads. | ||
|
||
info [--select-file=...] GID ... | ||
Retrieve informations regarding the given GIDs. | ||
- `wake` — Resume all the paused downloads. | ||
|
||
preview [--select-file=...] GID ... | ||
Preview all the files from all the downloads corresponding to the given GIDs. | ||
- `purge` — Clear the list of stopped downloads and errors. | ||
|
||
- `clean` — Stop seeding completed downloads. | ||
|
||
## Prerequisites | ||
|
||
First launch the daemon which is called `dad`. | ||
|
||
## Get the File Indexes | ||
|
||
This function might help: | ||
|
||
tl () { | ||
aria2c -S "$@" | grep '\./' | ||
} | ||
## Environment Variables | ||
|
||
- `DIANA_DOWNLOAD_DIR` — Used by the daemon. | ||
|
||
## Dependencies | ||
|
||
`aria2` and `python3`. | ||
- aria2 | ||
- python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,67 @@ | ||
#! /bin/sh | ||
|
||
diana list > /dev/null 2>&1 | ||
usage() { | ||
printf '%s [-h|-d DOWNLOAD_DIR] start|stop\n' "${0##*/}" | ||
} | ||
|
||
if [ $? -eq 0 ] ; then | ||
printf '%s.\n' 'The daemon is already running' >&2 | ||
download_dir=${DIANA_DOWNLOAD_DIR:-${XDG_DOWNLOAD_DIR:-${HOME}}} | ||
|
||
while getopts 'hd:' opt ; do | ||
case "$opt" in | ||
h) | ||
usage | ||
exit 0 | ||
;; | ||
d) | ||
download_dir=$OPTARG | ||
;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND - 1)) | ||
|
||
if [ $# -ne 1 ] ; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
DOWNLOAD_DIR=${1:-${XDG_DOWNLOAD_DIR:-${HOME}}} | ||
daemon_pid=/tmp/diana-daemon.pid | ||
|
||
aria2c -D --enable-rpc -j 13 -d "$DOWNLOAD_DIR" | ||
case "$1" in | ||
start) | ||
if [ -e "$daemon_pid" ] ; then | ||
printf '%s\n' 'The daemon is already running.' >&2 | ||
exit 1 | ||
fi | ||
|
||
HASHES_FILE=${XDG_DATA_HOME:-${HOME}/.local/share}/diana.lst | ||
BACKUP_HASHES=${HASHES_FILE}.bak | ||
XDG_DATA_HOME=${XDG_DATA_HOME:-${HOME}/.local/share} | ||
diana_session=${XDG_DATA_HOME}/diana.session | ||
|
||
if [ ! -e "$HASHES_FILE" ] ; then | ||
if [ -e "$BACKUP_HASHES" ] ; then | ||
mv "$BACKUP_HASHES" "$HASHES_FILE" | ||
else | ||
exit 0 | ||
fi | ||
fi | ||
[ ! -e "$diana_session" ] && touch "$diana_session" | ||
|
||
tmp_file=$(mktemp) | ||
sort -u "$HASHES_FILE" > "$tmp_file" | ||
cp "$tmp_file" "$HASHES_FILE" | ||
rm "$tmp_file" | ||
|
||
for line in $(cat "$HASHES_FILE") ; do | ||
rhsh=${line%:*} | ||
sel=${line#*:} | ||
hsh=${rhsh#_} | ||
|
||
for tor in "$DOWNLOAD_DIR"/*.torrent ; do | ||
match=$(aria2c -S "$tor" | grep -m 1 "$hsh") | ||
if [ -n "$match" ] ; then | ||
printf '%s\n' "$tor" | ||
gid=$(diana --select-file="$sel" add "$tor") | ||
[ $? -ne 0 ] && exit 1 | ||
case $rhsh in | ||
_*) | ||
diana pause $gid | ||
;; | ||
esac | ||
aria2c --daemon --enable-rpc --continue --dir "$download_dir" --input-file "$diana_session" --save-session "$diana_session" | ||
|
||
pgrep -n -x aria2c > "$daemon_pid" | ||
|
||
if [ $? -ne 0 ] ; then | ||
printf '%s\n' 'The daemon failed to start.' >&2 | ||
rm "$daemon_pid" | ||
exit 1 | ||
fi | ||
done | ||
done | ||
;; | ||
stop) | ||
if [ ! -e "$daemon_pid" ] ; then | ||
printf '%s\n' 'The daemon is not running.' >&2 | ||
exit 1 | ||
fi | ||
|
||
kill $(cat "$daemon_pid") > /dev/null 2>&1 | ||
|
||
mv "$HASHES_FILE" "$BACKUP_HASHES" | ||
if [ $? -ne 0 ] ; then | ||
printf '%s\n' 'Could not stop the daemon.' >&2 | ||
exit 1 | ||
else | ||
rm "$daemon_pid" | ||
fi | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.