dmenu_nyaa.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. index=()
  86. while true; do
  87. page2="-p $page"
  88. output=$(nyaash "$query" -t $category -f $filter -i "$instance" -p $page)
  89. i=0
  90. itemname=""
  91. unset lines
  92. readarray lines = < <(echo "$output")
  93. for line in ${!lines[@]}; do
  94. case $(expr $line % 5) in
  95. 0)
  96. itemname="$(printf '%s\n' "${lines[$line]}" | sed 's/^[0-9]* //')"
  97. items["$itemname"]=""
  98. index[$i]="$itemname"
  99. i=$(($i+1))
  100. ;;
  101. 1)
  102. items["$itemname"]="${lines[$line]}"
  103. ;;
  104. esac
  105. done
  106. if [ $page -eq 1 ]; then
  107. selected="$(echo -e "next page\n$(printf "%s\n" "${index[@]})")" | dmenu "$@" -p "(Nyaash) Download: ")"
  108. else
  109. selected="$(echo -e "next page\nprevious page\n$(printf "%s\n" "${index[@]})")" | dmenu "$@" -p "(Nyaash) Download: ")"
  110. fi
  111. case "$selected" in
  112. "next page")
  113. page=$(( page + 1))
  114. ;;
  115. "previous page")
  116. page=$(( page - 1))
  117. ;;
  118. *)
  119. break
  120. ;;
  121. esac
  122. done
  123. xdg-open "${items["$selected"]}"