dsuveges

4chan image/webm downloader

Sep 3rd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.95 KB | None | 0 0
  1. function dl {
  2.     fold=$(echo "${1}" | perl -lane '($fold) = $_ =~ /thread\/(\d+)/; print $fold' | head -n1)
  3.     mkdir -p "${fold}"
  4.     echo -n "Downloading.."
  5.     curl -s  "${1}" | perl -lane \
  6.         'BEGIN {
  7.            sub dl {
  8.                my $str = shift;
  9.                (my $URL) = $str =~ /href=\"\/\/(.+?)\"/;
  10.                (my $title) = $str =~ /\<a title\=/ ? $str =~ /title=\"(.+?)\"/ : $str =~ /target=\"_blank\">(.+?)\<\/a\>/;
  11.                $title =~ s/\s+/_/g;
  12.                print "$URL $title";
  13.            }
  14.        }{
  15.            (my @a) = $_ =~ /div class=\"fileText\"(.+?)<\/div>/g;
  16.            foreach $a (@a){
  17.                &dl($a)
  18.            }
  19.        }' | while read URL title; do
  20.             if [[ ! -e "${fold}/${title}" ]]; then
  21.                 curl -s  "${URL}" > "${fold}/${title}"
  22.                 echo -n "."
  23.             fi
  24.     done
  25.     echo
  26. }
  27.  
  28. ### Usage:
  29. # dl http://boards.4chan.org/b/thread/########
Add Comment
Please, Sign In to add comment