生配信チェッカーサイトを作りたいブログ

生配信チェッカーサイトを作りたい人がメモ書きをするブログ

Livestreamから情報を取得

APIを使用して様々な情報を取得できる。
APIはPlayer, Channel, Guide, Account, Live Publishing APIがある。
配信情報を得るだけならChannel APIだけで良さそう。

API制限

10req. / sec.
100 req. / min.
1000 req/ hr.
10000 req/ day

Channel API

http://original.livestream.com/userguide/index.php?title=Main_Page&title=Channel_API_2.0
チャンネルのリクエストURLは下記の変わった方法で生成されるので注意。サブドメインを使用するのは珍しい。
1.チャンネル名の頭と語尾に「x」を付ける。
 ex) 「hoge_hoge」→「xhoge_hogex」
2.チャンネル名にアンダースコア(_)が含まれる場合はハイフン(-)に置き換える
 ex) 「xhoge_hogex」→「xhoge-hogex」
3.後ろに「.api.channel.livestream.com/2.0/」を付ける。
 ex) 「xhoge-hogex」→「xhoge-hogex.api.channel.livestream.com/2.0」

生成されるURLにlistplaylists・listclips・latestclips・clipdetails・info・livestatus・thumbnail・eventsを続けて各種情報を取得。
デフォルトはxml形式だが、拡張子として.jsonを付けるとjson形式になる。



~.api.channel.livestream.com/2.0/ からJSONデータを取得し、さまざまなデータを取得するjavascript

var id_livestream = "john"; //取得チャンネルのID
$.getJSON('https://x' + id_livestream.replace("_","-") + "x" + '.api.channel.livestream.com/2.0/' + "livestatus.json"+ '?callback=?', function(json) {})
.success(function(json) {
	if (json.channel.isLive > 0) { //id:viewersに人数を埋め込み
		$('#livestream_isLive').text(id_livestream + 'は配信中です');
		$('#livestream_currentViewerCount').text('現在の視聴者数:' + json.channel.currentViewerCount);
	} else {
		$('#livestream_isLive').text(id_livestream + 'は配信していません');
		$('#livestream_currentViewerCount').text('現在の視聴者数:' + json.channel.currentViewerCount);
	}
	if (json.channel.isPremium > 0) { //id:viewersに人数を埋め込み
		$('#livestream_isPremium').text(id_livestream + 'はプレミアムアカウントです');
	} else {
		$('#livestream_isPremium').text(id_livestream + 'はプレミアムアカウントではありません');
	}


})
.error(function(jqXHR, textStatus, errorThrown) {
		$('#livestream_isLive').text(id_livestream + 'の配信状況は不明です');
})


↓結果

まだまだいっぱい情報を取得できるけどとりあえずここまで。
info.jsonはlivestatusの上位互換っぽい。