local fread=function(f) local h,x = io.open(f,"rb"),nil if h then x=h:read("*all"); io.close(h) end return x end local fwrite=function(s,tdir,f) s = s or "" local h,x = io.open(tdir..f:gsub('[%?%*"<>|:\\/]','_'),"wb"),nil if h then x=h:write(s); io.close(h) end return x end local GetPage=function(x) local s0="" if x then s0=io.popen("curl.exe"..x,"rb"):read("*all") end return s0 end local yadbg=function(x,url,line,tdir) fwrite('loc: '..x..'\nurl: '..url..'\nanswer:\n'..line,tdir,'debug.txt') end local GetYAD=function(purl,tdir) local patt='"mediatype":"compressed",.-,"size":(%d-)},"mtime":(%d-),"utime":%d-,"type":"file","name":"(.-)",.-,"hash":"(.-)"' local opt=' -A "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0" -k ' local line,line0,line1=GetPage(opt..'"'..purl..'"') local fsize,ftime,fname,key=line:match(patt) if fsize and ftime and fname and key then local url='"https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key='..key..'"' patt='"href":"(.-)"' line=GetPage(opt..url) url=line:match(patt) if url and #url>20 then line1='fname: '..fname..'\nfsize: '..fsize..'\nftime: '..os.date("%d.%m.%y %H:%M:%S",ftime) line0=fread(tdir..fname..'.txt') if line0 then line0=line0:match("^(.-)\nkey:") else line0="" end if line0 and line1~=line0 and #line1>40 then patt='Location: (.-)%c' line=GetPage(opt..'"'..url..'" -I') url=line:match(patt) if url and #url>20 then line0=line1..'\nkey: '..key..'\npurl: '..purl..'\ndurl: '..url line=GetPage(opt..'"'..url..'"') if #line>1024 then fwrite(line0,tdir,fname..'.txt') fwrite(line,tdir,fname) else yadbg(5,url,line,tdir) end else yadbg(4,url,line,tdir) end else yadbg(3,url,line,tdir) end else yadbg(2,url,line,tdir) end else yadbg(1,url,line,tdir) end end local tdir='C:\\Temp\\' GetYAD(arg[1],tdir) |