# -*- Mode: ruby ; Coding: sjis-dos -*- # $Id: amazondvd.rb,v 1.8 2002-09-04 23:37:05+09 waka Exp $ # http://wakahiko.cool.ne.jp/ =begin ※ほとんど amazon.rb のコメントそのままです。:-) (DVD:BCBA-0618) (CD:AMCY-7125) みたいな (DVD:背表紙にある記号) (CD:背表紙にある記号) という形式の文字列があると amazon からDVD,PS2データやらパッケージ画像やらを引っ張ってきて置き換えます。 ndiary.conf の LOG_DIRECTORY で指定したディレクトリに amzcacheDVD というディレクトリを 作っておくと取得したデータをキャッシュしておくようになります。 キャッシュの有効期限もスクリプト内で指定しているので必要に応じて変更してください。 ndiary.conf で PROXY = 'proxy.hoge.com:8080' と指定しておくと、情報取得時プロクシを経由するようになります。 =end class Module def attr_my_accessordvd( name ) module_eval %- def #{name.id2name}() get_dvddata @#{name.id2name} end - end end class Amazondvd require 'net/http' require 'kconv' attr_accessor :dvdid attr_my_accessordvd :title attr_my_accessordvd :actor attr_my_accessordvd :maker attr_my_accessordvd :publisher attr_my_accessordvd :director attr_my_accessordvd :size attr_my_accessordvd :pubdate attr_my_accessordvd :price attr_my_accessordvd :desc attr_my_accessordvd :writer attr_my_accessordvd :image_url attr_my_accessordvd :image_width attr_my_accessordvd :image_height attr_my_accessordvd :media attr_my_accessordvd :site attr_reader :cache_dir attr_accessor :expire attr_accessor :proxy attr_accessor :retry def initialize @expire = 14 @proxy = nil @retry = 0 end def load_cache if @flag or (File::directory?(@cache_dir.to_s) and File::readable?(@cache_dir + @dvdid) and File::mtime(@cache_dir + @dvdid) < Time::now.to_i - 3600 * 24 * @expire) then return end @flag = true read_cache end def read_cache begin open(@cache_dir + @dvdid){ |f| @title, @actor, @publisher, @maker,@size, @pubdate, @price, @desc, @writer, @image_url,@image_width, @image_height, @media, @director, @site = f.read.split(/\t/) } rescue @flag = nil end end def save_cache return unless File::directory?(@cache_dir.to_s) begin open(@cache_dir + @dvdid, 'w'){ |f| f.write [ @title, @actor, @publisher, @maker,@size, @pubdate, @price, @desc, @writer, @image_url,@image_width, @image_height, @media, @director, @site ].join("\t") } rescue # end end def httpconnect if @proxy then proxy, port = @proxy.split(':') port = port.to_i else proxy = port = nil end Net::HTTP::Proxy(proxy, port).new( 'www.amazon.co.jp', 80 ) end def httpconnect2 if @proxy then proxy, port = @proxy.split(':') port = port.to_i else proxy = port = nil end Net::HTTP::Proxy(proxy, port).new( 'www.jp.playstation.com', 80 ) end def httpconnect3 if @proxy then proxy, port = @proxy.split(':') port = port.to_i else proxy = port = nil end Net::HTTP::Proxy(proxy, port).new( 'www.google.com', 80 ) end def cache_dir=(dir) dir << '/' unless dir[-1,1] == '/' @cache_dir = dir end def large_image_url get_dvddata @image_url.sub('MZZZZZZZ','LZZZZZZZ') end def get_dvddata load_cache return if @flag dvdid = @dvdid path = "/exec/obidos/search-handle-url/index=blended%26field-keywords=#{dvdid.gsub(/\_/,'%3D')}" http = httpconnect response , = http.get2(path) if response.code == '302' then path = response.header['location'].sub('http://www.amazon.co.jp', '') response , = http.get2(path) end if %r|^
定価: [^¥]+(¥[\d,]+)| =~ response.body then
@price = $1
end
# 定価表示ではなく価格のみ表示の場合
if @price.nil? then
if %r|価格:[^¥]+(¥[\d,]+)| =~ response.body then
@price = $1
end
end
#--------------------------------------------------
# Actor
#--------------------------------------------------
if %r|出演: (.*)| =~ response.body then
@actor = $1
end
#--------------------------------------------------
# Director
#--------------------------------------------------
if %r|監督: (.*)| =~ response.body then
@director = $1
end
#--------------------------------------------------
# Description
#--------------------------------------------------
if %r"(出版社/著者からの内容紹介|内容(「.+?」データベースより)|メーカーより|作品内容) | #{img} | #{title} #{media} #{maker} #{actor} #{director} #{pubdate} #{price} #{size} #{writer} #{desc} #{site} |