dmenu_nyaa.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. filter_list="none
  3. noremakes
  4. trusted"
  5. category_list="all
  6. anime
  7. anime_mv
  8. anime_englis
  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. select=""
  43. while true; do
  44. case $(printf "search\nchoose filter\nchoose category\nchoose instance\n" | dmenu "$@" -p "Nyaash: ") in
  45. "search")
  46. break
  47. ;;
  48. "choose filter")
  49. user_filter="$(printf "%s\n" "$filter_list" | dmenu "$@" -p "(Nyaash) Pick category")"
  50. if [ -n "$user_filter" ]; then
  51. category="$user_filter"
  52. fi
  53. ;;
  54. "choose category")
  55. user_category="$(printf "%s\n" "$category_list" | dmenu "$@" -p "(Nyaash) Pick category")"
  56. if [ -n "$user_category" ]; then
  57. category="$user_category"
  58. fi
  59. ;;
  60. "choose instance")
  61. case $(printf "https://nyaa.si\nhttps://sukebei.nyaa.si\ncustom" | dmenu "$@" -p "(Nyaash) instance: ") in
  62. "https://nyaa.si")
  63. instance="https://nyaa.si"
  64. ;;
  65. "https://sukebei.nyaa.si")
  66. instance="https://sukebei.nyaa.si"
  67. ;;
  68. "custom")
  69. custom_instance="$(echo "" | dmenu "$@" -p "(Nyaash) Custom Instance: ")"
  70. if [ -n "$custom_instance"]; then
  71. instance="$custom_instance"
  72. fi
  73. ;;
  74. *)
  75. ;;
  76. esac
  77. ;;
  78. *)
  79. exit 0
  80. ;;
  81. esac
  82. done
  83. query=$(echo "" | dmenu "$@" -p "(Nyaash) Search: ")
  84. declare -A items
  85. while true; do
  86. page2="-p $page"
  87. output=$(nyaash "$query" -t $category -f $filter -i "$instance" -p $page)
  88. i=0
  89. itemname=""
  90. unset index
  91. unset lines
  92. readarray lines = < <(echo "$output")
  93. if [ ${#lines[@]} -gt 4 ]; then
  94. for line in ${!lines[@]}; do
  95. case $(expr $line % 5) in
  96. 0)
  97. itemname="$(printf '%s\n' "${lines[$line]}" | sed 's/^[0-9]* //')"
  98. items["$itemname"]=""
  99. index[$i]="$itemname"
  100. i=$(($i+1))
  101. ;;
  102. 1)
  103. items["$itemname"]="${lines[$line]}"
  104. ;;
  105. esac
  106. done
  107. fi
  108. if [ "${#index[@]}" -gt 0 ]; then
  109. if [ $page -eq 1 ] && [ ${#index[@]} -eq 75 ]; then
  110. selected="$(echo -e "next page\n$(printf "%s\n" "${index[@]})\nnext page")" | dmenu "$@" -p "(Nyaash) Download: ")"
  111. elif [ $page -gt 1 ] && [ ${#index[@]} -eq 75 ]; then
  112. selected="$(echo -e "next page\nprevious page\n$(printf "%s\n" "${index[@]})\nprevois page\nnext page")" | dmenu "$@" -p "(Nyaash) Download: ")"
  113. elif [ $page -eq 1 ]; then # It's the first page, but has less than 75 items -> also the last page
  114. selected="$(echo -e "$(printf "%s\n" "${index[@]})")" | dmenu "$@" -p "(Nyaash) Download: ")"
  115. else # It's not the first page, but it has less than 75 items -> it's the last page
  116. selected="$(echo -e "previous page\n$(printf "%s\n" "${index[@]})")\nprevous page" | dmenu "$@" -p "(Nyaash) Download: ")"
  117. fi
  118. elif [ $page -gt 1 ]; then
  119. selected="$(printf "previous page\n" | dmenu "$@" -p "(Nyaash) Download: ")"
  120. else
  121. selected="$(printf "no results\n" | dmenu "$@" -p "(Nyaash) Download: ")"
  122. fi
  123. case "$selected" in
  124. "next page")
  125. page=$(( page + 1))
  126. ;;
  127. "previous page")
  128. page=$(( page - 1))
  129. ;;
  130. *)
  131. break
  132. ;;
  133. esac
  134. done
  135. xdg-open "${items["$selected"]}"