Advertisement
reges007

Save_Hit_by_Last-Modified(raw)

Mar 24th, 2015
2,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. --[[ <HCExtension>
  2. @name          Save and Hit by Last-Modified (raw)
  3. @author        reges007
  4. @version       1
  5. @description   Cache-control by Last-Modified, berfungsi menggantikan peran menu 'save to cache' dan 'don't update' namun dalam kasus tertentu masih diperlukan secara manual.
  6. @exception     ^.*(googlevideo|youtube).com/videoplayback.*
  7. @exception     \.action$
  8. @exception     ^.*(google.com/market/GetBinary/.*)\?.*
  9. @exception     ^.+.(captcha|mrtg|cgi-bin|notice|announce).*
  10. @rule          ^(.*\.[a-z|0-9|\-]{2,15})(\?|&|$)
  11. @event         AnswerHeaderReceived/save
  12. </HCExtension> ]]
  13.  
  14. function GetAnswerCode(s)
  15.   _,_,x = string.find(s, 'HTTP/1%.%d +(%d+)')
  16.   if x==nil then return -1 else return tonumber(x) end
  17. end
  18.  
  19. function cek_file(s)
  20.    local f=io.open(s,"r")
  21.     if f~=nil then io.close(f) return true
  22.    else return false
  23.    end
  24. end
  25.  
  26. function save()
  27.  
  28.          local code = GetAnswerCode(hc.answer_header)
  29.  
  30.              if hc.method == 'GET' and code==200 then
  31.                 local file = hc.get_cache_file_name(hc.url)
  32.                 local dir =  re.replace(file, [[^(.*)]], [[\1.txt]])           -- destination log adalah sama pathnya dengan destination konten, untuk membedakan log dng konten dikasih akhiran .txt
  33.                 local dir =  re.replace(dir, [[(\w:\\)]], '')            
  34.                 local dir =  re.replace(dir, [[(Cache\\)]], '')
  35.                 local lmdf = re.find(hc.answer_header, [[^Last-Modified:\s([^\r\n]+)]]) -- mengambil variabel dimulai dari Last-modified
  36.                 local lmdf = re.replace(lmdf, [[Last-Modified:\s]], '', true)  -- membuang karakter yang tidak diperlukan
  37.                 local lmdf = re.replace(lmdf, [[([\s,:])]], '', true)          -- membuang karakter yang tidak diperlukan
  38.                 local path = hc.cache_path ..dir -- log last-modified disimpan sesuai path kontennya
  39.                    
  40.                     if cek_file(path) == false or hc.cache_file_name== '' then -- jika log atau cache kontennya kosong script mulai menulis log dan menyimpan konten
  41.                            hc.prepare_path(path)
  42.                          local tls = io.open(path, "w")
  43.                                tls:write(lmdf)
  44.                                tls:close()
  45.                            hc.action = 'save-'
  46.                            hc.monitor_string = hc.monitor_string.. 'SAVE.NEW-FILE'
  47.                     else                                                       -- jika log dan cache konten ada script memulai membaca data log last-modified
  48.                                 hc.prepare_path(path)
  49.                           local baca = io.open(path, "r")
  50.                           local cek = baca:read('*a')
  51.  
  52.                               if cek == lmdf and hc.cache_file_name==file then -- script melakukan pengecekan data log last-modified dengan data last-modified dari server/internet
  53.                                  baca:close()                                  -- jika data sama script melakukan action don't update aka hit cache
  54.                                  hc.action = 'dont_update-'
  55.                                  hc.monitor_string = hc.monitor_string.. 'Hit-Cache Last-Modified'
  56.                               else                                           -- jika log ada dan konten kosong atau konten ada dan log kosong
  57.                                  hc.prepare_path(path)                       -- atau data last-modified berubah dari server/internet script memulai tulis ulang log dan simpan new konten atau update konten  
  58.                                  local tls = io.open(path, "w")
  59.                                        tls:write(lmdf)
  60.                                        tls:close()
  61.                                   hc.action = 'save-'
  62.                                   hc.monitor_string = hc.monitor_string.. 'SAVE.UPDATE-FILE'
  63.                               end
  64.                     end
  65.              end
  66.              
  67. end
  68.  
  69. -- Extension ini hanya untuk penggunaan reguler saja alias static contents, yaitu kerpeluan browsing dan web based games atau pc games online yang algorithmanya tidak rumit.
  70. -- Untuk penggunaan expert seperti dynamic content (youtube dll) dan algorithma games yang rumit (elsword,garena dll) hanya khusus pembeli saja.
  71. -- Silahkan edit sesuai keperluan Anda tanpa merubah credit.
  72. -- Dengan membaca ini atau menggunakan Extension ini Anda setuju jika terjadi kelainan atau kerusakan adalah diluar tanggung jawab penulis (reges007) .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement