#!/bin/sh #shellcheck disable=SC2059 c_red="\033[1;31m" c_green="\033[1;32m" c_yellow="\033[1;33m" c_cyan="\033[1;36m" c_reset="\033[0m" down() { tput reset info_$os "Torrent: Downloading" 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="$*" if [ "$(uname -o)" = "Android" ]; then os="droid" script_dir="$HOME/.shortcuts" download_dir="/sdcard" [ -z "$magnet" ] && magnet="$(termux-clipboard-get)" else os="linux" script_dir="$HOME/repos_scripts" download_dir="$HOME/Softwares" [ -z "$magnet" ] && magnet="$(wl-paste)" fi #import generic 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 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:" read -r ch case $ch in f) down "$magnet" ;; p) 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/$file.torrent" printf "${c_cyan}Enter file idx(default=all): " read -r ind down "$HOME/.cache/$file.torrent" "$ind" rm -f "$HOME/.cache/$file.torrent" ;; q) exit 0 ;; esac