Advertisement
KiberInfinity

Grab photos links from vk walls list

Jun 4th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vk_photos.scan_walls_list=function(list){
  2.    var PER_REQ=100;
  3.    var offset=0;
  4.    var links=[];
  5.    var oid=cur.oid;
  6.    var type='owner_id';
  7.    var lid=0;
  8.    var abort=false;
  9.    if (oid) list.push(oid);
  10.    function next(){
  11.       offset=0;
  12.       if (lid>=list.length) {
  13.          var to_file=isChecked('links_to_file');
  14.          vkSetVal('vk_collect_links_to_file',to_file?'1':'0');
  15.          ge('vk_links_container').innerHTML='<h2>count: '+links.length+'</h2><textarea style="width:590px; height:300px;">'+links.join('\n')+'</textarea>';
  16.          if (to_file)
  17.             vkSaveText(links.join('\n'),("wall_photos_"+oid).substr(0,250)+".txt");
  18.          return;
  19.       }
  20.       oid=list[lid]+'';
  21.       if (oid.match(/^-?\d+$/)){
  22.          type='owner_id';
  23.       } else {
  24.          var m=oid.match(/(^|\/)(club|public|event|id)(\d+)/);
  25.          if (m){
  26.             oid=(m[2]=='id'?'':'-')+m[3];
  27.             type='owner_id';
  28.          } else {
  29.             oid=oid.split(/\?|#/)[0].split('/').pop().replace(/[^a-zA-Z0-9_]+/g,'');
  30.             type='domain';
  31.          }
  32.       }
  33.       if (!oid || oid==''){
  34.          lid++;
  35.          next();
  36.       } else {
  37.          scan();
  38.          lid++;
  39.       }
  40.    }
  41.    
  42.    function scan(filter){
  43.       if (abort) return;
  44.       filter = filter || 'all';
  45.       var params={count:PER_REQ,offset:offset,filter:filter,extended:1};
  46.       params[type]=oid;
  47.       dApi.call('wall.get',params,function(r){
  48.          if (abort) return;
  49.          var data=r.response;
  50.          if (r.error){
  51.             if (r.error.error_code==15 && filter!='owner'){
  52.                filter='owner';
  53.                scan(filter);
  54.                return;
  55.             } else {
  56.                ge('vk_scan_log').innerHTML+='Scan error. <b>'+oid+'</b> ('+r.error.error_msg+'). Skip...<br>';
  57.                next();
  58.                return;
  59.             }
  60.          }
  61.          var posts=data.wall;
  62.          var count=posts.shift();
  63.          var len=posts.length;
  64.          ge('vk_links_container_progr').innerHTML=vkProgressBar(offset,count,600)+(list.length>1?vkProgressBar(lid,list.length,600):'');
  65.          for (var j=0; j<len; j++){
  66.             var att=posts[j].attachments;
  67.             if (!att) continue;
  68.             for (var i=0; i<att.length; i++){
  69.                if (!att[i].photo) continue;
  70.                var p=att[i].photo;
  71.                links.push(p.src_xxxbig || p.src_xxbig || p.src_xbig || p.src_big || p.src_big);
  72.                p=null;
  73.             }
  74.             att=null;
  75.          }
  76.          data=null;
  77.          posts=null;
  78.          if (len>0){
  79.             offset+=PER_REQ;
  80.             setTimeout(function(){scan(filter)}, 350);
  81.          } else {
  82.             next();
  83.          }
  84.       })
  85.    }
  86.    
  87.       var html='<div id="vk_links_container"><div id="vk_links_container_progr"></div>'+
  88.                '<br><div class="checkbox'+(vkGetVal('vk_collect_links_to_file')=='1'?' on':'')+' fl_l" id="links_to_file" onclick="checkbox(this);"><div></div>Save links list to file after scan</div><br><div id="vk_scan_log"></div></div>';
  89.    var box=vkAlertBox(IDL('Links'),html,function(){abort=true;});
  90.    box.setOptions({width:"640px"});
  91.    next();
  92. }
  93. vk_photos.scan_walls_list_box=function(){
  94.    var html='<textarea id="vk_links_list" style="width:560px; height:300px;"></textarea>';
  95.    
  96.    var aBox = new MessageBox({title: IDL('Enter_links')});
  97.    aBox.removeButtons();
  98.    aBox.addButton(getLang('box_cancel'),aBox.hide, 'no')
  99.    aBox.addButton('OK',function(){  
  100.       var links=ge('vk_links_list').value;
  101.       links=trim(links).split(/\s*[\r\n,]+\s*/);
  102.       aBox.hide();
  103.       if (links.length==0){
  104.          alert('List is empty...');
  105.       } else {
  106.          vk_photos.scan_walls_list(links);
  107.       }
  108.    },'yes');
  109.    aBox.content(html);
  110.    aBox.setOptions({width:"600px", onHide:function(){aBox.content('');}});
  111.    aBox.show();
  112. }
  113. vk_photos.scan_walls_list_box();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement