您现在的位置是:网站首页> 软件下载软件下载
高速iDuel卡图下载工具下载-软件下载
2021-05-20
125人已围观
简介 高速iDuel卡图下载工具下载-软件下载
iDuel自带的卡图下载工具慢到不能忍...于是自己写了个
只有一个功能 就是下载/更新卡图
下载速度应该能占满带宽
需要放到 OCG联网决斗模拟软件(iDuel) 目录下。
http://www.cr173.com/soft/71354.html
实现代码:
#encoding: UTF-8
if !File.file? 'data/allcards.dll'
puts "请放到iDuel目录下运行"
exit
end
cards = IO.readlines('data/allcards.dll').size / 2
puts "卡片总计 #{cards} 张"
if File.file? 'data/config.ini'
require 'inifile'
config = IniFile.new IO.read('data/config.ini', mode: 'rb:BOM|UTF-16LE:UTF-8')
path = config['Config'] && config['Config']['CardImagePath']
end
if !path or !File.directory? path
require 'win32/registry'
path = Win32::Registry::HKEY_CURRENT_USER.open('Software\OCGSOFT\Cards') { |reg| reg['Path'] } rescue ''
path.force_encoding(Encoding::GBK).encode!(Encoding::UTF_8)
end
if !path or !File.directory? path
Dir.mkdir 'data' unless File.directory? 'data'
path = 'data/image'
end
puts "本地卡图路径 #{path}"
Dir.mkdir path unless File.directory? path
def batch_download(main_url, files, content_type=nil)
connections = {}
count = {total: files.size, error: 0}
[10*100, files.size].min.times { do_download(main_url, files, content_type, count, connections) }
end
def do_download(main_url, files, content_type, count, connections)
if connections.size < 10
connection = EventMachine::HttpRequest.new(main_url)
connections[connection] = 0
else
connection = connections.min_by { |key, value| value }
if connection[1] >= 100
return
else
connection = connection[0]
end
end
remote_path, local_path = files.shift
connections[connection] += 1
connection.get(path: remote_path, keepalive: connections[connection] != 100).callback { |http|
puts File.basename local_path
count[:error] = 0
count[:total] -= 1
if http.response_header['CONNECTION'] != 'keep-alive'
connection.close
connections.delete(connection)
do_download(main_url, files, content_type, count, connections) while !files.empty? and (connections.size < 10 or connections.values.min < 100)
end
if http.response_header.status == 200 and (!content_type or http.response_header['CONTENT_TYPE'] == content_type)
IO.binwrite local_path, http.response
else
puts http.response_header.http_status
end
if count[:total].zero?
connections.each_key { |connection| connection.close }
connections.clear
puts 'all done'
EM.stop
end
}.errback { |http|
puts http.error
connection.close
connections.delete(connection)
files[remote_path] = local_path
count[:error] += 1
if count[:error] <= 10*100
do_download(main_url, files, content_type, count, connections) while !files.empty? and (connections.size < 10 or connections.values.min < 100)
else
connections.each_key { |connection| connection.close }
connections.clear
puts 'network error'
EM.stop
end
}
end
cards_to_download = (1..cards).to_a - Dir.glob(File.expand_path '*.jpg', path).collect { |file| File.basename(file, '.jpg').to_i }
puts "需要下载 #{cards_to_download.size} 张"
exit if cards_to_download.empty?
#monkey patch for exerb & addressable
if defined? ExerbRuntime
require 'stringio'
module Addressable
module IDNA
module File
class <
end
def expand_path(*args)
end
def dirname(*args)
end
def open(*args)
result = ExerbRuntime.open('unicode.data')
if block_given?
begin
yield result
ensure
result.close
end
end
end
end
end
end
end
end
require 'em-http-request'
EventMachine.run do
http = EventMachine::HttpRequest.new('http://p.ocgsoft.cn/:osid.jpg').get redirects: 10
http.callback { |http|
main_url = http.last_effective_url
puts "获取卡图下载地址: #{main_url}"
files = {}
cards_to_download.each { |card_id| files[main_url.path.gsub(':osid', card_id.to_s)] = File.join(path, card_id.to_s + '.jpg') }
batch_download(main_url.to_s, files, 'image/jpeg')
}
end
相关内容
- 火狐浏览器下载记录查看(FirefoxDownloadsview)下载V1.37 绿色中文版-软件下载
- 无线信号扫描工具 inSSIDer下载3.0.7.48 免费版-软件下载
- 虚拟路由器 Virtual Router Plus下载2.6.0 免费版-软件下载
- NetResView (共享资源查看)下载v1.27 绿色中文版-显示连接到您的电脑的所有网络资源软件下载
- IIS 7.0 完整安装包(适用Win 2008)下载-软件下载
- dr.com宽带认证客户端最新版下载V3.46 绿色版-Dr.COM破解共享上网限制软件下载
- 锐捷客户端最新版-锐捷最新版下载4.96 官方正式版-软件下载
- Xuite空间下载器(xd)下载v2.0 绿色版-软件下载
- 卡脆地址转换助手下载v1.0 绿色版-软件下载
- 爱新闻下载v1.01 官方版-软件下载
点击排行
- 英语演讲软件下载 TED英语演讲软件 V1.0.0.4 免费安装版 下载-
- 腾讯课堂学生版下载 腾讯课堂学生版 v4.1.6.2 官方版 下载-
- REDUCE下载 REDUCE(交互式代数计算系统) v5424 免费安装版 下载-
- 好芳法课堂下载 好芳法课堂 v1.6.0 官方安装版 下载-
- 元贝驾考pc下载 元贝驾考(驾驶员考试科目一模拟系统) v2021.1 免费安装版 下载-
- Arithmetic下载 Arithmetic(算术学习软件) v1.0 免费绿色版 32/64位 下载-
- Dayday英语学习软件下载 Dayday英语电脑版 V1.0 官方安装版 下载-
- 腾讯教育应用平台客户端下载 腾讯教育应用平台 v2.9.2083.400 官方安装版 下载-


