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
开发者其他应用

简单搜索43.8M30201人在玩简单搜索是一款手机上的搜索引擎,在简单搜索中给用户可以智能高效的搜到自己想搜的内容哦,其中简单搜索在功能体验上还是很不错的,有需要上网的用户快来西西简单搜索专区下载
下载
腾讯体育app最新版224.1M42099人在玩腾讯体育app最新版是腾讯体育平台推出的一款便捷的手机体育直播app。通过这款腾讯体育app,你可以观看赛事直播,也能第一时间了解最新体育新闻动态。
下载
看点快报app40.3M1048人在玩天天快报app是一款生活娱乐应用,天天快报app每日为用户推送有趣的娱乐搞笑段子,同时你可以对文章及图片进行评论,有不少内涵的神吐糟回复,还能在在图片中加入贴图与文字
下载
猎豹浏览器手机版23.0M26398人在玩猎豹浏览器手机版以极速和炫酷为主要特色,重点突出手机观看视频功能,首次在手机浏览器上实现支持快播与百度影音。猎豹浏览器手机版更省流量、更安全、更智能
下载
百度安卓版133.7M11270人在玩手机百度是一款有6亿用户在使用的手机搜索客户端,依托百度网页、百度图片、百度新闻、百度知道、百度百科、百度地图、百度音乐、百度视频等专业垂直搜索频道,方便用户随时随地使用百度搜索服务。
下载
2345浏览器手机版54.6M582人在玩2345浏览器具有智能广告拦截、网页多标签浏览、超级拖拽、鼠标手势、上网痕迹清除、老板键等多项网页浏览实用功能。功能特性收藏夹随身携带网站网址随身携带不丢失,注册登录2345帐号。
下载
凤凰新闻80.3M8934人在玩凤凰新闻客户端是一款优秀的新闻阅读客户端,第一时间奉献最新最有价值的新闻!依托凤凰卫视、凤凰网独家新闻资讯优势,每天24小时精心呈现全方位新闻讯息。
下载
腾讯微云42.3M561人在玩腾讯微云下载,微云可以让PC和手机文件可进行无线传输并实现同步,让手机中的照片自动传送到PC,并可向朋友们共享,功能和苹果的iCloud较为类似。
下载
chrome谷歌浏览器手机版222.5M38380人在玩谷歌浏览器手机版下载安装到手机桌面是通用于android4.0以上平板电脑和手机设备上的chrome浏览器,GoogleChrome浏览器不仅在桌面设备上表现卓越,在Android手机和平板电脑上也可让您
下载
百度贴吧安卓版2022最新版58.1M7231人在玩西西最喜欢用百度贴吧安卓版下载安装最新版看小说,热门小说更新及时,而且是文字版,有手机看更方便,可以随时看。百度贴吧客户端抢楼更快捷,随心所欲发图片,还有更多贴吧豆奖励哦!更快升级速度!
下载
支持( 0 ) 盖楼(回复)