Skip to content

Instantly share code, notes, and snippets.

@nus
Created March 16, 2011 06:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nus/872110 to your computer and use it in GitHub Desktop.
Save nus/872110 to your computer and use it in GitHub Desktop.
Boost::asioでニコ生のコメントを取得
#include <iostream>
#include <string>
#include <boost/asio.hpp>
using namespace std;
using namespace boost::asio;
int main()
{
/*
ブラウザでニコニコ動画にログインした状態で
http://watch.live.nicovideo.jp/api/getplayerstatus?v=lvNNNNN
でニコ生のステータスを取得
必要なエレメントは
<ms>
<addr> msg101.live.nicovideo.jp </addr>
<port> 1234 </port>
<thread> 1234567890 </threa>
</ms>
*/
string ms = "msg102.live.nicovideo.jp"; // <addr>msgNNN.live.nicovideo.jp </addr>
string port = "2811"; // <port>ポート番号</port>
string thread = "1077478504"; // <thread>コメントのスレッドID</thread>
ip::tcp::iostream s(ms, port);
s << "<thread thread=\"" << thread << "\" version=\"20061206\" res_from=\"-1\"/>";
s << '\0';
s.flush();
string line;
while(1) {
getline(s, line, '\0');
/*
*****</chat>\0<chat thread=******
'\0'で1コメントの区切りだから
*/
cout << line << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment