-gem 'zipruby'
-require 'zipruby'
-require 'nkf'
+require 'archivers'
class Arc < ActiveGroonga::Base
def code
key
end
- def encode(str)
- str && NKF.nkf('-Sw', str)
- end
-
def create_zip_entries(path)
- Zip::Archive.open(path) do |ar|
- puts "# #{path}"
-
- n = ar.num_files # number of entries
- n.times do |i|
- # entry_name = ar.get_name(i) # get entry name from archive
-
- # open entry
- ar.fopen(i) do |f|
- path = encode(f.name)
- case path
- when /\.pmd\z/
- puts [ code, path ].join(' ')
- pmds = Pmd.select { |rec| rec.arc == code && rec.path == path }
- pmds.count != 0 || Pmd.create(:arc => code, :path => path)
- when /\.vmd\z/
- puts [ code, path ].join(' ')
- vmds = Vmd.select { |rec| rec.arc == code && rec.path == path }
- vmds.count != 0 || Vmd.create(:arc => code, :path => path)
- when /\.x\z/
- puts [ code, path ].join(' ')
- xes = X.select { |rec| rec.arc == code && rec.path == path }
- xes.count != 0 || X.create(:arc => code, :path => path)
- end
-
- # content = f.read # read entry content
- end
+ zip = Archivers::Zip.new(path)
+ zip.each_entry do |ent|
+ case ent
+ when /\.pmd\z/
+ puts [ code, ent ].join(' ')
+ pmds = Pmd.select { |rec| rec.arc == code && rec.path == ent }
+ pmds.count != 0 || Pmd.create(:arc => code, :path => ent)
+ when /\.vmd\z/
+ puts [ code, ent ].join(' ')
+ vmds = Vmd.select { |rec| rec.arc == code && rec.path == ent }
+ vmds.count != 0 || Vmd.create(:arc => code, :path => ent)
+ when /\.x\z/
+ puts [ code, ent ].join(' ')
+ xes = X.select { |rec| rec.arc == code && rec.path == ent }
+ xes.count != 0 || X.create(:arc => code, :path => ent)
end
end
- rescue Zip::Error => exc
- puts "error: " + exc.message
end
end
--- /dev/null
+#!ruby
+# encoding: utf-8
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'rubygems'
+require 'archivers'
+
+path = ARGV.shift
+
+lzh = Archivers::Lzh.new(path)
+lzh.each_entry do |ent|
+ puts ent
+end
--- /dev/null
+#!ruby
+# encoding: utf-8
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'rubygems'
+require 'archivers'
+
+path = ARGV.shift
+
+rar = Archivers::Rar.new(path)
+rar.each_entry do |ent|
+ puts ent
+end
--- /dev/null
+#!ruby
+# encoding: utf-8
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'rubygems'
+require 'archivers'
+
+path = ARGV.shift
+
+zip = Archivers::Zip.new(path)
+zip.each_entry do |ent|
+ puts ent
+end
--- /dev/null
+#!/usr/bin/ruby
+# download from uppervolta-3d.net
+#
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'sn_uploader'
+
+def each_filename(text)
+ file_href = './src/'
+ file_re = Regexp.new(Regexp.escape(file_href) + '(.+?)\.html')
+ text.scan(/href="(.+?)"/) do |href, |
+ if md = file_re.match(href)
+ yield md[1]
+ end
+ end
+end
+
+name = ARGV.shift || 'kiss'
+
+uploader = SnUploader.new
+uploader.host = "uppervolta-3d.net"
+uploader.root_path = "/" + name
+uploader.base_html = "all.html"
+uploader.local_dir = "/Volumes/uploader/arc/uppervolta-3d.net/" + name
+
+src_path = "/Volumes/uploader/src/uppervolta-3d.net/" + name + "/all.html"
+
+if false
+ # read index.html from remote site
+ body = uploader.get_base
+ # save index.html as local cache
+ open(src_path, 'wb') { |f| f.write body }
+end
+
+# read index.html from local cache
+body = IO.read(src_path)
+
+each_filename(body) do |filename|
+ exist = uploader.local_file_exist?(filename)
+ puts [ filename, exist ? 'exist' : 'download' ].join("\t")
+ unless exist
+ sleep(5)
+ uploader.download_file_through_clicker(filename)
+ end
+end
--- /dev/null
+gem 'zipruby'
+require 'zipruby'
+require 'nkf'
+
+module Archivers
+ class Lzh
+ def initialize(path)
+ @path = path
+ end
+
+ def each_entry
+ text = `lha lv #{@path}`
+ mode = :head
+ StringIO.new(text).each_line do |line|
+ case mode
+ when :head
+ if /\A----/.match(line)
+ mode = :flip
+ next
+ end
+ when :flip
+ if /\A----/.match(line)
+ mode = :tail
+ next
+ end
+ yield line
+ mode = :flop
+ when :flop
+ mode = :flip
+ end
+ end
+ end
+ end
+
+ class Rar
+ def initialize(path)
+ @path = path
+ end
+
+ def each_entry
+ text = `unrar vb #{@path}`
+ StringIO.new(text).each_line do |line|
+ yield line
+ end
+ end
+ end
+
+ class Zip
+ def initialize(path)
+ @path = path
+ end
+
+ def encode(str)
+ str && NKF.nkf('-Sw', str)
+ end
+
+ def each_entry
+ ::Zip::Archive.open(@path) do |ar|
+ n = ar.num_files # number of entries
+ n.times do |i|
+ # entry_name = ar.get_name(i) # get entry name from archive
+
+ # open entry
+ ar.fopen(i) do |f|
+ path = encode(f.name)
+ yield path
+
+ # content = f.read # read entry content
+ end
+ end
+ end
+ rescue ::Zip::Error => exc
+ puts "error: " + exc.message
+ end
+ end
+end