Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created February 29, 2012 03:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rummelonp/1937292 to your computer and use it in GitHub Desktop.
Save rummelonp/1937292 to your computer and use it in GitHub Desktop.
いかにしておっぱい画像をダウンロードするか〜2012 for Ruby

oppai.rb

いかにしておっぱい画像をダウンロードするか〜2012 - ゆーすけべー日記
これを Ruby でそのまま実装してみた

使い方

git clone git://gist.github.com/1937292.git oppai # この Gist をコピー
cd oppai
bundle install # Bundler で依存ライブラリをインストール
mkdir data # おっぱい画像専用フォルダ作る
vim oppai.rb # appid 変数に Bing API の ApplicationId 入れる
ruby oppai.rb # おっぱい画像集める

その他

僕達は効率よく大量のおっぱい画像をダウンロードする使命があります
おっぱい画像を集めるために Ruby を学びましょう

# -*- coding: utf-8 -*-
source 'http://rubygems.org'
gem 'addressable'
gem 'json' if RUBY_VERSION < '1.9'
gem 'hashie'
# -*- coding: utf-8 -*-
require 'rubygems'
require 'pathname'
require 'open-uri'
require 'digest/md5'
require 'addressable/uri'
require 'json'
require 'hashie'
appid = ''
uri = Addressable::URI.parse 'http://api.bing.net/json.aspx'
dir = Pathname.new './data'
page_count = 0
download_count = 0
loop do
offset = page_count * 50
uri.query_values = {
:Appid => appid,
:Version => '2.2',
:Market => 'ja-JP',
:Sources => 'Image',
'Image.Count' => 50,
'Image.Offset' => offset,
:Adult => 'off',
:Query => 'おっぱい'
}
res = open(uri).read
ref = JSON.parse res
ref = Hashie::Mash.new ref
break unless ref.SearchResponse!.Image!.Results
ref.SearchResponse.Image.Results.each do |entry|
next unless entry.MediaUrl =~ /\.jpg$/
download_count += 1
filename = Digest::MD5.hexdigest(entry.MediaUrl) + '.jpg'
filepath = dir + filename
next if filepath.file?
puts "#{download_count}: Download... #{entry.MediaUrl}"
res = open(entry.MediaUrl) rescue next
if res.content_type =~ /^image/
open(filepath, 'w').print res.read
end
end
page_count += 1
end
# -*- coding: utf-8 -*-
require 'rubygems'
require 'pathname'
require 'open-uri'
require 'digest/md5'
require 'addressable/uri'
require 'json'
require 'hashie'
appid = ''
uri = Addressable::URI.parse 'http://api.bing.net/json.aspx'
dir = Pathname.new './data'
page_count = 0
download_count = 0
loop do
offset = page_count * 50
uri.query_values = {
:Appid => appid,
:Version => '2.2',
:Market => 'ja-JP',
:Sources => 'Image',
'Image.Count' => 50,
'Image.Offset' => offset,
:Adult => 'off',
:Query => 'おっぱい'
}
res = open(uri).read
ref = JSON.parse res
ref = Hashie::Mash.new ref
break unless ref.SearchResponse!.Image!.Results
threads = []
ref.SearchResponse.Image.Results.each do |entry|
next unless entry.MediaUrl =~ /\.jpg$/
download_count += 1
filename = Digest::MD5.hexdigest(entry.MediaUrl) + '.jpg'
filepath = dir + filename
next if filepath.file?
puts "#{download_count}: Download... #{entry.MediaUrl}"
threads << Thread.start {
res = open(entry.MediaUrl) rescue next
if res.content_type =~ /^image/
open(filepath, 'w').print res.read
end
}
end
threads.each {|t| t.join}
page_count += 1
end
@ryo22222
Copy link

こんにちは。非常に面白いコードを有難う御座います。
早速、cloneしてやっていたのですが、上手く行きませんでした。

Bing API の登録も終え、
vim oppai.rb # appid 変数に Bing API の ApplicationId を入れ、ruby oppai.rb
をしたのですが、エラーが出るわけでもなく、かといって画像も収集できず・・・。

現在、以下のバージョンを使用しておりますが、バージョンの問題でしょうか?
ruby 2.1.5p273

それとも# appid 変数に Bing API の ApplicationId 入れるというところを間違えている可能性があります。

11行目の appid = ''
の''の中にApplicationIdをいれたのですが、こちらであっておりますでしょうか?

初心者ながら大変申し訳御座いませんが、ご回答頂けると幸いです。
宜しくお願いします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment