11月 04 2009

ニコニコ動画(9)で nicovideo.rb 動かなくなってた

Published by HoLY under tech

gem で入れた nicovideo プラグイン を動画ダウンロード用のスクリプトで使っていたけど、 ニコニコ動画(9)になって動作しなくなっていたのでとりあえずダウンロードだけ動くようにした。(XPath 部分直しただけ)

require 'nicovideo'

module Nicovideo
  class VideoPage < Page
    def parse(page)
      # title
      @title = page.title.toutf8.sub(/#{BASE_TITLE1}$/ou, '')

      # tags
      div = page.parser.search("div#video_tags")
      @tags = div.to_html.scan(/<a href=\"tag\/[\w\%]+?\">(.+?)<\/a>/ou).inject([]) {|arr, v|
        puts_debug v[0]
        arr << v[0]
      }

      # published_at
      str = page.search("div[@id='WATCHHEADER']//p[@class='font12']/strong")[0].inner_text
      tm = str.scan(/\d+/)
      @published_at = Time.mktime(*tm)
    end
  end
end

ダウンロード以外はやっぱり動かないので注意。マイリスト回りのコードにも影響があるので commit しにくいなー……。

Tags: ,

No responses yet

12月 08 2008

Rails 2.2.2 と RubyGems 1.3.1

Published by HoLY under tech

Rails 2.2 にアップデートしたら

$ ./script/console
Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update --system` and try again.

などと言われる。しかし、そのままやってもダメらしい。

$ sudo gem update --system
Updating RubyGems
Nothing to update

rubygems-1.2.x 以下の場合、 rubygems-update パッケージをインストールしたのち、update_rubygems コマンドを実行する必要がある。

$ sudo gem install rubygems-update
$ sudo update_rubygems

rubygems-1.3.1 のリリースアナウンスはこちら

Tags: ,

No responses yet

6月 06 2008

open-uri を Basic認証のあるサイトに使う

Published by HoLY under tech

Ruby の便利標準ライブラリ筆頭(個人的感想)である open-uri ですが、 いまだに「open-uri はBasic認証のあるサイトには使えない」という都市伝説(?)が。

こんな風に :http_basic_authentication オプションを与えることでできるよ。

require 'open-uri'
open('http://www.example.com/authenticated_page/',
     :http_basic_authentication => ['username', 'password'])

現在のマニュアルには載っていない ので注意。 新しい方にも特に書いてはいないみたい

ちなみにプログレスバーのために :content_length_proc と :progress_proc が使えるが、簡単に作るとこんな感じに。

open(downloading-filename, 'w') {|f|
  f.write open(url,
               :content_length_proc => proc{|len|
                 @len = len
               },
               :progress_proc => proc{|now|
                 per = now * 100 / @len
                 $stdout.print "%15u bytes (%3u%%) |" % [now, per]
                 $stdout.print "=" * per
                 $stdout.print ">" if per < 100
                 $stdout.print "-" * (99-per) if per < 99
                 $stdout.print "\r"
                 $stdout.flush
               }
  ).read
}

Tags:

2 responses so far

5月 18 2008

ドロップシャドウをつけるRubyスクリプト

Published by HoLY under tech

三国志大戦3Master のデータを作っていて、既存の大量の画像にドロップシャドウを付けたものが必要になったので、RMagick を使ったRubyスクリプトなどを書いてみた。

Continue Reading »

Tags: ,

No responses yet