commit d2084e6d3c3a509fc4c71b9b8d67821946c9597e Author: Crony Akatsuki Date: Mon Nov 21 12:40:12 2022 +0100 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0684771 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# OtakuKit + +Simple dmenu script to search nyaa.si and dowloand stuff using transmission daemon. + +Support's searching by category and next and previous pages. diff --git a/otakukit b/otakukit new file mode 100755 index 0000000..4139c9f --- /dev/null +++ b/otakukit @@ -0,0 +1,73 @@ +#!/bin/bash + +baseurl="https://nyaa.si" +cachedir="$HOME/.cache/ok" + +# get query +query=$(printf '%s' | dmenu -p "Search Otaku Shit: " | sed 's/ /+/g') + +# setup working dir +mkdir -p $cachedir +cd $cachedir + +case "$(printf "All\\nAnime\\nAudio\\nLiterature" | dmenu -p "Category to search in: ")" in + All) url="${baseurl}/?f=0&c=0_0&q=${query}" ;; + Anime) url="${baseurl}/?f=0&c=1_2&q=${query}" ;; + Audio) url="${baseurl}?f=0&c=2_0&q=${query}" ;; + Literature) url="${baseurl}?f=0&c=3_1&q${query}" ;; + *) exit ;; +esac + +case "$(printf "Normal\\nSeeders" | dmenu -p "Sort by:")" in + Normal) break;; + Seeders) url="${url}&s=seeders&o=desc" ;; + *) exit ;; +esac + +page=1 + +while true; do + + # get the page html + curl -s "$url&p=$page" --compressed -o tmp.html + + # get magnets + grep -o '' tmp.html | sed -n 's/.*href="\([^"]*\).*/\1/p' > magnets.bw + + # get titles + grep -o '' tmp.html | sed -n 's/.*title="\([^"]*\).*/\1/p' | grep -v 'comment.*' > titles.bw + + # get sizes + pup 'td.text-center text{}' -f tmp.html | awk -v RS='' '{print $1, $2}' | sed -r '/^\s*$/d' > sizes.bw + + # get seeders + pup 'td.text-center text{}' -f tmp.html | awk -v RS='' '{print $5}' | sed -r '/^\s*$/d' > seeders.bw + + # get leechers + pup 'td.text-center text{}' -f tmp.html | awk -v RS='' '{print $6}' | sed -r '/^\s*$/d' > leechers.bw + + # generate line numbers + awk '{print NR " - "$0""}' titles.bw > titlesNumbered.bw + + # prepend next and previous + [ "$page" = "1" ] && printf '%s\n' "next" >> titlesNumbered.bw || \ + printf '%s\n%s' "next" "previous" >> titlesNumbered.bw + + #gets line number (that groupthe user selected in dmenu) + LINE=$(paste -d\| titlesNumbered.bw seeders.bw leechers.bw sizes.bw | \ + sed 's/|||//' | dmenu -i -l 25 | cut -d- -f1) + + [ "$LINE" = "next" ] && let "page+=1" && continue + + [ "$LINE" = "previous" ] && let "page-=1" && continue + + [ -z "$LINE" ] && exit || break +done + +#get the magnet link +magnet=$(sed "${LINE}q;d" magnets.bw) + +transmission-remote -a $magnet + +#notify the user that the download has started +quick-notify "Otaku Kit" "Download Started"