Initial commit
This commit is contained in:
commit
d2084e6d3c
5
README.md
Normal file
5
README.md
Normal file
@ -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.
|
73
otakukit
Executable file
73
otakukit
Executable file
@ -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 '<a href="magnet.*">' tmp.html | sed -n 's/.*href="\([^"]*\).*/\1/p' > magnets.bw
|
||||
|
||||
# get titles
|
||||
grep -o '<a href="/view/.*">' 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"
|
Loading…
Reference in New Issue
Block a user