iDuel自带的卡图下载工具慢到不能忍...于是自己写了个
高速iDuel卡图下载工具只有一个功能 就是下载/更新卡图
下载速度应该能占满带宽
需要放到 OCG联网决斗模拟软件(iDuel) 目录下。
实现代码:#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 <<self
def join(*args)
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
同类佳作
-
- Internet Download Manager 订阅版 下载
- 2.4万 | 11.6 MB
- 一款优秀下载工具
-
- Internet Download Manager 标准版 下载
- 6.2万 | 9.7 MB
- 一款非常好用的下载软件
-
- Bilibili视频下载工具 V1.0 电脑版 下载
- 3.9万 | 804 KB
- 是一款为B站打造的视频解析下
-
- 冰点文库下载器 V3.2.7 电脑版 下载
- 1.8万 | 3.3 MB
- 是一款免费实用的文档下载软件
-
- BaiduCDP(百度网盘加速下载) V1.0.1 电脑版 下载
- 9.万 | 14.7 MB
- 是一款网络大神们自制的百度云
-
- 懒人听书批量下载音频工具 V1.0 免费版 下载
- 4.7万 | 407 KB
- 一款针对懒人听书这款软件打造
-
- 多接口音乐解析器 V2.0 电脑版 下载
- 2.3万 | 8.2 MB
- 是一款多平台免费音乐下载工具
-
- 谷歌空间 V1.0 电脑版 下载
- 3.万 | 6.3 MB
- 一款非常实用的谷歌安装器软件
近期新游
精选专题
话题问答
- 2022-06-24金铲铲之战驯龙敖兴阵容玩法攻略
- 2022-06-24金铲铲之战九星界龙阵容玩法攻略
- 2022-06-24金铲铲之战重骑熊阵容玩法攻略
- 2022-06-24原神久岐忍邀约任务攻略
- 2022-06-26数码宝贝新世纪番长飞虫兽天赋加点推荐
- 2022-06-24阴阳师百鬼乱狱第四关通关攻略
- 2022-06-24王者荣耀戈娅玩法攻略
- 2022-06-26金铲铲之战s7泥头车阵容攻略
- 2022-06-24堆叠大陆第三章玩法攻略
- 2022-06-23哈利波特魔法觉醒染发魔药制作攻略
火爆专区
最新资讯
-
- 号称“无担保,秒到账”的网络贷款,很可能是
- 1332024-11-23
-
- 蚂蚁庄园2024年11月24日答案
- 2772024-11-23
-
- 2024蚂蚁庄园今日最新答案11.24
- 1002024-11-23
-
- 2024今日小鸡最新答案11.24
- 522024-11-23
-
- 小鸡宝宝考考你有些树的叶子到了秋天就会变红,猜猜与什么有关
- 2692024-11-23
-
- 为什么树的叶子到了秋天就会变红
- 782024-11-23
-
- 温泉招待活动期间,使用“温泉’招 待光临温泉的忍者们,累计一定次数后可获得成就奖励?
- 2252024-11-23
-
- 蚂蚁庄园今日正确答案11月24日
- 1662024-11-23