123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- #!/bin/sh
- filter_list="none
- noremakes
- trusted"
- category_list="all
- anime
- anime_mv
- anime_english
- anime_other
- anime_raw
- audio
- lossless
- lossy
- literature
- literature_english
- literature_other
- literature_raw
- live_action
- live_action_english
- live_action_pv
- live_action_other
- live_action_raw
- picture
- graphic
- photo
- software
- apps
- games
- art
- art_anime
- art_doujin
- art_games
- art_manga
- art_pictures
- real_life
- real_life_pictures
- real_life_videos"
- filter="none"
- category="all"
- page=1
- instance="https://nyaa.si"
- exitsig=false
- if [ -z "$DMENU_COMMAND" ]; then
- dmenu="dmenu"
- else
- dmenu="$DMENU_COMMAND"
- fi
- select=""
- while ! ${exitsig}; do
- exitsig=true
- while true; do
- selection=$(printf "search\nchoose filter\nchoose category\nchoose instance\n" | $dmenu "$@" -p "Nyaash: ")
- case $selection in
- "search")
- break
- ;;
- "choose filter")
- user_filter="$(printf "%s\n" "$filter_list" | $dmenu "$@" -p "(Nyaash) Pick filter")"
- if [ -n "$user_filter" ]; then
- category="$user_filter"
- fi
- ;;
- "choose category")
- user_category="$(printf "%s\n" "$category_list" | $dmenu "$@" -p "(Nyaash) Pick category")"
- if [ -n "$user_category" ]; then
- category="$user_category"
- fi
- ;;
- "choose instance")
- case $(printf "https://nyaa.si\nhttps://sukebei.nyaa.si\ncustom" | $dmenu "$@" -p "(Nyaash) instance: ") in
- "https://nyaa.si")
- instance="https://nyaa.si"
- ;;
- "https://sukebei.nyaa.si")
- instance="https://sukebei.nyaa.si"
- ;;
- "custom")
- custom_instance="$(echo "" | $dmenu "$@" -p "(Nyaash) Custom Instance: ")"
- if [ -n "$custom_instance"]; then
- instance="$custom_instance"
- fi
- ;;
- *)
- ;;
- esac
- ;;
- *)
- if [ -z "$selection" ]; then
- exit 0
- fi
- break
- ;;
- esac
- done
- if [ "$selection" = "search" ]; then
- query=$(echo "" | $dmenu "$@" -p "(Nyaash) Search: ")
- else
- query=$selection
- fi
- new_search=true
- while true; do
- if $new_search; then
- page2="-p $page"
- output=$(nyaash "$query" -t $category -f $filter -i "$instance" -p $page)
- i=0
- itemname=""
- names=$(echo "$output" | awk '!((NR+4)%5)' | sed 's/^[0-9]* //')
- magnets=$(echo "$output" | awk '!((NR+3)%5)')
- sizes=$(echo "$output" | awk '!((NR+2)%5)' | grep -Eo "[0-9]+(\.[0-9]+)? (.i)?B")
- lines=$(echo "$names" | wc -l)
- unset namesizes
- while [ -n "$names" ]; do
- name=$(printf "%s" "$names" | head -n 1);
- size=$(printf "%s" "$sizes" | head -n 1);
- if [ -z "$namesizes" ]; then
- namesizes="$size $name"
- else
- namesizes=$(printf "%s\n%s %s" "$namesizes" "$size" "$name")
- fi
- names=$(echo "$names" | tail -n +2)
- sizes=$(echo "$sizes" | tail -n +2)
- done
- else
- new_search=true
- fi
- if [ $lines -gt 0 ]; then
- if [ $page -eq 1 ] && [ $lines -eq 75 ]; then
- selected="$(printf "main menu\nnext page\n%s\nnext page\nmain menu" "$namesizes" | $dmenu "$@" -p "(Nyaash) Download: ")"
- elif [ $page -gt 1 ] && [ $lines -eq 75 ]; then
- selected="$(printf "main menu\nnext page\nprevious page\n%s\nprevois page\nnext page\nmain menu" "$namesizes" | $dmenu "$@" -p "(Nyaash) Download: ")"
- elif [ $page -eq 1 ]; then # It's the first page, but has less than 75 items -> also the last page
- selected="$(printf "main menu\n%s\nmain menu" "$namesizes" | $dmenu "$@" -p "(Nyaash) Download: ")"
- else # It's not the first page, but it has less than 75 items -> it's the last page
- selected="$(printf "main menu\nprevious page\n%s\nprevous page\n main menu" "$namesizes" | $dmenu "$@" -p "(Nyaash) Download: ")"
- fi
- elif [ $page -gt 1 ]; then
- selected="$(printf "main menu\nprevious page\n" | $dmenu "$@" -p "(Nyaash) Download: ")"
- else
- selected="$(printf "no results\nmain menu\n" | $dmenu "$@" -p "(Nyaash) Download: ")"
- fi
- case "$selected" in
- "next page")
- page=$(( page + 1))
- ;;
- "previous page")
- page=$(( page - 1))
- ;;
- "main menu")
- exitsig=false
- break
- ;;
- "")
- break
- ;;
- *)
- selectedline=$(echo "$namesizes" | grep -nF "$selected" | grep -Eo '^[0-9]+')
- xdg-open $(printf "%s" "$magnets" | awk "NR==$selectedline") &
- choice=$(printf "yes\nno\n" | $dmenu "$@" -p "(Nyaash) Select another torrent?" )
- if ! echo "$choice" | grep -Eq '[Yy].*'; then
- break
- else
- new_search=false
- fi
- ;;
- esac
- done
- done
|