Skip to content

Instantly share code, notes, and snippets.

@staybuzz
Created March 6, 2014 00:10
Show Gist options
  • Save staybuzz/9379475 to your computer and use it in GitHub Desktop.
Save staybuzz/9379475 to your computer and use it in GitHub Desktop.
ニコ動の動画IDを指定するとそのタイトルを取得してくれる
# encoding: utf-8
# Ref: http://qiita.com/katabamisan/items/09b3e109fa59ee371ffc
# Ref: http://d.hatena.ne.jp/satake7/20080525/p1
require 'rexml/document'
require 'open-uri'
# 動画IDを与えるとXML形式の動画情報を受け取る
module NicoVideoAPIWrapper extend self
def get_thumb_info_xml(id)
open("http://ext.nicovideo.jp/api/getthumbinfo/#{id}") {|f|
return REXML::Document.new(f)
}
end
end
begin
# 動画IDを入力する
print "Please Input NicoNico Video Id (ex. sm500873): "
video_id = gets.chomp
# 動画情報を取得する
xmldoc = NicoVideoAPIWrapper::get_thumb_info_xml(video_id)
# 動画タイトルを取得、表示する
video_title = xmldoc.elements['nicovideo_thumb_response/thumb/title'].text
puts video_title
rescue
puts "Error! Retype Video ID"
error = 1
end while error==1 # タイトルが取得できない等エラーが起きたらもう一度
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment