From 736628ba27a0c7c5332027c9817f69024d3a0095 Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 23 Mar 2020 06:49:34 +0100 Subject: [PATCH] Clear output crawler, add torrent location in db.py --- crawl.py | 6 ++---- lib/scrabash.sh | 9 +++++---- trans-ctl.sh | 13 +++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crawl.py b/crawl.py index ce76c9c..1162056 100755 --- a/crawl.py +++ b/crawl.py @@ -31,7 +31,6 @@ name = ' '.join(sys.argv[1:]) # Search torrent name research = os.popen('./lib/scrabash.sh search --best=true ' + name).read() -print(colored(research, 'yellow')) try: research.index("No torrent found") @@ -53,8 +52,7 @@ def rollingFiles(): idTorrent = os.popen('./lib/scrabash.sh get_details ' + research).read() dbPath = "./data/meta/{}/db.py".format(idTorrent.rstrip()) torrentDB = os.popen('cat ' + dbPath).read() - - print(torrentDB) + print(colored(torrentDB, 'blue')) print("---") torrentDBFile = open(dbPath, "r") @@ -119,7 +117,7 @@ def removeTracker(): time.sleep(tkdelay) tkresult = os.popen('./trans-ctl.sh rmtracker ' + name).read() tkresult = os.popen('./trans-ctl.sh rmtracker ' + higherid).read() - print(tkresult) +# print(tkresult) rollingFiles() downloadTorrent() diff --git a/lib/scrabash.sh b/lib/scrabash.sh index 2b51e03..740da47 100755 --- a/lib/scrabash.sh +++ b/lib/scrabash.sh @@ -28,12 +28,13 @@ get_details() { echo "$result" > info.txt torrentName=$(echo "$result" | grep -w "Name :" | awk -F ": " '{ print $2 }') - Url=$(echo "$result" | grep -w "Url :" | awk -F ": " '{ print $2 }') + Category=$(echo "$name" | awk -F '/' '{print $6}') Size=$(echo "$result" | grep -w "Size :" | awk -F ": " '{ print $2 }') Uploader=$(echo "$result" | grep -w "Uploader :" | awk -F ": " '{ print $2 }') Files=$(echo "$result" | grep -w "file_name :" | awk -F ": " '{ print $2 }' | wc -l) - FilesNames=$(echo "$result" | grep -w "file_name :" | awk -F ": " '{ print $2 }' | tr -d '"}') - FilesLocations="data/files/$FilesNames" + FileName=$(echo "$result" | grep -w "file_name :" | awk -F ": " '{ print $2 }' | tr -d '"}' | head -n1 | awk -F '/' '{ print $1 }') + FilesLocations="data/files/$FileName" + TorrentLocation="data/torrents/$FileNameShort.torrent" if [[ $Size =~ "Go" ]]; then Unity="Go" @@ -45,7 +46,7 @@ get_details() { echo "$idTorrent" - echo -e "Name = '$torrentName'\nUrl = '$Url'\nSize = $Size\nUnity = '$Unity'\nID = $idTorrent\nUploader = $Uploader\nFiles = $Files\nFilesLocations = $FilesLocations" > db.py + echo -e "Name = $torrentName\nUrl = $name\nCategory = $Category\nSize = $Size\nUnity = $Unity\nID = $idTorrent\nUploader = $Uploader\nFiles = $Files\nFilesLocations = $FilesLocations\nTorrentLocation = $TorrentLocation" > db.py # Get image [[ ! -d img ]] && mkdir img && cd img diff --git a/trans-ctl.sh b/trans-ctl.sh index d71b88a..863f31c 100755 --- a/trans-ctl.sh +++ b/trans-ctl.sh @@ -18,10 +18,12 @@ name="${@:2}" # Functions getid() { + # Check if no name, give last ID if [[ -z $name ]]; then result=$($transcmd --list | grep -vE 'Sum:|ID Done' | tail -n1 | awk '{ print $1 }') elif [[ $name =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then result=$name + # Get ID else j=0 for i in "$name"; do @@ -84,6 +86,17 @@ case "$1" in remove) idt=$(getid | tr -d '*') if [[ $idt =~ ^[+-]?[0-9]+([.][0-9]+)?$ ]]; then + for i in "$($transcmd --list | grep -vE 'Sum:|ID Done' )"; do + if [[ $(echo "$i" | awk '{ print $1 }') == $idt ]]; then + fileName=$(echo "$i" | awk '{ print $NF }') + break + fi + done + + cd data/meta + torrentId=$(grep -r $fileName | head -n1 | awk -F '/' '{ print $1 }') + rm -rf $torrentId + $transcmd -t $idt --remove-and-delete > /dev/null && echo "Torrent $idt removed." || echo "Failed to remove $1" else echo "$idt"