Advertisement
Guest User

/u/BASH_SCRIPTS_FOR_YOU e621v3 downloader

a guest
Jul 15th, 2015
1,351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. #!/bin/bash
  2. #https://e621.net/
  3. #by: /u/BASH_SCRIPTS_FOR_YOU
  4. #GPLv3 or later
  5. SITE="https://e621.net/post/index/"
  6. one=${1}
  7. two=${2}
  8. three=${3}
  9. four=${4}
  10. five=${5}
  11.  
  12. if [ -z "${one}" ]
  13. then one=0
  14. fi
  15.  
  16. if [ "${one}" == 2 ]
  17. then two=0
  18. three=0
  19. four=0
  20. five=0
  21. fi
  22.  
  23. if [ -z "${two}" ]
  24. then two=0
  25. fi
  26.  
  27.  
  28. if [ -z "${three}" ]
  29. then three=0
  30. fi
  31.  
  32. if [ -z "${four}" ]
  33. then four=0
  34. fi
  35.  
  36. if [ -z "${five}" ]
  37. then five=0
  38. fi
  39.  
  40.  
  41. if [ "${one}" == 0 ] && [ "${two}" == 0 ] && [ "${three}" == 0 ] && [ "${four}" == 0 ] && [ "${five}" == 0 ]
  42. then echo "You have not enter any arguments for this script"
  43. echo "there are 5 arguments, like so: ./script.sh 1 1 1 1 1"
  44. echo "the arguments are either 1 or 0, 1 is to do the action, 0 is to not"
  45. echo "except the first argument, it has the option of 2, more on that later"
  46. echo "first argument runs the site downloader. It'll output a database of info"
  47. echo "every argument give you a blank line to enter tags, seperated by spaces"
  48. echo "Put a negative infront of a tag to exclude"
  49. echo "second argument creates a list of links from the database, this is useful for downloaders."
  50. echo "for example, wget, to download them, like so"
  51. echo "~\$wget -i filename.txt"
  52. echo "third argument creates a list of tags from the database"
  53. echo "forth argument creates a list of artists from the database"
  54. echo "fifth argument downloads the lists of links from the second argument"
  55. echo "first argument also has the option of 2, which lists the amount of pages, content, and popular tags"
  56. echo "if 2 is used on the first argument, all other arguments will ignored, set to 0"
  57. echo "if an argument is not given a value it gets turned into 0"
  58. echo "by running this script with no arguments, it was assume to be 0 0 0 0 0"
  59. echo "which displays this message"
  60. echo "any combination except 0 0 0 0 0 will give you a blank line for tags, so it can find the right database file"
  61. echo "a line in any list refernces the same line in other lists"
  62. echo "EG: line 3 in links, Artists, Tags, and Database all refer to the same image"
  63. echo "this script uses cat, awk, curl, sed, grep, printf, and echo, incase you don't have them installed"
  64. echo "happy yiffing"
  65. else read TAGS
  66. fi
  67.  
  68.  
  69. if [ "${one}" == 2 ]
  70. then PAGE=0
  71. PAGES=`curl --retry 8 -s -g "${SITE}1/${TAGS}" | sed '35!d' | tr '/' '\n' | grep ^[1-9]`
  72. if [ -z "${PAGES}" ]
  73. then PAGES=1
  74. fi
  75. printf ""${PAGES}" pages. "
  76. lastpagecontent=`curl --retry 8 -s -g "${SITE}${PAGES}/${TAGS}" | grep -c 'Post.register({"sample_url":'`
  77. content=$(((((( ${PAGES} - 1 )) * 75 )) + ${lastpagecontent} ))
  78. printf ""${content}" media\n"
  79. curl -s -g "${SITE}${PAGES}/${TAGS}" | grep '^<li class="' | sed 's/&ndash;/\n/g' | sed '1d' | tr '<' '>' | awk -F'>' '{ print $5 "\t" $9 }'
  80. fi
  81.  
  82.  
  83. if [ "${one}" == 1 ] && [ -f "DB:${TAGS}.txt" ]
  84. then printf "\n"DB:${TAGS}.txt" already exists\n"
  85. fi
  86.  
  87. if [ "${one}" == 1 ] && [ ! -f "DB:${TAGS}.txt" ]
  88. then PAGE=0
  89. PAGES=`curl --retry 8 -s -g "${SITE}1/${TAGS}" | sed '35!d' | tr '/' '\n' | grep ^[1-9]`
  90. if [ -z "${PAGES}" ]
  91. then PAGES=1
  92. fi
  93. printf "${PAGES} pages. "
  94. lastpagecontent=`curl --retry 8 -s -g "${SITE}${PAGES}/${TAGS}" | grep -c 'Post.register({"sample_url":'`
  95. content=$(((((( ${PAGES} - 1 )) * 75 )) + ${lastpagecontent} ))
  96. printf ""${content}" media. Page"
  97. while [ "${PAGE}" != "${PAGES}" ]
  98. do PAGE=$(( ${PAGE} + 1 ))
  99. printf ",${PAGE}"
  100. curl -s -g "${SITE}${PAGE}/${TAGS}" | grep 'Post.register({"sample_url":' >>"DB:${TAGS}.txt"
  101. done
  102. fi
  103.  
  104. if [ "${two}" == 1 ] && [ -f "DB:${TAGS}.txt" ]
  105. then sed 's/.*"file_url":"//g' "DB:${TAGS}.txt" | sed 's/....$//g' >> "Links:${TAGS}.txt"
  106. fi
  107.  
  108. if [ "${two}" == 1 ] && [ ! -f "DB:${TAGS}.txt" ]
  109. then printf ""DB:${TAGS}.txt" does not exist\n"
  110. fi
  111.  
  112.  
  113. if [ "${three}" == 1 ] && [ -f "DB:${TAGS}.txt" ]
  114. then awk -F'"' '{ print $10 }' "DB:${TAGS}.txt" >> "Tags:${TAGS}.txt"
  115. fi
  116.  
  117. if [ "${three}" == 1 ] && [ ! -f "DB:${TAGS}.txt" ]
  118. then printf ""DB:${TAGS}.txt" does not exist\n"
  119. fi
  120.  
  121.  
  122. if [ "${four}" == 1 ] && [ -f "DB:${TAGS}.txt" ]
  123. then sed "s/.*"artist":\[//g" "DB:${TAGS}.txt" | sed 's/\],"has_notes":.*//g' | sed 's/"//g' | sed "s/,/ /g" >> "Artists:${TAGS}.txt"
  124. fi
  125.  
  126. if [ "${four}" == 1 ] && [ ! -f "DB:${TAGS}.txt" ]
  127. then printf ""DB:${TAGS}.txt" does not exist\n"
  128. fi
  129.  
  130.  
  131. if [ "${five}" == 1 ] && [ -f "Links:${TAGS}.txt" ]
  132. then lines=0
  133. linenumber=`cat "Links:${TAGS}.txt" | wc -l`
  134. while [ "${lines}" != "${linenumber}" ]
  135. do lines=$(( ${lines} + 1 ))
  136. printf ""${lines}" of "${linenumber}"\n"
  137. sed -n "${lines}{p;q;}" "Links:${TAGS}.txt" | xargs curl -g -# -O
  138. done
  139. fi
  140.  
  141. if [ "${five}" == 1 ] && [ ! -f "Links:${TAGS}.txt" ]
  142. then
  143. printf ""Links:${TAGS}.txt" does not exist\n"
  144. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement