Created
March 6, 2014 00:10
-
-
Save staybuzz/9379475 to your computer and use it in GitHub Desktop.
ニコ動の動画IDを指定するとそのタイトルを取得してくれる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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