Sha256: 02311449c8f58b52f8a95f3395c7cf5a0bccbf5f42ee01b39121d96bd65884ba
Contents?: true
Size: 1.89 KB
Versions: 2
Compression:
Stored size: 1.89 KB
Contents
module Niconico class Mylist < Fabric include Niconico::Helper def initialize(ptr, agent=nil) super(agent) @id = normalize(ptr) @mylist = nil fetch end def method_missing(method, *args) raise(NoMethodError, method) unless @mylist.respond_to? method @mylist[method] end private def normalize(ptr) ptr.match(/mylist\/([0-9]+)\??/)[1] end def fetch doc = REXML::Document.new(open("http://www.nicovideo.jp/mylist/#{@id}?rss=2.0").read) channel = doc.elements['/rss/channel'] items = [] channel.elements.each('item') do |item| html_description = item.elements['description/text()'].to_s.gsub(/<p class=\"nico-info\">.+<\/p>/, '') description = html_description.gsub(/<\/?.*?>/, '') items << OpenStruct.new({ :title => item.elements['title/text()'].to_s, :link => item.elements['link/text()'].to_s, :guid => item.elements['guid/text()'].to_s, :created_at => item.elements['pubDate/text()'].to_s, :description => description, :html_description => html_description }) end @mylist = OpenStruct.new({ :title => channel.elements['title/text()'].to_s.gsub(/(^マイリスト\s|‐ニコニコ動画$)/, ''), :link => channel.elements['link/text()'].to_s, :description => channel.elements['description/text()'].to_s, :created_at => channel.elements['pubDate/text()'].to_s, :updated_at => channel.elements['lastBuildDate/text()'].to_s, :generator => channel.elements['generator/text()'].to_s, :author => channel.elements['dc:creator/text()'].to_s, :language => channel.elements['language/text()'].to_s, :items => items, :items_count => items.size }) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nv-1.2.2 | lib/nv/niconico/mylist.rb |
nv-1.2.1 | lib/nv/niconico/mylist.rb |