Advertisement
Guest User

wishmaster.sh

a guest
Dec 25th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ############################################################################
  4. #    This program is free software: you can redistribute it and/or modify  #
  5. #    it under the terms of the GNU General Public License as published by  #
  6. #    the Free Software Foundation, either version 3 of the License, or     #
  7. #    (at your option) any later version.                                   #
  8. #                                                                          #
  9. #    This program is distributed in the hope that it will be useful,       #
  10. #    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
  11. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
  12. #    GNU General Public License for more details.                          #
  13. #                                                                          #
  14. #    You should have received a copy of the GNU General Public License     #
  15. #    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
  16. #                                                                          #
  17. ############################################################################
  18. help() {
  19.     cat <<EOF
  20. Usage: $0 [options] thread_url [destination_directory]
  21. Options:
  22. -i          download images only
  23. -c          re-check page and get files until error
  24. -s interval sleep interval between page checks (default 20s; see man sleep)
  25. -n          don't notify on page changes
  26. -N          don't download anything; implies -c
  27. -p          save additional page files (thumbs, css, etc.)
  28. default destination directory - thread number
  29. EOF
  30. }
  31. # [r]ecursive, [c]ontinue, recursion [l]evel, N - check by timestamp only,
  32. # nd - no directories
  33. wgetopts="-e robots=off -r -l1 -N -nd -H --no-check-certificate --convert-links --no-verbose"
  34. s=20s; c=""; dl=1; page=""
  35. [ "$DISPLAY" ] && [ "$(which notify-send)" ] && notify=1
  36. while getopts "ics:nNp" o; do
  37.     case "$o" in
  38.         i)  wgetopts+=" -A png,gif,jpg" ;;
  39.         c)  c=1 ;;
  40.         s)  s="$OPTARG" ;;
  41.         n)  notify="" ;;
  42.         N)  dl=""; c=1 ;;
  43.         p)  page=1 ;;
  44.         *)  help
  45.             exit 1 ;;
  46.     esac
  47. done
  48. shift $((OPTIND - 1))
  49. [ -z "${dl}${notify}" ] && echo "$0: nothing to do">&2 && exit 1
  50. [ -z "$1" ] && help && exit 1
  51. [ "$3" ] && help && exit 1
  52. domain=${1#*://}; domain=${domain#www.}; domain=${domain%%/*}
  53. b="$(expr "$1" : ".*/\([^/]\+\)/res")"
  54. t="$(expr "$1" : ".*/res/\([0-9]\+\).html")"
  55. if [ "$dl" ]; then
  56.    [ "$2" ] && destdir="$2" || destdir="$t"
  57.    [ -d "$destdir" ] || mkdir -p "$destdir"
  58.    cd "$destdir" || exit 1
  59. fi
  60. case "$domain" in
  61.    2-ch.ru) [ "$page" ] && idirs="/$b/thumb,/$b/res,/$b/src,/css,/js,/math,/icons,/plugins" \
  62.                         || idirs="/$b/src" ;;
  63.    *)  [ "$page" ] && idirs="/$b/thumb,/$b/res,/$b/src,/css,/js" \
  64.                    || idirs="/$b/src" ;;
  65. esac
  66.  
  67. getFiles() {
  68.    lm_=$(wget --no-check-certificate --spider "$1" -S 2>&1 | grep Last-Modified)
  69.    [ "$lm_" ] || exit 1
  70.    [ "$lm" == "$lm_" ] && return
  71.    [ "$notify" ] && [ "$lm" ] && notify-send "$1: new posts"
  72.    lm="$lm_"
  73.    [ -z "$dl" ] && return
  74.    wget "$1" --include-directories="$idirs" $wgetopts
  75. }
  76.  
  77. while getFiles "$1" && [ "$c" ]; do
  78.    sleep "$s"
  79. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement