Subscribe::Nicovideo::mylist - マイリスト取得

Pragger 用のプラグインです。
指定したマイリストから、動画の情報を取得します。

require 'rubygems'
require 'nicovideo'
require 'rss'

def mylist(config, data)
  return data  unless config.key?('mailaddress') && config.key?('password') && config.key?('mylist_id')

  nicov = Nicovideo.new(config['mailaddress'], config['password']).login

  rss = RSS::Maker.make("2.0") do |maker|
    list = nicov.mylist(config['mylist_id'])
    # TODO:
    maker.channel.title       = list.title
    maker.channel.description = list.description
    maker.channel.link        = list.url

    list.videos.each {|video|
      item = maker.items.new_item

      item.title       = video.title
      item.link        = video.url
      sleep 1
      item.description = video.tags
      # TODO:
      item.date        = Time.now

      if config.key?('dir')
        # TODO:
        filename = config['dir'] + '/' + video.id + '.flv'
        File.open(filename, "wb") {|f| f.write video.flv }

        item.enclosure.url = filename
        item.enclosure.type = 'video/flv'
        item.enclosure.length = File::stat(filename).size
      end
    }

    sleep 1
  end

  rss.items
end