Guest User

Untitled

a guest
Jan 8th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. SAVEDIR='/home/anon/stuff/2ch'
  4.  
  5. [[ $1 =~ (.+)/([a-z0-9]+)/res/([0-9]+) ]]
  6.  
  7. if [ $? != 0 ]
  8. then
  9.     echo "wrong args"
  10.     exit 1
  11. fi
  12.  
  13. domain=${BASH_REMATCH[1]}
  14. board=${BASH_REMATCH[2]}
  15. num=${BASH_REMATCH[3]}
  16.  
  17. url="$domain/makaba/mobile.fcgi?task=get_thread&board=$board&thread=$num&num=$num"
  18.  
  19. mkdir -p "$SAVEDIR/$board/$num"
  20. cd "$SAVEDIR/$board/$num"
  21. if [ $? != 0 ]
  22. then
  23.     echo "cd fail"
  24.     exit 1
  25. fi
  26.  
  27. wget -O thread.json.new "$url"
  28. if [ $? != 0 ]
  29. then
  30.     echo "wget fail"
  31.     exit 1
  32. fi
  33.  
  34. jq -r -e '.[] | .files[]?.path' thread.json.new > urls.txt
  35. if [ $? != 0 ]
  36. then
  37.     echo "jq fail, thread doesn't exists?"
  38.     exit 1
  39. fi
  40.  
  41. mv thread.json.new thread.json
  42.  
  43. wget --no-clobber --base="$domain/$board/" --input urls.txt
  44. if [ $? != 0 ]
  45. then
  46.     echo "wget fail"
  47.     exit 1
  48. fi
  49.  
  50. exit 0
Advertisement
Add Comment
Please, Sign In to add comment