dmenu_nyaa.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/sh
  2. filter_list="none
  3. noremakes
  4. trusted"
  5. category_list="all
  6. anime
  7. anime_mv
  8. anime_english
  9. anime_other
  10. anime_raw
  11. audio
  12. lossless
  13. lossy
  14. literature
  15. literature_english
  16. literature_other
  17. literature_raw
  18. live_action
  19. live_action_english
  20. live_action_pv
  21. live_action_other
  22. live_action_raw
  23. picture
  24. graphic
  25. photo
  26. software
  27. apps
  28. games
  29. art
  30. art_anime
  31. art_doujin
  32. art_games
  33. art_manga
  34. art_pictures
  35. real_life
  36. real_life_pictures
  37. real_life_videos"
  38. filter="none"
  39. category="all"
  40. page=1
  41. instance="https://nyaa.si"
  42. exitsig=false
  43. select=""
  44. while ! ${exitsig}; do
  45. exitsig=true
  46. while true; do
  47. case $(printf "search\nchoose filter\nchoose category\nchoose instance\n" | dmenu "$@" -p "Nyaash: ") in
  48. "search")
  49. break
  50. ;;
  51. "choose filter")
  52. user_filter="$(printf "%s\n" "$filter_list" | dmenu "$@" -p "(Nyaash) Pick filter")"
  53. if [ -n "$user_filter" ]; then
  54. category="$user_filter"
  55. fi
  56. ;;
  57. "choose category")
  58. user_category="$(printf "%s\n" "$category_list" | dmenu "$@" -p "(Nyaash) Pick category")"
  59. if [ -n "$user_category" ]; then
  60. category="$user_category"
  61. fi
  62. ;;
  63. "choose instance")
  64. case $(printf "https://nyaa.si\nhttps://sukebei.nyaa.si\ncustom" | dmenu "$@" -p "(Nyaash) instance: ") in
  65. "https://nyaa.si")
  66. instance="https://nyaa.si"
  67. ;;
  68. "https://sukebei.nyaa.si")
  69. instance="https://sukebei.nyaa.si"
  70. ;;
  71. "custom")
  72. custom_instance="$(echo "" | dmenu "$@" -p "(Nyaash) Custom Instance: ")"
  73. if [ -n "$custom_instance"]; then
  74. instance="$custom_instance"
  75. fi
  76. ;;
  77. *)
  78. ;;
  79. esac
  80. ;;
  81. *)
  82. exit 0
  83. ;;
  84. esac
  85. done
  86. query=$(echo "" | dmenu "$@" -p "(Nyaash) Search: ")
  87. new_search=true
  88. while true; do
  89. if $new_search; then
  90. page2="-p $page"
  91. output=$(nyaash "$query" -t $category -f $filter -i "$instance" -p $page)
  92. i=0
  93. itemname=""
  94. names=$(echo "$output" | awk '!((NR+4)%5)' | sed 's/^[0-9]* //')
  95. magnets=$(echo "$output" | awk '!((NR+3)%5)')
  96. lines=$(echo "$names" | wc -l)
  97. else
  98. new_search=true
  99. fi
  100. if [ $lines -gt 0 ]; then
  101. if [ $page -eq 1 ] && [ $lines -eq 75 ]; then
  102. selected="$(printf "main menu\nnext page\n%s\nnext page\nmain menu" "$names" | dmenu "$@" -p "(Nyaash) Download: ")"
  103. elif [ $page -gt 1 ] && [ $lines -eq 75 ]; then
  104. selected="$(printf "main menu\nnext page\nprevious page\n%s\nprevois page\nnext page\nmain menu" "$names" | dmenu "$@" -p "(Nyaash) Download: ")"
  105. elif [ $page -eq 1 ]; then # It's the first page, but has less than 75 items -> also the last page
  106. selected="$(printf "main menu\n%s\nmain menu" "$names" | dmenu "$@" -p "(Nyaash) Download: ")"
  107. else # It's not the first page, but it has less than 75 items -> it's the last page
  108. selected="$(printf "main menu\nprevious page\n%s\nprevous page\n main menu" "$names" | dmenu "$@" -p "(Nyaash) Download: ")"
  109. fi
  110. elif [ $page -gt 1 ]; then
  111. selected="$(printf "main menu\nprevious page\n" | dmenu "$@" -p "(Nyaash) Download: ")"
  112. else
  113. selected="$(printf "no results\nmain menu\n" | dmenu "$@" -p "(Nyaash) Download: ")"
  114. fi
  115. case "$selected" in
  116. "next page")
  117. page=$(( page + 1))
  118. ;;
  119. "previous page")
  120. page=$(( page - 1))
  121. ;;
  122. "main menu")
  123. exitsig=false
  124. break
  125. ;;
  126. "")
  127. break
  128. ;;
  129. *)
  130. selectedline=$(echo "$names" | grep -nF "$selected" | grep -Eo '^[0-9]+')
  131. xdg-open $(printf "%s" "$magnets" | awk "NR==$selectedline") &
  132. choice=$(printf "yes\nno\n" | dmenu "$@" -p "(Nyaash) Select another torrent?" )
  133. if ! echo "$choice" | grep -Eq '[Yy].*'; then
  134. break
  135. else
  136. new_search=false
  137. fi
  138. ;;
  139. esac
  140. done
  141. done