require "nori"
module NicoQuery
module ObjectMapper
class MylistRSS
attr_reader :meta, :items
def initialize(xml)
parser = Nori.new
parsed_xml = parser.parse xml
entire = parsed_xml['rss']['channel']
@meta = Meta.new entire, title_prefix
@items = entire['item'].map { |item| Item.new item }
end
def title_prefix
"マイリスト"
end
class Meta
def initialize(parsed_xml, title_prefix)
@title_prefix = title_prefix
@hash = parsed_xml
end
def title
@hash['title']
.scan(/(?<=#{@title_prefix}\s).+(?=\‐ニコニコ動画)/)[0].split(' ')[0]
# .force_encoding('utf-8')
end
def url
link
end
def link
@hash['link']
end
def mylist_id
@hash['link'].scan(/(?<=mylist\/)\d{1,}/)[0].to_i
end
def description
@hash['description']
end
def publish_date
Time.parse @hash['publish_date']
end
def last_build_date
Time.parse @hash['lastBuildDate']
end
def creator
@hash['dc:creator']
end
end
class Item
#
おまえら、みっくみくにしてやんよ。歌詞はhttp://ikamo.hp.infoseek.co.jp/mikumiku.txt(9/20 1:55修正)。上げている他のもの→mylist/1450136
1:38|2007年09月20日 01:22:02 投稿
再生:10,643,217 コメント:2,726,450 マイリスト:210,310
]]> # def initialize(parsed_xml) @hash = parsed_xml end def title @hash['title'] end def video_id (url.scan(/((sm|nm)\d{1,})/).map {|e| e[0]})[0] end def url @hash['link'] end def thread_id @hash['guid'].scan(/(?<=watch\/)\d{1,}$/)[0].to_i end def publish_date Time.parse @hash['pubDate'] end def thumbnail_url description.raw_text.scan(/(?<=src\=\").{1,}(?=\"\swidth)/)[0] $& end def view_counter description.raw_text.scan(/(?<=nico-numbers-view\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i end def comment_num description.raw_text.scan(/(?<=nico-numbers-res\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i end def mylist_counter description.raw_text.scan(/(?<=nico-numbers-mylist\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i end def description @_description ||= Description.new @hash['description'] end def length description.raw_text.scan(/(?<=class\=\"nico\-info\-length\"\>)\d{1,}\:\d{1,2}(?=\<\/strong\>)/) length_string = $&.to_s.split(':') length_string[0].to_i * 60 + length_string[1].to_i end class Description attr_reader :raw_text def initialize(raw_text) @raw_text = raw_text.to_s end def text @raw_text.scan /(?<=class\=\"nico\-description\"\>).{1,}(?=\<\/p\>)/ $& end def movie_references # is this the high road? text.scan(/((sm|nm)\d{1,})/).map {|e| e[0]} end def mylist_references text.scan /(?<=mylist\/)\d{1,}/ end def community_references text.scan /co\d{1,}/ end def seiga_references text.scan /im\d{1,}/ end end end # #おまえら、みっくみくにしてやんよ。歌詞はhttp://ikamo.hp.infoseek.co.jp/mikumiku.txt(9/20 1:55修正)。上げている他のもの→mylist/1450136
1:38|2007年09月20日 01:22:02 投稿
]]>レッツゴー!陰陽師(フルコーラスバージョン)
5:19|2007年03月06日 00:33:00 投稿
]]>