
var secs_to_backfill = mp3;0day;dox;ebook;pda;xxx;games;divx;svcd;vcd;xbox
var source_sites_to_skip = badsite1|badsite2
var skip_dirs = *NUKED*

#days to backfill can only be 1 ... everything else is kinda useless but well
var days_to_backfill = 1

var tmp = $paramstr(1)
if $tmp != 
  var secs_to_backfill = $tmp
end


######################################################################################


  var source_sites = ACTIVESITELIST

  for sec in $secs_to_backfill


    for sname in $source_sites

      if $sname = $source_sites_to_skip
        goto site_done
      end

      var i=0
      :backfill_start


      var source_dirs=$sname.sectionpath($sec,$i)
      var sdir_temp=$sname.sectionpath($sec,500)

      for sdir in $source_dirs

        #did we have this one parsed already?
        if $sdir = $parsed_pathes
          #writeln [-] already parsed $sdir ($parsed_pathes)
          goto dir_done
        end

        if $parsed_pathes<>
          var parsed_pathes=$parsed_pathes|
        end
        var parsed_pathes=$parsed_pathes$sdir
          

        #create check-dir
        var dir_count=$dir_count+1
        var sdir_chk=GETPART $sdir_temp $dir_count ";"

        #check if its a dated dir or not....
        var dated_dir=1
        if $sdir_chk=$sdir
          var dated_dir=0
        end

        select $sname
        if $sname.connected = false
          connect $sname
        end
        if $sname.connected = false
          goto dir_done
        end

        cwd $sdir
        if $sname.ok = false
          goto dir_done
        end

        refresh
        SELECT mask *
        if $dated_dir=0
          LIMITSELECTION DAY-$days_to_backfill
        end
        var que=SELECTION

        var beauty_i=$i+1
        writeln [$sec] %bold$sname:%bold$sdir
        writeln [$sec] Dated: $dated_dir, Day-X: $beauty_i/$days_to_backfill
          

        for item in $que
          if $item <> $skip_dirs
            TRADE $item
            var skip_dirs=$skip_dirs|$item
          end
        end

        :dir_done

      end

      if $source_dirs!=$sdir_temp
        var dated_dir=1
      end

      if $dated_dir=1
        var i=$i+1
        if $i != $days_to_backfill
          goto backfill_start
        end
      end
      :site_done

    end
    :section_done
  end
