#! /bin/sh

isbn=$1
aid='p-sarumaru60427'

search=`/usr/local/bin/wget -q -O /dev/stdout --cookies=on "http://www.bk1.co.jp/cgi-bin/srch/srch_result_book.cgi?idx=3&isbn=$isbn" | nkf -eZ1`
#search=`cat bk1 | nkf -eZ1`
bib=`echo "$search" | sed -E '1,/(分売可|非全集)/d`
bibid=`echo "$bib" | sed -E -n '/書名/,$d; /bibid/s/^.*bibid=//;s/&.*$//p'`
title=`echo "$bib" | sed -E -n '1,/書名/d; /著者/,$d; /href/s/^[^>]*>//;s/<\/a>.*$//p'`
author=`echo "$bib" | sed -E -n '1,/著者/d; /出版社/,$d; /<br>/s/ //g; s/(著)?(<\/a>)?<br>//p'`
publisher="("`echo "$bib" | sed -E -n '1,/出版社/d; /書評数/,$d; /<br>/s/ //g; s/(著)?(<\/a>)?<br>//p'`")"
#echo $publisher
#echo "$bibid"
#echo "$title"
#echo "$author"
series=`echo $title | sed -E -n '/\(/s/^.*(\(.*\)).*$/\1/p'`
title=`echo $title | sed -E 's/\(.*$//; s/ ([0-9]*$)/ (\1)/'`
#echo $title
#echo $series
if [ -z "$series" ] ; then comment=$publisher ; else comment=$series; fi
echo -n "$title / $author $comment ["
echo -n "<A href=\"http://www.bk1.co.jp/cgi-bin/srch/srch_detail.cgi?aid=$aid&amp;bibid=$bibid\">ISBN$isbn</A>"
echo "]"

