require "nori" require "nicoquery/object_mapper/description" 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 deleted? if @parsed_xml['nicovideo_thumb_response']["error"].presence @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence == "DELETED" else false end end def video_id return nil if @hash == nil @hash['video_id'] end def title return nil if @hash == nil @hash['title'] end def description @_description ||= Description.new @hash['description'] end def thumbnail_url return nil if @hash == nil @hash['thumbnail_url'] end def first_retrieve return nil if @hash == nil @hash['first_retrieve'].to_time end def publish_date # alias first_retrieve end def length return nil if @hash == nil string = @hash['length'].split(':') string[0].to_i * 60 + string[1].to_i end def movie_type return nil if @hash == nil @hash['movie_type'] end def size_high return nil if @hash == nil @hash['size_high'].to_i end def size_low return nil if @hash == nil @hash['size_low'].to_i end def view_counter return nil if @hash == nil @hash['view_counter'].to_i end def comment_num return nil if @hash == nil @hash['comment_num'].to_i end def mylist_counter return nil if @hash == nil @hash['mylist_counter'].to_i end def last_res_body return nil if @hash == nil @hash['last_res_body'] end def url return nil if @hash == nil @hash['watch_url'] end def watch_url return nil if @hash == nil @hash['watch_url'] end def thumb_type return nil if @hash == nil @hash['thumb_type'] end def embeddable return nil if @hash == nil @hash['embeddable'] == 1 end def no_live_play return nil if @hash == nil @hash['no_live_play'] == 1 end def tags return nil if @hash == nil 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 return nil if @hash == nil @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 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 # #