require "nori" module NicoQuery module ObjectMapper class GetThumbInfo def initialize(xml) @xml = xml parser = Nori.new parsed_xml = parser.parse xml @hash = parsed_xml['nicovideo_thumb_response']['thumb'] end def video_id @hash['video_id'] end def title @hash['title'] end def description @_description ||= Description.new @hash['description'] end def thumbnail_url @hash['thumbnail_url'] end def first_retrieve @hash['first_retrieve'].to_time end def publish_date # alias first_retrieve end def length string = @hash['length'].split(':') string[0].to_i * 60 + string[1].to_i end def movie_type @hash['movie_type'] end def size_high @hash['size_high'].to_i end def size_low @hash['size_low'].to_i end def view_counter @hash['view_counter'].to_i end def comment_num @hash['comment_num'].to_i end def mylist_counter @hash['mylist_counter'].to_i end def last_res_body @hash['last_res_body'] end def url @hash['watch_url'] end def watch_url @hash['watch_url'] end def thumb_type @hash['thumb_type'] end def embeddable @hash['embeddable'] == 1 end def no_live_play @hash['no_live_play'] == 1 end def tags xml = @xml.scan(/\\n.+\n\<\/tags\>/m)[0] parsed = Nokogiri::XML xml parsed.xpath("//tag").map do |tag_object| generate_tag_hash_by tag_object end end def user_id @hash['user_id'].to_i end private def generate_tag_hash_by(nokogiri_xml) text = nokogiri_xml.text lock = if nokogiri_xml.attributes['lock'].present? nokogiri_xml.attributes['lock'].text.to_i == 1 else false end { text: text, lock: lock } end class Description attr_reader :raw_text def initialize(raw_text) @raw_text = raw_text.to_s end def text @raw_text 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,}/).map(&:to_i) end def community_references text.scan(/co\d{1,}/) end def seiga_references text.scan(/im\d{1,}/) end end end end end # # # sm9 # 新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師 # レッツゴー!陰陽師(フルコーラスバージョン) # http://tn-skr2.smilevideo.jp/smile?i=9 # 2007-03-06T00:33:00+09:00 # 5:19 # flv # 21138631 # 17436492 # 13536149 # 4148196 # 133688 # へん? はははははははははは wwwwwwwwwwwwwwwwwwww ... # http://www.nicovideo.jp/watch/sm9 # video # 1 # 0 # # 陰陽師 # レッツゴー!陰陽師 # 公式 # 音楽 # ゲーム # β時代の英雄 # 運営のお気に入り # 最古の動画 # 1000万再生 # 弾幕動画 # # 4 # #