Amazon_shopver='$Id: amazon_shop.rb,v 1.23 2005/09/22 17:45:44 waka Exp waka $'.split(" ")[2] # http://www.double-red.net/ =begin 日記中に (@DVD:BCBA-0618) (@CD:AMCY-7125) みたいな (@DVD:背表紙にある記号) (@CD:背表紙にある記号) という形式の文字列があると amazon から書誌、DVD,CDの情報やら書影、ジャケット画像、商品画像やらを引っ張ってきて置き換えます。 www.amazon.co.jp が取り扱っている以下の商品に対応しています。 (基本的に ASIN で指定すれば確実です) 本 (@ASIN:ASIN) もしくは (@ISBN:ISBN) 洋書 (@ASIN:ASIN) もしくは (@ISBN:ISBN) エレクトロニクス (@ASIN:ASIN) ホーム&キッチン (@ASIN:ASIN) ミュージック(CD) (@ASIN:ASIN) もしくは (@CD:背表紙にある記号) DVD/ビデオ (@ASIN:ASIN) もしくは (@DVD:背表紙にある記号) ソフトウェア (@ASIN:ASIN) ゲーム (@ASIN:ASIN) ゲームは ASIN の他に以下の書式が利用できます ・PlayStation (@PS:背表紙にある記号) ・PlayStation2 (@PS2:背表紙にある記号) ・GAMECUBE (@GC:背表紙にある記号) ・GAME BOY ADVANCE (@GBA:背表紙にある記号) ・Xbox (@XBOX:背表紙にある記号) ・PSP (@PSP:背表紙にある記号) ・Nintendo DS (@NDS:背表紙にある記号) @@仕様----------------------------------------------------------- ruby 1.8.x 以上推奨 ※ ruby 1.6.x で利用する際には ※ yaml.rb(http://yaml4r.sourceforge.net/)をインストールしてください。 http://prdownloads.sourceforge.net/yaml4r/syck-0.42.tar.gz?download が最新のようです(2004-01-27現在) @@キャッシュディレクトリ設定------------------------------------ ndiary.conf の LOG_DIRECTORY で指定したディレクトリに amazon_shop というディレクトリを作っておくと取得したデータをキャッシュしておくようになります。 キャッシュの有効期限もスクリプト内で指定しているので必要に応じて変更してください。 ※ amazondvd.rb を利用していた方へ。(必読) amazondvd.rb 上位互換です。 設定も同一です。特に変更するような追加設定項目は今のところありません。 amazondvd.rb のキャッシュがそのまま利用可能です。 amzcacheDVD の中身を amazon_shop へコピーすれば利用可能です。 書式も同一です。過去の日記を書き直す必要はありません。 ※ただし、amazon_shop.rb のキャッシュは amazondvd.rb では利用できません。 @@キャッシュ保持期間-------------------------------------------- キャッシュの有効期限を指定できます。 ndiary.conf にて 変数 AMAZON_CACHE_EXPIRE に日数(正の整数)を指定してください。 (0は無期限) (例) AMAZON_CACHE_EXPIRE = '30' @@プロキシ設定-------------------------------------------------- ndiary.conf で PROXY = 'proxy.hoge.com:8080' と指定しておくと、情報取得時プロクシを経由するようになります。 @@その他の設定-------------------------------------------------- ndiary.conf にて以下の変数が使用できます(必須ではない) * BOOKSTORE_AMAZON_ID(Amazonアソシエイトに参加している場合に有効) (例) BOOKSTORE_AMAZON_ID = 'hogehoge-foo' * NO_IMAGE_FILE ・ジャケット画像がない場合に代替に表示する画像(imgタグで表記) (例) NO_IMAGE_FILE='no image' * AMAZON_WITH_AP あれこれポップアップ(http://www.remus.dti.ne.jp/~a-satomi/bunsyorou/ArekorePopup.html) の ap:banner を使用したリンク表記を使う(true)か (例) AMAZON_WITH_AP = true *AMAZON_NOIMAGE_RETRY_SPAN 画像取得リトライ期間。 設定すると、前回日記生成時に画像がなかった商品について以下の動作をする。 日記生成時から AMAZON_NOIMAGE_RETRY_SPAN 日以上経過、 もしくは前回画像取得リトライから AMAZON_NOIMAGE_RETRY_SPAN 日以上経過していれば、 画像情報のみ取得し、キャッシュを更新する(キャッシュファイル生成日時は前回の状態を保持)。 設定しない場合、もしくは値が '0' の場合は無画像リトライは実行しない。 @@テンプレートにより表示をカスタマイズする----------------------- ndiary.conf に以下を設定 AMAZON_SHOP_TEMPLATE= true キャッシュディレクトリ(amazon_shop)以下に"template" という名前の テンプレートファイルを用意 テンプレートファイルの例ここから テンプレートファイルの例ここまで ※["画像","
  • ",""]は["小画像","
  • ",""]と書く事で小さい画像に変更できます。 次のような配列が置換対象。 ["キーワード","キーワードの前に置かれる文字列","キーワードの後に置かれる文字列"] * <-makerStr> * <-actorStr> * <-sizeStr> * <-sizeUnit> はテンプレート内で特殊な意味を持つ文字。 <-makerStr>は "メーカー"もしくは"アーティスト"(CD)もしくは"出版社"(本) <-actorStr>は "出演者"(DVDなど)もしくは"著者"(本) <-sizeStr> は "枚数"(CD,DVD)もしくは"サイズ"(本) <-sizeUnit> は"枚"(CD,DVD)もしくは "cm"(本) とメディアにあわせて自動できりかわる。 @@テンプレートを切替える---------------------------------------- amazon_shop のキャッシュディレクトリに複数のテンプレートファイルを用意する。 テンプレートファイルの名前は何でもよい。(default という名前は使用できない) 特定の商品に対しテンプレートを切替えたい場合以下のように記述。 (いつもの記述/テンプレートファイル名) ~~~~~~~~~~~~~~~~~~~~~~~ なお、"/テンプレートファイル名"は、 * 省略可能 * 省略時、AMAZON_SHOP_TEMPLATE= true だと "template" という名前のファイルが使用される * 省略時、"template" という名前のファイルがない場合は amazon_shop.rb デフォルトの表示 * "/default" と指定するとデフォルト表示 @@その他マイナーな設定---------------------------------------- 商品リンク(title 属性)文字列の変更 AMAZON_PRODUCT_LINK_STRING = '商品リンクへジャンプ(<-Media>)' <-Media> は特別な文字列です。自動で 本、CD、DVD などの商品メディアに変換されます。 @@ 非標準ライブラリの使用 image_size http://raa.ruby-lang.org/list.rhtml?name=image_size をインストールすると拡大画像の幅と高さをゲットするようになります。 @@ Special Thanx------------------------------------------------ == amazondvd.rb / amazon_shop.rb は以下の方の助力、影響、恩恵を受けています == - not (のとや) さん -- http://www14.cds.ne.jp/~not/ -- nDiary本体とamazon.rbの作者 -- amazon.rb のソースに少し変更を加えたものが amazondvd.rb そこからさらに発展したものが amazon_shop.rb - mas さん -- http://home3.highway.ne.jp/mas/ -- バグ報告や動作確認、Amazonアソシエイト対応など - Ace of Diamond さん -- http://every.pobox.ne.jp/ -- Amazonアソシエイト対応コード不具合パッチなど - amazondvd.rb / amazon_shop.rb 利用者の方々 @@ 注意事項------------------------------------------------------ 著作権がらみの情報を取得するため、 www.amazon.co.jpのアソシエイトプログラムを確認の上自己責任でご利用下さい。 =end class Module def attr_my_accessorshop( name ) module_eval %{ def #{name.id2name}() get_shopdata @#{name.id2name} end } end end class Amazon_shop require 'date' require 'ftools' require 'net/http' begin require 'yaml' rescue LoadError raise NDiaryFatalError, "Can't load yaml. please install 'yaml' or use ruby 1.8.x(amazon_shop.rb)" end attr_accessor :code_id attr_accessor :key #attr_accessor :skey attr_accessor :diary_day attr_accessor :cached_day, :retry_day attr_my_accessorshop :title attr_my_accessorshop :actor attr_my_accessorshop :maker attr_my_accessorshop :company attr_my_accessorshop :director attr_my_accessorshop :size attr_my_accessorshop :pubdate attr_my_accessorshop :price attr_my_accessorshop :desc attr_my_accessorshop :writer attr_my_accessorshop :edition attr_my_accessorshop :image_url attr_my_accessorshop :image_width attr_my_accessorshop :image_height attr_my_accessorshop :imageL_url attr_my_accessorshop :imageL_width attr_my_accessorshop :imageL_height attr_my_accessorshop :imageS_url attr_my_accessorshop :imageS_width attr_my_accessorshop :imageS_height attr_my_accessorshop :media attr_my_accessorshop :site attr_my_accessorshop :time attr_my_accessorshop :voice attr_my_accessorshop :voice_spec attr_my_accessorshop :caption attr_my_accessorshop :stand_in attr_my_accessorshop :screen_size attr_my_accessorshop :electro_spec attr_my_accessorshop :asin attr_reader :cache_dir attr_accessor :expire attr_accessor :proxy attr_accessor :noimage_retry_span def initialize @expire = 0 # 0だと存在するキャッシュを必ず使用 @noimage_retry_span = 0 # 画像取得リトライ期間 (0 だとリトライしない) @proxy = nil @flag = false @flag2 = false # true : ファイル修正時間を変更しないでキャッシュ保存する @image_get_flag = false @diary_day = Time.now @cached_day = Time.now @retry_day = Time.now @imageS_url = nil @imageS_width = nil @imageS_height = nil @maker = nil @company = nil @price = nil @writer = nil @desc = nil @writer = nil @desc = nil @writer = nil @desc = nil @company = nil @size = nil @desc = nil @writer = nil @imageL_url = nil @imageL_width = nil @imageL_height = nil @director = nil @site = nil @time = nil @voice = nil @voice_spec = nil @caption = nil @stand_in = nil @screen_size = nil @electro_spec = nil end def load_cache begin if @flag or (File::directory?(@cache_dir.to_s) and File::readable?(@cache_dir + @code_id) and File::mtime(@cache_dir + @code_id).to_i < Time::now.to_i - 3600 * 24 * @expire and @expire != 0) then return end rescue puts "cache_file= " + @code_id.to_s puts $! end @flag = true read_cache end def load_cache_old if @flag or (File::directory?(@cache_dir.to_s) and File::readable?(@cache_dir + @code_id) and File::mtime(@cache_dir + @code_id).to_i < Time::now.to_i - 3600 * 24 * @expire and @expire != 0) then return end @flag = true read_cache end def read_cache cache_file = @cache_dir + @code_id begin cache = File.open(cache_file,mode="r") str = YAML::load(cache) cache.close @title = str["商品タイトル"] @actor = str["出演者/著者"] @maker = str["メーカー"] # アーティスト、ジャンル、著作者 @company = str["販売元"] @size = str["枚数/サイズ"] @pubdate = str["発売日"] @price = str["価格"] @desc = str["解説"] @writer = str["解説者"] @image_url = str["画像URL"] @image_width = str["画像幅"] @image_height = str["画像高さ"] @imageL_url = str["拡大画像URL"] @imageL_width = str["拡大画像幅"] @imageL_height= str["拡大画像高さ"] @imageS_url = str["小画像URL"] @imageS_width = str["小画像幅"] @imageS_height= str["小画像高さ"] @media = str["メディア"] @director = str["監督"] @site = str["サイト"] @key = str["キー"] @time = str["再生時間"] @voice = str["音声"] @voice_spec = str["音声仕様"] @caption = str["字幕"] @stand_in = str["吹替え"] @screen_size = str["スクリーンサイズ"] @electro_spec = str["スペック"] @diary_day = str["日記記載日"] @cached_day = str["キャッシュした時間"] @asin = str["ASIN"] @edition = str["エディション"] @version = str["FILTER_VERSION"] @retry_day = str["画像取得リトライ日"] if @noimage_retry_span > 0 then # 前回取得時に画像情報得られなかった場合のみ再挑戦(1 回のみ) if @image_width.to_i <= 1 && ! @image_get_flag then @retry_day = @cached_day if @retry_day.to_s.empty? if (Date.today - Date.parse(@retry_day.to_s)) > noimage_retry_span then puts "RETRY; Get no image information." image_get @retry_day = Time.now @flag2 = true save_cache # 画像取得できたらキャッシュ保存 end end end rescue begin open(cache_file){ |f| @title, @actor, @maker, @size, @pubdate, @price, @desc, @writer, @image_url,@image_width, @image_height, @media, @director, @site, @key, @imageL_url, @time, @voice, @voice_spec, @caption, @stand_in, @screen_size, @electro_spec = f.read.split(/\t/) } if $DEBUG then puts "****** amazon_shop.rb is loading Old type cache. Please ignore yaml.rb Warnings. *******" end rescue puts @cache_dir + @code_id @flag = nil end end end def save_cache return unless File::directory?(@cache_dir.to_s) cache_file = @cache_dir + @code_id str = Hash[\ "商品タイトル",@title,\ "出演者/著者",@actor,\ "メーカー",@maker,\ "販売元",@company,\ "枚数/サイズ",@size,\ "発売日",@pubdate,\ "価格",@price,\ "解説",@desc,\ "解説者",@writer,\ "画像URL",@image_url,\ "画像幅",@image_width,\ "画像高さ",@image_height,\ "拡大画像URL",@imageL_url,\ "拡大画像幅",@imageL_width,\ "拡大画像高さ",@imageL_height,\ "小画像URL",@imageS_url,\ "小画像幅",@imageS_width,\ "小画像高さ",@imageS_height,\ "メディア",@media,\ "監督",@director,\ "サイト",@site,\ "キー",@key,\ "再生時間",@time,\ "音声",@voice,\ "音声仕様",@voice_spec,\ "字幕",@caption,\ "吹替え",@stand_in,\ "スクリーンサイズ",@screen_size,\ "スペック",@electro_spec,\ "日記記載日",@diary_day,\ "キャッシュした時間",@cached_day,\ "ASIN",@asin,\ "エディション",@edition,\ "画像取得リトライ日", @retry_day,\ "FilterVersion",Amazon_shopver\ ] stat = nil stat = File.stat(cache_file) if @flag2 cache = File.open(cache_file,mode="w") cache.write(str.to_yaml) cache.close File.utime(stat.atime, stat.mtime, cache_file) if @flag2 end def download(url, proxy) if /^http/ =~ url if $DEBUG then $stderr.puts "CHK; access; #{url}" end require 'net/http' domain, port = "", "" if /\/\/(.+?)(?:\/|$)/ =~ url domain = $1.to_s end protocol = url.split(":").first + "://" path = url.gsub(Regexp.new(protocol + domain),"") if proxy proxy, port = proxy.split(':') port = port.to_i else proxy = port = nil end begin http = Net::HTTP::Proxy(proxy, port).new(domain, 80) if /1\.6/ =~ RUBY_VERSION file_info, = http.get2(path) else file_info = http.get(path) end while file_info.code == '302' do path = file_info.header['location'].sub(Regexp.new(url), "") file_info = http.get(path) end return file_info.response.body , path rescue return $! end else return open(url, "rb").read,nil end end def image_get @image_get_flag = true if @image_url.to_s.empty? then # 強引に隠し画像情報をゲットしに行く save_info = [@image_url,@image_width,@image_height] @image_url,@image_width,@image_height = force_image_get("medium",save_info) end unless @image_url.to_s.empty? then # 取得した画像情報を調査する save_info = [@image_url,@image_width,@image_height] @image_url,@image_width,@image_height = force_image_get(@image_url.to_s,save_info) end #if @image_width.to_i <= 1 or @image_url.to_s.empty? then # return #else save_info = [@imageL_url,@imageL_width,@imageL_height] @imageL_url,@imageL_width,@imageL_height = force_image_get("large",save_info) save_info = [@imageS_url,@imageS_width,@imageS_height] @imageS_url,@imageS_width,@imageS_height = force_image_get("small",save_info) #end end def force_image_get(type,save_info) image_info = save_info begin require 'lib/imagesize' rescue LoadError return image_info end amazon_img_url = 'http://images-jp.amazon.com/images/P/' # small http://images-jp.amazon.com/images/P/ASIN.09.THUMBZZZ.jpg # medium http://images-jp.amazon.com/images/P/ASIN.09.MZZZZZZZ.jpg # large http://images-jp.amazon.com/images/P/ASIN.09.LZZZZZZZ.jpg url_img = "" case type when /large/i suffix = "LZZZZZZZ" when /medium/i suffix = "MZZZZZZZ" when /small/i suffix = "THUMBZZZ" #suffix = "TZZZZZZZ" when /http/ url_img = type else return image_info end begin if url_img.to_s.empty? then url_img = amazon_img_url + @asin + ".09." + suffix + ".jpg" end suffix = url_img.split(".").last downloadImgFile = File.join(@cache_dir,"amazon_shop_tmp.#{suffix}") downloadImg = File.open(downloadImgFile,"w") downloadImg.puts download(url_img,proxy) downloadImg.close #imageBin, = download(url_img,proxy) #image = ImageSize.new(imageBin) # <= lib/imagesize.rb 参照。2005-6-28(Tue) w, h = ImageSize::size(downloadImgFile) # <= lib/imagesize.rb 参照。2005-6-28(Tue) #if w.to_i > 10 && h.to_i > 10 then url_img, w, h = nil, nil, nil if w <= 1 || h <= 1 image_info = [url_img,w,h] #end return image_info rescue return image_info end end def cache_dir=(dir) dir << '/' unless dir[-1,1] == '/' @cache_dir = dir end def media_get(str) featured_system="プラットフォーム:.*?\n \n(.*?)\n
    |sm =~ str then @media = @media + "(#{$1})" end end #エレクトロニクスカテゴリー取得(未完成) if /商品/ =~ @media then if %r!同じ種類の商品を探す(.*)!smi =~ str then media_scope = $1 # if %r!
  • (.+?)
  • !smi =~ media_scope then # media_scope = $1 #なぜかこうしないとスコープがしぼれない…… # end end if %r!カテゴリー別.+?(.+?)!smi =~ media_scope then @media = $1.delete("\n") end end return @media end def asin_phase path = "/exec/obidos/ASIN/#{code_id.delete("-")}/250-0959300-8075455?val=authorized" url = "www.amazon.co.jp" path = "http://" + url + path download(path,proxy) end def dvd_phase path = "/exec/obidos/search-handle-url/index=dvd-jp%26field-keywords=#{code_id}" url = "www.amazon.co.jp" path = "http://" + url + path download(path,proxy) end def cd_phase path = "/exec/obidos/search-handle-url/index=music-jp%26field-keywords=#{code_id}" url = "www.amazon.co.jp" path = "http://" + url + path download(path,proxy) end def blend_phase path = "/exec/obidos/search-handle-url/index=blended%26field-keywords=#{code_id}" url = "www.amazon.co.jp" path = "http://" + url + path download(path,proxy) end def playstation_phase path = "/php/item/#{code_id}" url = "www.jp.playstation.com" path = "http://" + url + path response,path = download(path,proxy) if %r|(\w+)| =~ response then keyword_trade = $1 if %r|発売日\n([\d\/]+[\d])|s =~ response then keyword_date = $1 end keyword = "イメージを拡大" + " " + keyword_date.to_s + " " + keyword_trade.to_s + " playstation" else keyword = "" end return(keyword) end def google_phase(keyword) skey = keyword.gsub(/\ /,'%2b') # Google!! # ' ' ===> %20 ; '?' ===> %3f ; '+' ===> %2b ; '%' ===> %25 # '&' ===> %26 ; '=' ===> %3d ; '/' ===> %2f ; ':' ===> %3a url = "www.google.com" path = "/search%3fhl=ja%26inlang=ja%26ie=Shift_JIS%26q=site%3Awww.amazon.co.jp%2b#{skey}" path = "http://" + url + path download(path,proxy) if %r|.+]+)>Amazon.co.jp:| =~ response then path2 = $1 return(path2) end end def get_shopdata load_cache return if @flag code_id = @code_id s = @skey key = @key if /asin|isbn/i =~ key then response,path = asin_phase path = "http://www.amazon.co.jp/exec/obidos/ASIN/#{code_id.delete("-")}" path2 = "/exec/obidos/ASIN/#{code_id.delete("-")}" else got_data = true response, path2 = blend_phase if %r|^
  • \n(?:)?.*(?:)?
    .*注文した商品はどこ[??])|sm =~ response then #if %r|(^.*注文した商品はどこ[??])|sm =~ response then image_scope = $1 end #-------------------------------------------------- # DVD Spec #-------------------------------------------------- if %r|
    仕様について| =~ response then path3=$1 url = "www.amazon.co.jp" path3 = "http://" + url + path3 response_spec, = download(path3,proxy) if %r|時間:([^<]+)<| =~ response_spec then @time = $1 end if %r|音声仕様:([^<]+)<| =~ response_spec then @voice_spec = $1 end if %r|音声:([^<]+)<| =~ response_spec then @voice = $1 end if %r|字幕:([^<]+)<| =~ response_spec then @caption = $1 end if %r|吹き替え:([^<]+)<| =~ response_spec then @stand_in = $1 end if %r|画面サイズ:([^<]+)<| =~ response_spec then @screen_size = $1 end if %r|発売日:([^<]+)<| =~ response_spec then @pubdate = $1 end if %r|販売元:(.+?)<| =~ response_spec then # @maker = $1 @company = $1 end end #-------------------------------------------------- # PC/エレクトロニクス Spec #-------------------------------------------------- #if %r|(?:製品概要・)?仕様[::](.*?)|m =~ response then # @electro_spec = $1.gsub(/\n/,"").gsub(/(<\/?font.*?>|<\/?span.+?>||.+?<\/a>)/,"") #end # エレクトロニクスのスペックがうるさいなら上のコメントをはずして # ここから if %r|]+?)"?>詳しい情報を見る|m =~ image_scope then #" path3 = $1 url = "http://www.amazon.co.jp" + path3.to_s response_spec, = download(url,@proxy) if %r!製品概要・仕様:.+?(
      .*
    )!m =~ response_spec @electro_spec = $1.gsub(/\n/,"").gsub(/(<\/?font.*?>|<\/?span.+?>)/,"") end else if %r|(?:製品概要・)?仕様[::](.*?)|m =~ response then @electro_spec = $1.gsub(/\n/,"").gsub(/(<\/?font.*?>|<\/?span.+?>||.+?<\/a>)/,"") end end # エレクトロニクスのスペックがうるさいならここまでをコメントにする path = path.gsub!("http://www.amazon.co.jp","") #-------------------------------------------------- # Title #-------------------------------------------------- #Amazon.co.jp:ゲーム: 東北大学未来科学技術共同研究センター 川島隆太教授 監修 脳力トレーナー ポータブル #if %r|^Amazon.co.jp:(?:[^:]+:)?(.+?)$| =~ response then if %r|^Amazon.co.jp:(?:[^::]+[::])?(.+?)$| =~ response then title_str = $1.strip # @title = "#{title_str}" @title = title_str else @title = "Not Found #{code_id}" save_cache return if @title end #-------------------------------------------------- # CD,DVD or PS2? #-------------------------------------------------- if /isbn/i =~ key then if %r|^Amazon.co.jp:([^::]+)[::]| =~ response then @media = $1.strip end else if %r|この(\w+)に\w+レビューを書|s =~ response then @media = $1 if @media =~ /商品/ then media_get(response) end else media_get(response) end end #-------------------------------------------------- # ASIN #-------------------------------------------------- if /asin|isbn/ =~ @key @asin = @code_id else if %r!! =~ response then @asin = $1 end end #-------------------------------------------------- # Image #-------------------------------------------------- #if %r|.+(?:[^<]+)?)| =~ response then maker0 = $1.gsub(/  |, ' / ') else if %r!()! =~ image_scope then @maker = $1 end if @maker.nil? && /dvd/i !~ @media then if %r!nbsp;([^>]+) +- +ASIN[::]! =~ image_scope then @maker = $1 end end end end if %r!^出版社: (.+)! =~ image_scope then @actor = @maker @maker = $1 if %r|^.*;([^<]+)|m =~ image_scope then comic = $1 @maker = @maker + "(" + comic + ")" end end #-------------------------------------------------- # 販売元 #-------------------------------------------------- if @company.nil? then if %r|>(.+?) ?- ASIN:.+?|i =~ image_scope then @company = $1 end end #-------------------------------------------------- # Price #-------------------------------------------------- if %r|定価:
    \n.+?[^¥]+(¥[\d,]+)|m =~ image_scope then @price = $1 end # 定価表示ではなく価格のみ表示の場合 if @price.nil? then if %r|価格:[^¥]+(¥[\d,]+)| =~ image_scope then @price = $1 elsif %r|(¥[\d,]+)
    |m =~ image_scope then @price = $1 elsif %r|(¥[\d,]+).+?|m =~ image_scope then @price = $1 end end #-------------------------------------------------- # Actor #-------------------------------------------------- if %r|出演: (.+?)
    \n|m =~ response then @actor = $1.gsub(/\n+/,"") end #-------------------------------------------------- # Director #-------------------------------------------------- if %r|監督: (.*)| =~ response then @director = $1 end #-------------------------------------------------- # Edition(本) #-------------------------------------------------- if /本/s =~ @media then if %r|エディション:\n(.+?)\n
    |m =~ response then @edition = $1 end end #-------------------------------------------------- # Description #-------------------------------------------------- if %r'
    レビュー
    (.*)'mis =~ response then review_scope = $1 end # 何種類かあるみたい… if %r"(出版社/著者からの内容紹介|メーカーより|作品内容|内容(「.+?」データベースより))
    +
    +
    +(.+?) *<[pP]>"s =~ review_scope then @writer =$1 @desc = $2 end if %r!(出版社/著者からの内容紹介|商品紹介|メーカーより|作品内容|内容(「.+?」データベースより))

    \n+(.+?)(?:

    ...)?
    !mis =~ review_scope then @writer =$1 @desc = $2 end if @writer.to_s.empty? and @desc.to_s.empty? then if %r"(メーカーより|作品内容|内容紹介|出版社/著者からの内容紹介|内容(「.+?」データベースより))
    +(.*)

    (?:.*

    )+"s =~ review_scope.to_s.gsub(/\n/,'') then @writer =$1 @desc = $2 end end if @writer.to_s.empty? and @desc.to_s.empty? then if %r"(作品内容|内容(「.+?」データベースより))
    \n(.*?)"mis =~ review_scope then @writer =$1 @desc = $2 end end if @writer.to_s.empty? and @desc.to_s.empty? then if %r|(製品概要)[::](.*?)|mi =~ review_scope then @writer = $1 @desc = $2 end end #-------------------------------------------------- # Published Date #-------------------------------------------------- #(2002/05/24)
    :DVD,CD #発売日:2002/03/28
    :PS2 if %r"(?:発売日[::]|\()([\d\/]+[\d])\)?
    " =~ response then @pubdate = $1 elsif %r|\((\d{4}\/[\d\/]+)\)| =~ response then @pubdate = $1 end #-------------------------------------------------- # Size(ディスク枚数) #-------------------------------------------------- if %r!(?:)?ディスク枚数:(?:)?(.+)
    ! =~ response then @size = $1.gsub(/[^\d]/,"") elsif %r!サイズ\(cm\): ([^<]*)(.+?)/)[0]} title=\"#{column_str}の作品\">#{column_str}#{each_column.scan(/(\(.+?\))/)[0].to_s}" column_str_with_link = "#{each_column.scan(/(/)[0]} title=\"#{column_str}の作品\">#{column_str}#{each_column.scan(/(\(.+?\))/)[ column_str.count( '(' ) ].to_s}" else column_str_with_link = each_column end href_added_title << column_str_with_link } return href_added_title.join(",") end def amazon_shop(str, type) tagend = (@diary.isXHTML ? ' />' : '>') amazon_id = '' expire = '' no_img = '

    No Image
    ' noimage_retry_span = 0 product_link_title = "この <-Media> について" if @diary.respond_to?('config') then proxy = @diary.config['PROXY'] amazon_id = @diary.config['BOOKSTORE_AMAZON_ID'].to_s expire = @diary.config['AMAZON_CACHE_EXPIRE'].to_s no_img = @diary.config['NO_IMAGE_FILE'].to_s unless @diary.config['NO_IMAGE_FILE'].to_s.empty? no_imgS = @diary.config['NO_IMAGE_FILE_S'].to_s unless @diary.config['NO_IMAGE_FILE_S'].to_s.empty? media_icon = @diary.config['AMAZON_MEDIA_ICON'] noimage_retry_span = @diary.config['AMAZON_NOIMAGE_RETRY_SPAN'] unless @diary.config['AMAZON_NOIMAGE_RETRY_SPAN'].to_s.empty? product_link_title = @diary.config['AMAZON_PRODUCT_LINK_STRING'] unless @diary.config['AMAZON_PRODUCT_LINK_STRING'].to_s.empty? end begin case type when :P, :UL, :DL #str.gsub!(/[\((][@@](CD|DVD|PS|PS2|GC|XBOX|GBA|ASIN|ISBN)[::](.+)[\))]/mi){ #str.gsub!(/[\((][@@](CD|DVD|PS|PS2|GC|XBOX|GBA|ASIN|ISBN)[::](.+?)(\/.+?)?[\))]/mi){ str.gsub!(/\(@(CD|DVD|PS|PS2|PSP|GC|GBA|NDS|XBOX|ASIN|ISBN):(.+?)(\/.+?)?\)/i){ key = $1 code_id = $2 template_file = $3.to_s.gsub("/","") amzshop = Amazon_shop::new amzshop.cache_dir = @diary.logDirectory + 'amazon_shop' amzshop.code_id = code_id amzshop.key = key amzshop.proxy = proxy amzshop.diary_day = @diary.date # キャッシュの有効日数 if expire.empty? then amzshop.expire = 0 else amzshop.expire = expire.to_i end if ! noimage_retry_span.to_s.empty? amzshop.noimage_retry_span = noimage_retry_span.to_i end # テンプレート template = "" if /default/ !~ template_file then if @diary.config['AMAZON_SHOP_TEMPLATE'] then template_fp = amzshop.cache_dir + File::Separator + 'template' if ! template_file.empty? then template_fp = amzshop.cache_dir + File::Separator + template_file if ! FileTest.exist?(template_fp) then template_fp = amzshop.cache_dir + File::Separator + 'template' end end if FileTest.exist?(template_fp) then template = open(template_fp,"r").read end end else template = "" end title = body = img = desc = media = maker = actor = director = size = writer = desc = site = largeimage = asin = titlewithasin = pubdate = price = date_price_size = time = voice_spec = voice = caption = stand_in = screen_size = electro_spec = imgS = product_url = ap_banner ='' if /Not Found/ =~ amzshop.title then print @diary.date.to_s print "\tamazon_shop error.#{amzshop.title}\n" return 1 end if ! amzshop.title.nil? product_title = amzshop.title unless amzshop.title.to_s.empty? if /^(.+?) 1 || imageM_h.to_i > 1) then if /_P._SC/ =~ imageM then imageM = imageM.gsub(/_P._SC/,"").gsub(/_\.jpg/,".jpg") end valiation = "" base_extention_w = 0 base_extention_h = 0 rotate_angle = 90 if ! @diary.config['AMAZON_IMAGE_VARIATION'].to_s.empty? valiation = @diary.config['AMAZON_IMAGE_VARIATION'] valiation.split("_").each{|param| total_w = 0 total_h = 0 #_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_PU90_PF_SCMZZZZZZZ_.jpg case param when /^PA/ #ドロップシャドウ param.gsub!(/^PA/,"") arg1 = param.split(",")[0].to_i.abs # 余白ピクセルサイズ arg2 = param.split(",")[1].to_i.abs # x 方向影ピクセルサイズ arg3 = param.split(",")[2].to_i.abs # y 方向影ピクセルサイズ arg4 = param.split(",")[3].to_i.abs # シャープさ加減 total_w = arg1 + arg2 total_h = arg1 + arg3 when /^PU/ # 左回転 param.gsub!(/^PU/,"") arg1 = param.to_i arg1 = 5 if arg1 == 0 # blank:5 rotate_angle += arg1 when /^PV/ # 右回転 param.gsub!(/^PV/,"") arg1 = param.to_i arg1 = 5 if arg1 == 0 # blank:5 rotate_angle -= arg1 end base_extention_w += total_w base_extention_h += total_h } end imageS = imageM.gsub(/MZZZZZZZ.jpg/,"_AA50_SCMZZZZZZZ_.jpg") imageL = imageM.gsub(/MZZZZZZZ.jpg/,"_SCLZZZZZZZ_.jpg") # M x 3.4 imageM = imageM.gsub(/MZZZZZZZ.jpg/,"#{valiation}_SCMZZZZZZZ_.jpg") imageL_title = "拡大イメージ(#{(imageM_w.to_f*3.4).to_i}x#{(imageM_h.to_f*3.4).to_i})" # イメージバリエーション後のサイズ計算 imageM_w += base_extention_w imageM_h += base_extention_h pi = 3.14159265358979 rad = pi*(rotate_angle.to_f)/180.to_f xdir = Math.cos(rad).abs * imageM_h + Math.sin(rad).abs * imageM_w ydir = Math.sin(rad).abs * imageM_h + Math.cos(rad).abs * imageM_w imageM_w = xdir imageM_h = ydir img = %Q'#{product_title}' end if @diary.config['AMAZON_WITH_AP'] then ap_banner = " ap:banner=\"#{imageS}\"" end title = %Q'#{product_title}' title = title.gsub(/<-Media>/,"#{media}") unless media.to_s.empty? # maker = メーカー maker = add_title(amzshop.maker) unless amzshop.maker.to_s.empty? # company = 販売元 company = amzshop.company unless amzshop.company.to_s.empty? # actor = 出演者 actor = add_title(amzshop.actor) unless amzshop.actor.to_s.empty? # director = 監督 director = add_title(amzshop.director) unless amzshop.director.to_s.empty? # pubdate = 発売日 pubdate = amzshop.pubdate unless amzshop.pubdate.to_s.empty? # price = 価格 price = amzshop.price.gsub(/¥/,'\\') unless amzshop.price.to_s.empty? # size = 枚数 (CD,DVD) size = amzshop.size.gsub(/ /,'') unless amzshop.size.to_s.empty? # time = 再生時間 (CD,DVD) time = amzshop.time unless amzshop.time.to_s.empty? # desc = 内容記述 desc = amzshop.desc.gsub(/\/exec/,"http:\/\/www.amazon.co.jp\/exec") unless amzshop.desc.to_s.empty? if //i,"") end # writer = desc のライター(「DVD NAVIGATOR」データベースより ...など) writer = amzshop.writer unless amzshop.writer.to_s.empty? # site = obsolete (google とかだった) site =amzshop.site unless amzshop.site.to_s.empty? # voice = 音声(英語/日本語 ...など) voice = amzshop.voice unless amzshop.voice.to_s.empty? # voice_spec = 音声仕様 (Dolby Digital 5.1/Dolby Digital 5.1 ...など) voice_spec = amzshop.voice_spec unless amzshop.voice_spec.to_s.empty? # caption = 字幕 (日本語/英語/日本語吹き替え用字幕 ...など) caption = amzshop.caption unless amzshop.caption.to_s.empty? # stand_in = 吹き替え stand_in = amzshop.stand_in unless amzshop.stand_in.to_s.empty? # screen_size = 画面サイズ (シネマスコープ ...など) screen_size = amzshop.screen_size unless amzshop.screen_size.to_s.empty? # electro_spec = エレクトロニクススペック electro_spec = amzshop.electro_spec unless amzshop.electro_spec.to_s.empty? # edition = エディション edition = amzshop.edition unless amzshop.edition.to_s.empty? if desc.size > 100 then desc.gsub!(/(.{100}.+?)
    .*/mi){ $1 + %Q'(...)' } end if electro_spec.size > 100 then electro_spec.gsub!(/.+?(
  • .+?
  • .+?
  • .+?)
  • .*/mi){ $1 + %Q'(...)' } end info_hash = { "商品タイトル" => title, "出演者/著者" => actor, "メーカー" => maker, "販売元" => company, "枚数/サイズ" => size, "発売日" => pubdate, "価格" => price, "解説" => desc, "解説者" => writer, "画像" => img, "小画像" => imgS, "メディア" => media, "監督" => director, "再生時間" => time, "音声" => voice, "音声仕様" => voice_spec, "字幕" => caption, "吹替え" => stand_in, "スクリーンサイズ" => screen_size, "スペック" => electro_spec, "キー" => key, "エディション" => edition, "コード" => code_id } if /本|洋書/ =~ media then makerStr = "出版社" actorStr = "著者" sizeStr = "サイズ" sizeUnit = " cm" else if /CD/ =~ media then makerStr = "アーティスト" else makerStr = "メーカー" end actorStr = "出演者" sizeStr = "枚数" sizeUnit = " 枚" end body = Array.new if ! template.empty? then template.tosjis.each{|line| unless /^#/ =~ line then line.gsub!(/(\[.+?\])/){ eval_str = $1 hash_key, before, after = eval eval_str hash_item = info_hash[hash_key] before + hash_item + after unless hash_item.to_s.empty? } line.gsub!(/<-makerStr>/,makerStr) line.gsub!(/<-actorStr>/,actorStr) line.gsub!(/<-sizeStr>/,sizeStr) line.gsub!(/<-sizeUnit>/,sizeUnit) line.chop! body << line if ! line.empty? end } else media = "#{edition}" if ! edition.to_s.empty? body << "

    " body << %Q!\t
    ! body << %Q!\t! body << "\t" body << "\t\t" body << "\t\t" body << "\t" body << "\t
    " body << "\t\t\t#{img}" body << "\t\t" body << "\t\t\t『#{title}』" body << "\t\t\t#{media}#{@diary.tag_br}" body << "\t\t\t#{maker}#{@diary.tag_br}" unless maker.empty? body << "\t\t\t#{company}#{@diary.tag_br}" unless company.to_s.empty? body << "\t\t\t#{actorStr}:#{actor}#{@diary.tag_br}" unless actor.empty? body << "\t\t\t監督:#{director}#{@diary.tag_br}" unless director.empty? date_price_size_time = Array.new date_price_size_time << "発売日:" + pubdate unless pubdate.to_s.empty? date_price_size_time << "価格:" + price unless price.to_s.empty? date_price_size_time << sizeStr + ":" + size + sizeUnit unless size.to_s.empty? date_price_size_time << "時間:" + time unless time.to_s.empty? dpst = date_price_size_time.join(", ") body << "\t\t\t#{dpst}#{@diary.tag_br}#{@diary.tag_br}" unless dpst.empty? body << "\t\t\t音声:#{voice}#{@diary.tag_br}" unless voice.empty? body << "\t\t\t音声仕様:#{voice_spec}#{@diary.tag_br}" unless voice_spec.empty? body << "\t\t\t字幕:#{caption}#{@diary.tag_br}" unless caption.empty? body << "\t\t\t吹き替え:#{stand_in}#{@diary.tag_br}" unless stand_in.empty? body << "\t\t\t画面サイズ:#{screen_size}#{@diary.tag_br}" unless screen_size.empty? body << "\t\t\t
    • 仕様:#{electro_spec}
    " unless electro_spec.empty? body << "\t\t\t--#{writer}--#{@diary.tag_br}" unless writer.empty? body << "\t\t\t#{desc}#{@diary.tag_br}" unless desc.empty? body << "\t\t
    " body << "" end body << "\t" body << "\t" body << "\t

    " if template.empty? body << "" end body.join("\r\r").to_s.gsub(/&field/,"%26field").gsub(/^ +\n/m,"") } when :HTML str.gsub!("\r\r","\n") str.gsub!(/\s*<\/p>/mi, '') end rescue puts "#{$!}" end end end =begin Local Variables: mode: ruby coding: japanese-shift-jis-dos End: =end