Skip to content

Updated script to share, search and autodownload by keyword and uploader #7

Description

@ysguy

Thanks for the script, I made some changes

  • Two scripts, one does download by uploader, keeps processed magnets and checks / does not redownload duplicates
  • The other script downloads everything based on a keyword, again keeps processed magnets
  • The last script is because i use Transmission instead of deluge so I can pass to that and auto-add/start magnets and specify the add folder.

First file - fetch based on username of uploader, usage

./filename <start page #> <end page #>

e.g. ./filename cooluploader 1 10

`
#!/bin/bash

mkdir -p $HOME/.cache/pirokit

if [ -z $1 ]; then
query=$(echo "" | dmenu -p "Search Torrent: ")
else
query=$1
fi

start=$2
end=$3

echo "----- Begin processing $1"

for (( a = $start ; a <= $end ; a++))
do

baseurl="https://1337x.to"
cachedir="$HOME/.cache/pirokit"
query="$(sed 's/ /+/g' <<<$query)"
fails=0

curl -s https://1337x.to/$query-torrents/$a/ > $cachedir/tmp.html

#Get Titles
grep -o '<a href="/torrent/.' $cachedir/tmp.html |
sed 's/<[^>]
>//g' > $cachedir/titles.bw

result_count=$(wc -l $cachedir/titles.bw | awk '{print $1}')
if [ "$result_count" -lt 1 ]; then
notify-send "😔 No Result found. Try again 🔴"
exit 0
fi

#Seeders and Leechers
grep -o '<td class="coll-2 seeds.|<td class="coll-3 leeches.' $cachedir/tmp.html |
sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > $cachedir/seedleech.bw

#Size
grep -o '<td class="coll-4 size.' $cachedir/tmp.html |
sed 's/.
</span>//g' |
sed -e 's/<[^>]*>//g' > $cachedir/size.bw

#Links
grep -E '/torrent/' $cachedir/tmp.html |
sed -E 's#.(/torrent/.)/">.*/#\1#' |
sed 's/td>//g' > $cachedir/links.bw

#Clearning up some data to display
sed 's/./ /g; s/-/ /g' $cachedir/titles.bw |
sed 's/[^A-Za-z0-9 ]//g' | tr -s " " > $cachedir/tmp && mv $cachedir/tmp $cachedir/titles.bw

awk '{print NR " - ["$0"]"}' $cachedir/size.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/size.bw
awk '{print "[S:"$1 ", L:"$2"]" }' $cachedir/seedleech.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/seedleech.bw

LINEC=$(wc -l < ~/.cache/pirokit/links.bw)

for (( x = 0 ; x <= $LINEC ; x++))
do
LINE=$x
url=$(head -n $LINE $cachedir/links.bw | tail -n +$LINE)
fullURL="${baseurl}${url}/"

    echo "Processing: $fullURL Page $a of $2"

    #Requesting page for magnet link
    curl -s $fullURL > $cachedir/tmp.html
    magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" $cachedir/tmp.html | head -n 1)

    #echo "Adding Magnet:  $magnet"
    if [ $(grep "$magnet" processed | wc -l) -eq 0 ]; then
            echo "⬇️  Start downloading File 📁: $magnet"
            ./mag2trans.sh "$magnet"
            #Simple notification
            echo "$magnet" >> processed
    else
            if [ $fails -gt 3 ]; then #Stop processing after 4 duplicates
                echo "----- Max duplicates reached, ending processing of $1"
                break 3
            fi
       echo "Duplicate Magnet, skipping..."
       ((fails=fails+1))
    fi
    done

done
`

2nd script
Change the curl line to the following

First file - fetch based on search word

./filename <start page #> <end page #>

e.g. ./filename wallpaper 1 10

curl -s https://1337x.to/search/$query/$a/ > $cachedir/tmp.html

3rd script mag2trans.sh taken from an example online and extended to allow for destination path subfolder (non standard download folder in transmission)

`#!/bin/bash
test -z $1 && echo "need magnet link!
$0 " && exit -1

HOST=localhost
PORT=9091
USER=username
DLPATH="/path/to/custom/download/folder/"
#NOTE: I had issues using passwords with semicolons (;) in them,
#you might want to stay away from them
PASS=password

LINK="$1"
#set true if you want every torrent to be paused initially
#PAUSED="true"
PAUSED="false"
SESSID=$(curl --silent --anyauth --user $USER:$PASS "http://$HOST:$PORT/transmission/rpc" | sed 's/.//g;s/</code>.//g')
curl --silent --anyauth --user $USER:$PASS --header "$SESSID" "http://$HOST:$PORT/transmission/rpc" -d "{"method":"torrent-add","arguments":{"paused":${PAUSED},"filename":"${LINK}","download-dir":"${DLPATH}"}}"
`

Hope someone finds this as useful as i do.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions