Pragger で Pixiv
PraggerでPixivのフィード作るのは簡単だった。
- module: Feed::custom_feed
config:
url: http://www.pixiv.net/index.php?tag=C74
split: "<li>(<a\\ href=\"index\\.php\\?mode=medium&illust_id=\d+?\"><img\\ src=\"http.+?\"\\ border=\"0\"\\ /></a><br\\ /><div\\ class=\"pdgTop5\">.+?</div>)</li>"
title: "<div\\ class=\"pdgTop5\">(.+?)</div>"
- module: Filter::subs
config:
regex: "(index\\.php)"
to: "http://www.pixiv.net/member_illust.php"
- module: Feed::custom_feed
config:
link: "<a\\ href=\"(http://www.pixiv.net/member_illust.php\\?mode=medium&illust_id=\d+?)\">"
- module: RSS::save
config:
title: An Title
link: http://www.example.com/hoge.rdf
description: sample rdf
filename: sample.xml
あとはファイルをダウンロードするプラグインが欲しいなあ。
ちなみに、PraggerのFeed::custom_feedの config['link'] はバグじゃないだろうか…。
diff -Naru pragger.orig/plugin/Feed/custom_feed.rb pragger/plugin/Feed/custom_feed.rb
--- pragger.orig/plugin/Feed/custom_feed.rb 2008-06-09 20:51:07.000000000 +0900
+++ pragger/plugin/Feed/custom_feed.rb 2008-06-09 20:52:03.000000000 +0900
@@ -68,7 +68,7 @@
end
end
- if config['link'] and config['url']
+ if config['link']# and config['url']
link = Regexp.new(config['link'])
items.each do|i|
if i =~ link
以下は古い情報
Pragger で Pixiv のRSSを生成するプラグインを書いた。
## Read Pixiv Pictures -- Yuanying
##
## Read Pixiv Pictures with tag.
##
## for example you can get your search tag 'C74'
##
## - module: Feed::pixiv_tag
## config:
## id: yuanying
## password: password-dayo
## tag: C74
##
require 'rubygems'
require 'mechanize'
require 'cgi'
require "rss/maker"
def pixiv_tag(config, data)
agent = WWW::Mechanize.new
agent.user_agent_alias = 'Windows IE 6'
page = agent.get("http://www.pixiv.net/tags.php?tag=#{CGI.escape(config['tag'])}")
sleep 1
agent.post('http://www.pixiv.net/index.php',
{
'pixiv_id' => config['id'],
'pass' => config['password']
}
)
sleep 1
rss = RSS::Maker.make("1.0") do |maker|
page.links.each do |link|
if !link.href.nil? && link.href.index('index.php?mode=medium') == 0
url = "http://www.pixiv.net/#{link.href.gsub('index.php', 'member_illust.php')}"
p = agent.get(url)
item = maker.items.new_item
item.title = p.title
item.link = url
item.author = p.root.at('#profile div').inner_text rescue 'Error'
comment = p.root.at('#illust_comment').inner_text rescue 'Error'
image = link.node.to_html
# item.description = comment
item.description = "<p>#{image}</p><p>#{comment}</p>"
item.date = Time.now
data << item
sleep 1
end
end
end
return data
end
たとえばこんな感じのRSSを出力できる。
けど、なんか違う感じなんだよなー…。
PlaggerならわざわざPixiv用のプラグインを書かなくても 設定ファイルいじるだけで生成できるし。