Advertisement
metalx1000

BASH Torrent Search

Mar 22nd, 2020
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2020  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. csv="/tmp/torrent.csv"
  21. url="https://gitlab.com/dessalines/torrents.csv/-/raw/master/torrents.csv"
  22. open="xdg-open"
  23. red=`echo -en "\e[31m"`
  24. normal=`echo -en "\e[0m"`
  25. #check dependences
  26. for d in aria2c fzf
  27. do
  28.   [[ ! -f "/usr/bin/$d" ]] &&
  29.     echo -e "${red}$d${normal} is needed\nplease install it\nsudo apt install ${red}$d${normal}" &&
  30.     sleep 3 &&
  31.     continue="$(echo -e "Continue\nExit"|fzf --prompt="Continue without $d: ")"
  32.     [[ "$continue" == "Exit" ]] && exit 1
  33. done
  34.  
  35. function main(){
  36.   [[ ! -f "$csv"  || "$1" == "update" ]] && getList
  37.   [[ "$1" == "sites" ]] && (sites;exit)
  38.   [[ "$1" == "" ]] && search
  39. }
  40.  
  41. function getList(){
  42.   aria2c -x 10 "$url" -o "$csv"
  43.   # wget "$url" -O-|while read line;do
  44.   #   size_bytes=$(echo -e "$line" | cut -d ';' -f3)
  45.   #   size=$(numfmt --to=iec-i --suffix=B $size_bytes)
  46.   #   echo "$line"|cut -d\; -f1,2|tr -d "\n"
  47.   #   echo ";$size"
  48.   # done > "$csv"
  49. }
  50.  
  51.  
  52. function search(){
  53.   item="$(cat "$csv"|awk -F';' '{print $1 ";" $2 ";" $3 ";" $5}'|fzf)"
  54.   title="$(echo "$item"|cut -d\; -f2)"
  55.   magnet="magnet:?xt=urn:btih:$(echo "$item"|cut -d\; -f1)"
  56.   seeds=$(echo -e "$item" | cut -d ';' -f4)
  57.   size_bytes=$(echo -e "$item" | cut -d ';' -f3)
  58.   size=$(numfmt --to=iec-i --suffix=B $size_bytes)
  59.  
  60.   a="$(echo -e "Download\nCancel"|fzf --prompt "Download $title [$size - SEEDS: $seeds]?")"
  61.   echo -e "=======================\n$title\n$size\n$magnet\n======================="
  62.  
  63.   [[ "$a" == "Download" ]] && aria2c "$magnet" || (echo "Goodbye";exit)
  64. }
  65.  
  66. function sites(){
  67.   read -p "Enter Search String: " q
  68.   $open "https://t.extto.com/search/?q=$q"  
  69.   read -p "Enter Torrent/Magnet Link: " magnet
  70.   [[ "$magnet" == "" ]] && echo "Good-bye" || aria2c --seed-time=0 "$magnet"
  71. }
  72.  
  73. main $*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement