Skip to content

Instantly share code, notes, and snippets.

@Yengas
Last active December 29, 2015 07:09
Show Gist options
  • Save Yengas/7633965 to your computer and use it in GitHub Desktop.
Save Yengas/7633965 to your computer and use it in GitHub Desktop.
Popoizle.com arşivini indirir.
require 'net/http'
require 'json'
if (!Dir.exist?("Archive")) then Dir.mkdir("Archive"); end
@hashes = []; # Hashleri tutmak için array oluştur.
def downloadGif(uri, hash)
uri = URI(uri);
http = Net::HTTP.new(uri.host, uri.port);
get = Net::HTTP::Get.new(uri.to_s);
response = http.request(get);
if (response.code == "200") then File.open("Archive/#{hash}.gif","wb") do |file| file.write(response.body); end; puts "Added #{hash}.gif to the Archive, from URL: #{uri}, Total Gifs: #{(@hashes.length + 1)}"; end;
end
Dir.foreach("Archive/") do |file|
if (file.slice(-3,3) == "gif") then @hashes.push(file.sub(".gif","")); end; # Klasörü tara ve hash isimlerini, array'e gönder.
end
puts "Total of #{@hashes.count} gifs in the current Archive.";
uri = URI("http://popoizle.com/api/?action=get"); # Uri'yi initialize et.
http = Net::HTTP.new(uri.host, uri.port); # http bağlantısının ön hazırlığı. "http://forum.donanimhaber.com", 80
get = Net::HTTP::Get.new(uri.to_s); # get bağlantısının ön hazırlığı. "/index.asp"
bad = 0;
while true do
response = http.request(get); # http değişkeni üzerinden, get değişkeni bilgilerine göre http request yap, cevabı response'a ata.
if (response.code == "200") then
jResponse = JSON.parse(response.body);
puts jResponse
if (!@hashes.include?(jResponse["message"]["hash"])) then
begin
downloadGif(jResponse["message"]["url"], jResponse["message"]["hash"]);
@hashes.push(jResponse["message"]["hash"]);
bad = 0;
rescue then end;
else bad += 1; end
end
if (bad == 100) then puts "Hepsini indirmiş olmalı panpa."; break; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment