mirror of
https://github.com/CoolnsX/repos_scripts.git
synced 2025-12-20 07:15:20 +05:30
first blush
This commit is contained in:
22
torrent
22
torrent
@@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#shellcheck disable=SC2059
|
||||
|
||||
c_red="\033[1;31m"
|
||||
c_green="\033[1;32m"
|
||||
c_yellow="\033[1;33m"
|
||||
@@ -9,7 +11,8 @@ c_reset="\033[0m"
|
||||
down() {
|
||||
tput reset
|
||||
info_$os "Torrent: Downloading"
|
||||
aria2c --file-allocation=trunc -d Softwares --select-file=$2 --seed-time=0 $1 && info_$os "Torrent: Download complete" && rm -f $file || error_$os "Torrent: Error!!"
|
||||
aria2c --file-allocation=trunc -d "$download_dir" --select-file="$2" --seed-time=0 "$1" && info_$os "Torrent: Download complete" && return 0
|
||||
error_$os "Torrent: Error!!"
|
||||
}
|
||||
|
||||
magnet="$*"
|
||||
@@ -21,16 +24,16 @@ if [ "$(uname -o)" = "Android" ]; then
|
||||
else
|
||||
os="linux"
|
||||
script_dir="$HOME/repos_scripts"
|
||||
download_dir="Downloads"
|
||||
download_dir="$HOME/Softwares"
|
||||
[ -z "$magnet" ] && magnet="$(wl-paste)"
|
||||
fi
|
||||
|
||||
#import generic functions
|
||||
. $script_dir/.functions
|
||||
# shellcheck source=./.functions
|
||||
. "$script_dir/.functions"
|
||||
|
||||
#check if the url is magnet
|
||||
! printf "%s" "$magnet" | grep -qE "magnet:\?xt=urn:btih:|torrent" && error_$os "Not a valid magnet link!" && exit 0
|
||||
trap "rm -f $HOME/.cache/*.torrent;exit 0" INT HUP
|
||||
echo "$magnet"
|
||||
printf "${c_yellow}Download>>\n${c_green}[f]ull torrent\n${c_cyan}[p]artial torrent \n${c_red}[q]uit"
|
||||
printf "${c_reset}\n\tenter choice:"
|
||||
@@ -40,13 +43,14 @@ case $ch in
|
||||
down "$magnet"
|
||||
;;
|
||||
p)
|
||||
aria2c --dir=$HOME/.cache --bt-metadata-only=true --bt-save-metadata=true "$magnet"
|
||||
file=$(printf "%s" "$magnet" | sed -nE 's|.*urn:btih:([^&]*).*|\1|p' | tr '[:upper:]' '[:lower:]')
|
||||
aria2c --dir="$HOME/.cache" --bt-metadata-only=true --bt-save-metadata=true "$magnet"
|
||||
tput reset
|
||||
aria2c --show-files=true $HOME/.cache/*.torrent
|
||||
info_$os "Enter file idx(default=all):"
|
||||
aria2c --show-files=true "$HOME/.cache/$file.torrent"
|
||||
printf "${c_cyan}Enter file idx(default=all): "
|
||||
read -r ind
|
||||
down "$HOME/.cache/*.torrent" "$ind"
|
||||
rm -f $HOME/.cache/*.torrent
|
||||
down "$HOME/.cache/$file.torrent" "$ind"
|
||||
rm -f "$HOME/.cache/$file.torrent"
|
||||
;;
|
||||
q)
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user