Advertisement
someone_

threaddl

Dec 22nd, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.95 KB | None | 0 0
  1. #!/system/bin/sh
  2.  
  3. name=`basename $0`
  4.  
  5. usage () {
  6.     echo "$name - 4chan thread downloader"
  7.     echo ""
  8.     echo "Usage: $name [4chan thread URL] <time value and/or return target>"
  9.     echo ""
  10.     echo "  <time value>"
  11.     echo "     1: run script once"
  12.     echo "     Between 9 and 1000: Set the initial"
  13.     echo "      waiting time between runs"
  14.     echo "     Default: 10 seconds"
  15.     echo ""
  16.     echo "  <return target>"
  17.     echo "     Set the target path of the 'Return'"
  18.     echo "      link"
  19.     echo "     Default: ./"
  20.     exit 0
  21. }
  22.  
  23. [ $# -eq 0 ] && usage
  24.  
  25. for arg in $@; do
  26.     urltest=$(echo "$arg" | sed -e "s_^https_http_" | egrep -o "^http://boards.4chan.org/[a-z0-9]+/res/[0-9]+")
  27.     timetest=$(echo "$arg" |egrep "^[0-9]{1,3}$")
  28.     if [ $urltest ]; then
  29.         URL="$urltest"
  30.     elif [ $timetest ]; then
  31.         SLP="$arg"
  32.     else
  33.         RET="$arg"
  34.     fi
  35. done
  36.  
  37. [ ! $URL ] && usage
  38.  
  39. echo "4chan downloader"
  40.  
  41. LOC=$(echo "$URL" | sed 's_.*/\([^/]\+\)/res/\(.\+\)_\1\_\2_')
  42.  
  43. if [ ! $LOC ]; then
  44.     echo "Can't determine the thread's number"
  45.     echo "Use valid URL without hash or search tags"
  46.     echo ""
  47.     usage
  48. fi
  49.  
  50. ST="static.4chan.org"
  51.  
  52. [ ! $SLP ] && SLP="10"
  53. [ ! $RET ] && RET="./"
  54.  
  55. if [ -s /system/build.prop ]; then
  56.     for path in $(echo "$PATH" | sed "s_:_\n_g"); do
  57.         if [ -s ${path}/busybox ]; then
  58.             alias echo="${path}/busybox echo -ne"
  59.             alias read="${path}/busybox sh read -n 1 Q"
  60.             alias sed="${path}/busybox sed"
  61.             break
  62.         fi
  63.     done
  64. else
  65.     alias echo="echo -ne"
  66. fi
  67.  
  68. SLAP=$SLP
  69.  
  70. NO=$(echo "$LOC" | grep -o '[0-9]\+$')
  71. N="\n"
  72. R="\r"
  73. LM=""
  74.  
  75. thejob () {
  76.     if [ ! -d $LOC ]; then
  77.         mkdir $LOC
  78.     fi
  79.  
  80.     if [ ! -d $LOC/misc ]; then
  81.         mkdir $LOC/misc
  82.     fi
  83.  
  84.     egrep "//.\.thumbs\.4chan\.org/[a-z0-9]+/thumb/[0-9]*s\.jpg" $LOC.html -o | sed 's_^//_http://_g' > $LOC/misc/misc
  85.  
  86.     egrep "//${ST}/image/(spoiler[^\x2E]*\.png|filedeleted-res\.gif|favicon[^\x2E]*\.ico|[a-z]*icon\.gif)" $LOC.html -o | sed 's_^//_http://_g' >> $LOC/misc/misc
  87.  
  88.     egrep "//${ST}/image/country/[a-z]*/?[\w]+\...." $LOC.html -o | sed 's_^//_http://_g' >> $LOC/misc/misc
  89.  
  90.     egrep "//${ST}/css/[a-z]+\.[0-9]+\.css" $LOC.html -o | sed -e 's_^//_http:&_' | head -n1 > $LOC/misc/css
  91.  
  92.     egrep "//${ST}/css/[a-z]+\.[0-9]+\.css" $LOC.html -o | sed -e 's_^//_http:&_' | egrep 'tomorrow|prettify' >> $LOC/misc/css
  93.  
  94.     egrep "//${ST}/image/title/[a-z]+/[0-9a-z]+\.(jpg|png|gif)" $LOC.html -o | sed 's_^//_http://_g' > $LOC/misc/logo
  95.  
  96.     egrep "//images\.4chan\.org/[a-z0-9]+/src/[0-9]*\.(jpg|png|gif)" $LOC.html -o | sed 's_^//_http://_g' > $LOC/images
  97.  
  98.     egrep "^(<!DOCTYPE|<link rel|</head>)" $LOC.html > a
  99.  
  100.     head -n2 a > $LOC.html
  101.  
  102.     cat << EOF >> $LOC.html
  103. <!<script>/*<![CDATA[*/var d=document,dE=d.documentElement,lS=localStorage,z,i,u="threaddl_arch_theme",e;Element.prototype.gA=function(a){return this.getAttribute(a);};Element.prototype.pN=function(){return this.parentNode;};String.prototype.iO=function(a){return this.indexOf(a);};function s(a,b,c){a.setAttribute(b,c);}function sT(b){lS.setItem(u,b);for(i=0;(z=d.getElementsByTagName("link")[i]);i++){if(z.gA("rel").iO("style")!=1&&z.gA("title")){z.disabled=true;if(z.gA("title")==(b?"switch":"Tomorrow"))z.disabled=false;}}}sT(parseInt(lS.getItem(u))||0);(function(){var a,b,c,e,f,g,h,i,j,k,l=parseInt(lS.qp_opt),m,n=parseInt(lS.img_hover),o;k={hover:function(a){var b,c,d,e,f,g,h;d=a.clientX,e=a.clientY;g=k.el.style;b=dE.clientHeight,c=dE.clientWidth;f=k.el.offsetHeight;h=e-120;g.top=b<=f||h<=0?"0px":h+f>=b?b-f+"px":h+"px";if(d<=c-400){g.left=d+45+"px";return g.right=null}else{g.left=null;return g.right=c-d+45+"px"}},hoverend:function(){a.rm(k.el);return delete k.el}};a=function(a,b){if(b==null){b=d.body}return b.querySelector(a)};a.extend=function(a,b){var c;for(c in b){a[c]=b[c]}};a.extend(a,{id:function(a){return d.getElementById(a)},addStyle:function(b){var c;c=a.el("style",{textContent:b});a.add(d.head,c);return c},x:function(a,b){b===null&&(b=d.body);return d.evaluate(a,b,null,8,null).singleNodeValue},addClass:function(a,b){return a.classList.add(b)},rmClass:function(a,b){return a.classList.remove(b)},rm:function(a){return a.pN().removeChild(a)},tn:function(a){return d.createTextNode(a)},nodes:function(a){var b,c,e=0;if(!(a instanceof Array)){return a}b=d.createDocumentFragment();for(;e<a.length;e++){c=a[e];b.appendChild(c)}return b},add:function(b,c){return b.appendChild(a.nodes(c))},after:function(b,c){return b.pN().insertBefore(a.nodes(c),b.nextSibling)},el:function(b,c){var e=d.createElement(b);if(c){a.extend(e,c)}return e},on:function(a,b,c){var d,e=0,f=b.split(" ");for(;e<f.length;e++){d=f[e];a.addEventListener(d,c,false)}},off:function(a,b,c){var d,e=0,f=b.split(" ");for(;e<f.length;e++){d=f[e];a.removeEventListener(d,c,false)}}});b=function(a,b){if(b==null){b=d.body}return [].slice.call(b.querySelectorAll(a))};c={post:function(b,d){var e=a.id("pc"+b);e&&a.add(d,c.cleanPost(e.cloneNode(true)))},cleanPost:function(c){var d,e,f,g,h,i=Date.now(),j=a(".post",c),k=_j=_k=_l=0,l=[].slice.call(c.childNodes),m=b(".inline",j),n=b(".inlined",j);for(;k<l.length;k++){if((d=l[k])!==j){a.rm(d)}}for(;_j<m.length;_j++){a.rm(m[_j])}for(;_k<n.length;_k++){a.rmClass(n[_k],"inlined")}(f=b("[id]",c)).push(c);for(;_l<f.length;_l++){(e=f[_l]).id=""+i+"_"+e.id}a.rmClass(c,"forwarded");a.rmClass(c,"qphl");a.rmClass(j,"highlight");a.rmClass(j,"qphl");return c}};j={init:function(){return e.callbacks.push(this.node)},node:function(b){var c=a(".postInfo > .dateTime",b.el);if(b.isInlined){return}j.date=new Date(c.dataset.utc*1e3);c.title="4chan time: "+c.textContent;return c.textContent=j.zeroPad(j.date.getMonth()+1)+"/"+j.zeroPad(j.date.getDate())+"/"+(j.date.getFullYear()-2e3)+"("+j.day[j.date.getDay()]+")"+j.zeroPad(j.date.getHours())+":"+j.zeroPad(j.date.getMinutes())},day:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],zeroPad:function(a){if(10>a){return"0"+a}else{return a}}};g={init:function(){return e.callbacks.push(this.node)},node:function(b){var c,d,e,f,g,j,k={},n=0,m=b.quotes;if(b.isInlined){return}for(;m.length>n;n++){j=m[n];if(g=j.hash.slice(2)){k[g]=true}}c=a.el("a",{href:"#p"+b.ID,className:"backlink",textContent:">>"+b.ID});for(g in k){if(!(e=a.id("pi"+g))||/\bop\b/.test(e.pN().className)){continue}f=c.cloneNode(true);l&&a.on(f,"mouseover",i.mouseover);a.on(f,"click",h.toggle);if(!(d=a.id("blc"+g))){d=a.el("span",{className:"container",id:"blc"+g});a.add(e,d)}a.add(d,[a.tn(" "),f])}}};h={init:function(){return e.callbacks.push(this.node)},node:function(b){var c,d=_j=0,e=b.quotes,f=b.backlinks;for(;e.length>d;d++){c=e[d];if(!c.hash){continue}c.removeAttribute("onclick");a.on(c,"click",h.toggle)}for(;f.length>_j;_j++){a.on(f[_j],"click",h.toggle)}},toggle:function(b){if(b.shiftKey||b.altKey||b.ctrlKey||b.metaKey||b.button!==0){return}b.preventDefault();var c=this.dataset.id||this.hash.slice(2);if(/\binlined\b/.test(this.className)){h.rm(this,c)}else{if(a.x("ancestor::div[contains(@id,'p"+c+"')]",this)){return}h.add(this,c)}return this.classList.toggle("inlined")},add:function(b,d){var e=d,f=a.id("p"+e),g=a.el("div",{id:"i"+e,className:"inline"}),h=/\bbacklink\b/.test(b.className),i=h?b.pN():a.x("ancestor-or-self::*[parent::blockquote][1]",b);a.after(i,g);c.post(e,g);if(!f){return}if(h){a.addClass(f.pN(),"forwarded");++f.dataset.forwarded||(f.dataset.forwarded=1)}},rm:function(c,d){var e,f,g,h,i;e=a.x("following::div[@id='i"+d+"']",c);a.rm(e);i=b(".backlink.inlined",e);for(g=0,h=i.length;h>g;g++){f=i[g];e=a.id(f.hash.slice(1));if(!--e.dataset.forwarded){a.rmClass(e.pN(),"forwarded")}}if(/\bbacklink\b/.test(c.className)){e=a.id("p"+d);if(!--e.dataset.forwarded){return a.rmClass(e.pN(),"forwarded")}}}};i={init:function(){return e.callbacks.push(this.node)},node:function(b){var c,d=_j=0,e=b.quotes,f=b.backlinks;for(;e.length>d;d++){c=e[d];if(c.hash||/\bdeadlink\b/.test(c.className)){a.on(c,"mouseover",i.mouseover)}}for(;f.length>_j;_j++){a.on(f[_j],"mouseover",i.mouseover)}},mouseover:function(e){var f,g=this.hash.slice(2),h,j,l,m=0,n;if(/\binlined\b/.test(this.className)){return}if(h=a.id("qp")){if(h===k.el){delete k.el}a.rm(h)}if(k.el){return}h=k.el=a.el("div",{id:"qp",className:"reply dialog"});k.hover(e);a.add(d.body,h);f=a.id("p"+g);c.post(g,h);a.on(this,"mousemove",k.hover);a.on(this,"mouseout click",i.mouseout);if(!f){return}if(/\bop\b/.test(f.className)){a.addClass(f.pN(),"qphl")}else{a.addClass(f,"qphl")}l=a.x("ancestor::*[@id][1]",this).id.match(/\d+$/)[0];n=b(".quotelink, .backlink",h);for(;n.length>m;m++){j=n[m];if(j.hash.slice(2)===l){a.addClass(j,"forwardlink")}}},mouseout:function(b){var c;k.hoverend();if(c=a.id(this.hash.slice(1))){a.rmClass(c,"qphl");a.rmClass(c.pN(),"qphl")}a.off(this,"mousemove",k.hover);return a.off(this,"mouseout click",i.mouseout)}};m={init:function(){return e.callbacks.push(this.node)},node:function(b){if(!b.img){return}return a.on(b.img,"mouseover",m.mouseover)},mouseover:function(){var b;if(b=a.id("ihover")){if(b===k.el){delete k.el}a.rm(b)}if(k.el){return}b=k.el=a.el("img",{id:"ihover",src:this.pN().href});a.add(d.body,b);a.on(b,"load",m.load);a.on(this,"mousemove",k.hover);return a.on(this,"mouseout",m.mouseout)},load:function(){var a;if(!this.pN()){return}a=this.style;return k.hover({clientX:-45+parseInt(a.left),clientY:120+parseInt(a.top)})},mouseout:function(){k.hoverend();a.off(this,"mousemove",k.hover);return a.off(this,"mouseout",m.mouseout)}};o={init:function(){return e.callbacks.push(this.node)},node:function(b){if(!b.img){return}return a.on(b.img.pN(),'click',o.cb.toggle)},cb:{toggle:function(e){if(e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||e.button!==0){return}e.preventDefault();return o.toggle(this)}},toggle:function(b){var c,e=b.firstChild;if(e.hidden){c=b.getBoundingClientRect();if(d.body.gA("class")!=='i'){if(c.top<0){d.body.scrollTop+=c.top-42}if(c.left<0){d.body.scrollLeft+=c.left}}else{if(c.top<0){dE.scrollTop+=c.top-42}if(c.left<0){dE.scrollLeft+=c.left}}return o.contract(e)}else{return o.expand(e)}},contract:function(b){b.hidden=false;return b.nextSibling.hidden=true},expand:function(b){var c,d;if(a.x('ancestor-or-self::*[@hidden]',b)){return}b.hidden=true;if(d=b.nextSibling){d.hidden=false;return}c=b.pN();d=a.el('img',{src:c.href,alt:b.alt});return a.add(c,d)}};e={init:function(){(function(){var c=b('a.fileThumb'),i=0;/WebKit/.test(navigator.userAgent)||s(d.body,'class','i');for(;c.length>i;i++){var n=a.nodes([a.tn(' '),a.el('a',{textContent:'google',href:'http://www.google.com/searchbyimage?image_url='+c[i].href,target:'_blank'})]);-1!==location.protocol.iO('http')&&c[i].previousElementSibling.appendChild(n)}for(c=b('span.abbr a'),i=0;c.length>i;i++){s(c[i],'onclick','javascript:e=this.pN().pN().lastChild.style;e.display=e.display=="block"?"none":"block"')}}());a.add(a("div.navLinks"),[a.tn(" ["),a.el("a",{href:"javascript:;",textContent:"QuotePreview is "+(l?"ON":"OFF"),onclick:function(){lS.qp_opt=l?0:1;window.location.reload()}}),a.tn("] ["),a.el("a",{href:"javascript:;",textContent:"ImageHover is "+(n?"ON":"OFF"),onclick:function(){lS.img_hover=n?0:1;window.location.reload()}}),a.tn("]")]);j.init();h.init();l&&i.init();n&&m.init();o.init();g.init();e.ready()},ready:function(){var c=[],d=0,f=b(".postContainer",a.id("delform"));for(;f.length>d;d++){c.push(e.preParse(f[d]))}e.node(c);if(MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.OMutationObserver){observer=new MutationObserver(e.observer);observer.observe(a(".board"),{childList:true,subtree:true})}else{a.on(a(".board"),"DOMNodeInserted",e.listener)}},preParse:function(c){var d=a(".post",c),e=c.pN().className,f={root:c,el:d,"class":d.className,ID:d.id.match(/\d+$/)[0],threadID:a.x("ancestor::div[parent::div[@class='board']]",c).id.match(/\d+$/)[0],isInlined:/\binline\b/.test(e),blockquote:d.lastElementChild,quotes:b("a.quotelink[href^='#p']",d),backlinks:d.getElementsByClassName("backlink"),img:false},g;if(g=a('img[data-md5]',d)){f.img=g}return f},node:function(a){for(var b=0,c=e.callbacks;c.length>b;b++){var d=c[b];try{for(var f=0;a.length>f;f++){d(a[f])}}catch(g){alert("Error: "+g.message+"\nReport the bug to HandyAnon@Steam\n\nURL: "+window.location+"\n"+g.stack)}}},observer:function(a){var b,c,d,f,g,h,i,j;d=[];for(f=0,h=a.length;h>f;f++){c=a[f];j=c.addedNodes;for(g=0,i=j.length;i>g;g++){b=j[g];if(/\bpostContainer\b/.test(b.className)){d.push(e.preParse(b))}}}if(d.length){return e.node(d)}},listener:function(a){var b;b=a.target;if(/\bpostContainer\b/.test(b.className)){return e.node([e.preParse(b)])}},callbacks:[]};a.on(d,"DOMContentLoaded",e.init)}).call(this);//]]></script><style>/*<![CDATA[*/img[data-md5]+img{max-width:100%!important;}.i img[data-md5]+img{width:100%!important;}.op:after{clear:both;content:'';display:block;}#qp{padding:2px 2px 5px;position:fixed;border:1px solid rgba(128,128,128,0.5);}#qp .post{border:none;margin:0;padding:0;}#qp img{max-height:300px;max-width:500px;}.qphl{outline:2px solid rgba(216,94,49,.7);}.inlined{opacity:.5;}.inline{border:1px solid rgba(128,128,128,0.5);display:table;margin:2px;padding:2px;}.inline .post{background:none;border:none;margin:0;padding:0;}.forwarded{display:none;}.quotelink.forwardlink,.backlink.forwardlink{text-decoration:none;border-bottom:1px dashed;}#ihover{max-height:97%;max-width:75%;padding-bottom:18px;position:fixed;} blockquote{word-wrap:break-word;min-width:120px;}/*]]>*/</style>
  104. EOF
  105.  
  106.     tail -n1 a >> $LOC.html
  107.  
  108.     rm a
  109.  
  110.     sed -i -e '1 s/<script.*$/!>/' -e '2 {s_<script_!>\n&_
  111.         s_<link [^>]*RSS feed[^>]*>__
  112.         s@//'$ST'/image/\(favicon[^\x2E]*\.ico\)@'$LOC'/misc/\1@
  113.         s_<link rel="alternate style[^-]*\(<link[^>]*tomorrow\.[^>]*>\)[^-]*<_\1<_
  114.         s@//'$ST'/css/\([a-z0-9\.]\{1,75\}\.css\)@'$LOC'/misc/\1@g
  115.         s/^/<!/}' -e '$ {s_</head>_<!&_
  116.         s_<div id="boardNavDesktop" class="desktop">_\n_
  117.         s_<div class="boardBanner"_\n<!&_
  118.         s_<hr class="above_\n_
  119.         s_ .<a[^>]*>Catalog</a>.__g
  120.         s_\(<div class="navLinks desktop">.<a href="\.\./\./[^#]*\)#bottom\(">Bottom</a>.\)_\n<!\1javascript:dE.scrollIntoView(false)\2</div><hr>\n_
  121.         s_\(<form name="delform" id="delform"\)[^>]*_\n<!\1_
  122.         s@//.\.thumbs\.4chan\.org/[^/]*/thumb/\([0-9]*s\.jpg\)@'$LOC'/misc/\1@g
  123.         s@//images\.4chan\.org/[^/]*/src/\([0-9]*\....\)@'$LOC'/\1@g
  124.         s@//'$ST'/image/title/[^/]*/[a-z0-9-]*\.\(...\)@'$LOC'/misc/logo.\1@g
  125.         s@//'$ST'/image/\(spoiler[^\x2E]*\....\)@'$LOC'/misc/\1@g
  126.         s@//'$ST'/image/\(filedeleted-res\.gif\)@'$LOC'/misc/\1@g
  127.         s@//'$ST'/image/country/\([^/]*/\?[^\x2E]*\....\)@'$LOC'/misc/\1@g
  128.         s@//'$ST'/image/\([a-z]*icon.gif\)@'$LOC'/misc/\1@g
  129.         s_\(<a href="\)'$NO'#p_\1#p_g
  130.         s_<a href="#p'$NO'"[^>]*>&gt;&gt;'$NO'_& (OP)_g
  131.         s_\(<a href="[0-9]\+\)\(#p[^>]*>[^<]*\)_\1.html\2 (Cross-thread)_g
  132.         s_\(</div></div></div><hr>\)<div class="mobile"_\1\n_
  133.         s_\(<div class="navLinks navLinksBot desktop">.<a href="\.\./\./"[^>]*>Return</a>. .<a href="\)#top\(">Top</a>.\)_\n<!</form><span style="float:right;">Style: [ <a href="javascript:sT(1);dE.scrollIntoView(false)">Default</a> | <a href="javascript:sT(0);dE.scrollIntoView(false)">Tomorrow</a> ]</span>\1javascript:dE.scrollIntoView()\2\n_
  134.         s@</body>@\n<!</div>&@}' -e '{s:\(<a href="\)\.\./\./\([^>]*>Return</a>\):\1'"$RET"'\2:g
  135.         s_\(<a[^>]*href="\)//_\1http://_g
  136.         s_\(<a[^>]*\) onclick="replyhl[^"]*"_\1_g
  137.         s_\(<a href="javascript:\)quote[^>]*_\1;"_g
  138.         s_<div class="postInfoM_\n_g
  139.         s_<div class="file"_\n<!&_g
  140.         s_<div class="postInfo _\n<!&_g
  141.         s_<a href="/ic\?/anim\.php?file=[0-9]*" target="\_blank">_<a title="View is supported only on 4chan">_g
  142.         s_\(<input type="checkbox"\)[^>]*_\1_g
  143.         s_<a onclick="toggle..exif[^"]*"_<a_g}' $LOC.html
  144.  
  145.     grep '^<!' $LOC.html > a
  146.  
  147.     sed -i -e '2,$ s_^<!__' a
  148.  
  149.     tr -d '\n' < a > $LOC.html
  150.  
  151.     sed -i -e 's_!>_\n_g' $LOC.html
  152.  
  153.     rm a
  154.  
  155.     # :a;N;$!ba;
  156.  
  157.     cd $LOC
  158.  
  159.     if [ -s a ]; then
  160.         rm $(basename `cat a`) a
  161.     fi
  162.  
  163.     for image in $(cat images); do
  164.         echo $image > a
  165.         wget -q -nc $image
  166.         > a
  167.     done
  168.  
  169.     rm images a
  170.  
  171.     cd misc
  172.  
  173.     if [ -s a ]; then
  174.         rm $(basename `cat a`) a
  175.     fi
  176.  
  177.     for misc in $(cat misc); do
  178.         echo $misc > a
  179.         wget -q -nc $misc
  180.         > a
  181.     done
  182.  
  183.     CSS=$(basename `head -n1 css`)
  184.  
  185.     if [ "$CSSt" != "$CSS" ]; then
  186.         CSSt=CSS
  187.         if [ "$(ls|grep '.css')" ]; then
  188.             rm *.css
  189.         fi
  190.         wget -q -nc -i css
  191.         wget -q -nc "$(grep -o 'fade-\?[a-z0-9]*\.png' $CSS | sed -e 's_.*_http://'$ST'/image/&_')"
  192.         sed -i -e 's_/image/\(fade[^\x2E]*\.png\)_\1_g' $CSS
  193.     fi
  194.  
  195.     if [ "$(ls|grep logo.)" ]; then
  196.         rm "$(ls|grep logo.)"
  197.     fi
  198.  
  199.     wget -q -i logo -O "logo.$(sed 's_\._\n_g' logo|tail -n1)"
  200.  
  201.     rm misc logo css a
  202.  
  203.     touch .nomedia
  204.  
  205.     cd ../..
  206. }
  207.  
  208. exito () {
  209.     echo "Session completed. Exiting     $N"
  210.     exit 0
  211. }
  212.  
  213. echo "${N}Downloading to $LOC$N${N}------------------------------$N"
  214.  
  215. while true; do
  216.     trap exito 1 2 3 15
  217.  
  218.     stat="$(wget -S --spider "$URL" 2>&1)"
  219.  
  220.     if [ "$(echo "$stat" |grep '404 Not Found')" ]; then
  221.         if [ -s $LOC.html ]; then
  222.             echo "Thread has 404'd or 4chan is down. Stopping script${N}"
  223.         else
  224.             echo "Thread does not exist. Stopping script${N}"
  225.         fi
  226.         exit 0
  227.     fi
  228.  
  229.     if [ "$LM" != "$(echo "$stat" |grep Last-Modified)" ]; then
  230.         LM="$(echo "$stat" |grep Last-Modified)"
  231.         SLAP=$SLP
  232.         wget -np -nd -nH -q -erobots=off $URL -O $LOC.html
  233.         thejob
  234.     else
  235.         SLAP=`expr "$SLAP" + "5"`
  236.     fi
  237.  
  238.     trap - 1 2 3 15
  239.  
  240.     if [ $SLP = "1" ]; then
  241.         exito
  242.     fi
  243.  
  244.     echo OK
  245.  
  246.     sleep $SLAP
  247.  
  248.     echo "\b\b  \b\b"
  249. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement