iqdb fixes

This commit is contained in:
r888888888
2014-03-27 10:54:47 -07:00
parent 7a3e843259
commit 22a2c97963
3 changed files with 7 additions and 4 deletions

View File

@@ -1,15 +1,15 @@
module Iqdb module Iqdb
class Importer class Importer
def import! def import!
IO.popen("iqdb command #{Danbooru.config.iqdb_file}", "w") do |io| Post.find_each do |post|
Post.find_each do |post| IO.popen("iqdb command #{Danbooru.config.iqdb_file}", "w") do |io|
if File.exists?(post.preview_file_path) if File.exists?(post.preview_file_path)
puts post.id puts post.id
hex = post.id.to_s(16) hex = post.id.to_s(16)
io.puts "add 0 #{hex}:#{post.preview_file_path}" io.puts "add 0 #{hex}:#{post.preview_file_path}"
end end
io.puts "quit"
end end
io.puts "quit"
end end
end end
end end

View File

@@ -1,6 +1,8 @@
module Iqdb module Iqdb
module Responses module Responses
class Collection class Collection
attr_reader :responses
def initialize(response_string) def initialize(response_string)
@responses = response_string.split(/\n/).map do |string| @responses = response_string.split(/\n/).map do |string|
::Iqdb::Responses.const_get("Response_#{string[0..2]}").new(string[4..-1]) ::Iqdb::Responses.const_get("Response_#{string[0..2]}").new(string[4..-1])

View File

@@ -3,7 +3,7 @@ module Iqdb
FLAG_SKETCH = 0x01 FLAG_SKETCH = 0x01
FLAG_GRAYSCALE = 0x02 FLAG_GRAYSCALE = 0x02
FLAG_WIDTH_AS_SET = 0x08 FLAG_WIDTH_AS_SET = 0x08
FLAG_DISCARD_COMMON_COEFFS = 0x16 FLAG_DISCARD_COMMON_COEFFS = 0x10
attr_reader :hostname, :port, :socket attr_reader :hostname, :port, :socket
@@ -48,6 +48,7 @@ module Iqdb
def query(results, filename, flags = FLAG_DISCARD_COMMON_COEFFS) def query(results, filename, flags = FLAG_DISCARD_COMMON_COEFFS)
request do request do
socket.puts "query 0 #{flags} #{results} #{filename}" socket.puts "query 0 #{flags} #{results} #{filename}"
socket.puts "done"
responses = Responses::Collection.new(@socket.read) responses = Responses::Collection.new(@socket.read)
end end
end end