990のひとのブログ

ニコ生アラートの開発秘話 あと英語の話もときどきするかも?

色付きコメに対応する苦肉の策><

HSPって16進法から10進法に(簡単に)変換できないんだって><

と思ったら、全然そんなことないみたい>< ちょうショック><

 http://lhsp.s206.xrea.com/hsp_tips9.html#3

	private String colorCodeConverter(String command){
		/*
		white	白色(#FFFFFF)
		red		赤色(#FF0000)
		pink	桃色(#FF8080)
		orange	橙色(#FFCC00)
		yellow	黄色(#FFFF00)
		green	緑色(#00FF00)
		cyan	水色(#00FFFF)
		blue	青色(#0000FF)
		purple	紫色(#C000FF)
		white2	白2(#CCCC99)	
		red2	赤2(#CC0033)	
		orange2	橙2(#FF6600)	
		yellow2	黄2(#999900)	
		green2	緑2(#00CC66)	
		blue2	青2(#33FFFC)	
		purple2	紫2(#6633CC)	
		black	黒(#000000)	
		
		CC=204 33=51 66=102 99=153
		*/
		if (command=="184") 				return "#255255255";
		if (command.indexOf("white2") >-1) 	return "#204204153";
		if (command.indexOf("white") >-1) 	return "#255255255";
		if (command.indexOf("cyan") >-1) 	return "#000255255";
		if (command.indexOf("black") >-1) 	return "#000000000";
		if (command.indexOf("purple2") >-1) return "#102051204";
		if (command.indexOf("purple") >-1) 	return "#192000255";
		if (command.indexOf("blue2") >-1) 	return "#051255252";
		if (command.indexOf("blue") >-1) 	return "#000000255";
		if (command.indexOf("green2") >-1) 	return "#000204102";
		if (command.indexOf("green") >-1) 	return "#000255000";
		if (command.indexOf("yellow2") >-1) return "#153153000";
		if (command.indexOf("yellow") >-1) 	return "#255255000";
		if (command.indexOf("orange2") >-1) return "#255102000";
		if (command.indexOf("orange") >-1) 	return "#255204000";
		if (command.indexOf("red2") >-1) 	return "#204000051";
		if (command.indexOf("red") >-1) 	return "#255000000";
		if (command.indexOf("pink") >-1) 	return "#255128128";
		
		return "#255255255";
	}

 

ついにPHPで自動コメント取得に成功したよ><

っていっても別に特殊なことしてるわけじゃなくて、

  1. cronで1分おきに生放送一覧をチェック→副産物
  2. 登録したコミュニティの生放送を見つけたらその情報をファイルに保存
  3. そのファイルをもとに、5秒おきにコメントを取得してhtmlに保存

cronは1分おきが最小単位だから、phpは5秒おきに11回繰り返してコメントをゲットするようになっているよ><

というか、実際コメント読んでhtml出すのに2秒くらいかかってるから3秒のスリープかけてる。これもexecとか使ってごにょごにょすればちゃんと5秒おきになるはずだけど、とりあえず動けばいいよね><

てわけで、おなじみ「おい!ゆとり!」コミュニティの生放送を自動的に検出してコメントを表示するページはここ!

yutoriQR

http://yutori-english.com/comments.html

鯖をあんまりいじめないでね><

携帯でもアクセスできるよ><

でもアクセスキーが動かないよ><

 

PHPでニコ生コメント鯖の情報をゲットしたよ><

とりあえずこんな感じ。

 

$cookie_file_path = realpath("../")."/cookie.txt";
$loginData = array('mail' => 'me-ru@adoresu', 'password' => 'pasuwa-do');
$lvID = "lv999999";


function getConnectionInfo($lvID){
	global $thread,$port,$addr;
	
	$xmlLoaded=2;
	while($xmlLoaded){
		
		$xml=getPlayersStatus($lvID);
		
		$sxe = simplexml_load_string($xml);

		

		if ($sxe === false) {

			echo 'Error while parsing the document
'; echo $xml; exit; } $code=$sxe->xpath("//code"); if ($code !=null){ if((string)$code[0] == "notlogin"){ login();// $xmlLoaded--; }elseif((string)$code[0] == "closed"){ echo 'Live Closed
'; return null; }else{ echo 'Error on server
'; echo $xml; return null; } }else{ $xmlLoaded=0; } }//while //thread port addr room_label $thread=$sxe->xpath("//thread"); $port=$sxe->xpath("//port"); $addr=$sxe->xpath("//addr"); echo "Thread:$thread[0]
\n"; echo "port:$port[0]
\n"; echo "addr:$addr[0]
\n"; }///getConnectionInfo function login(){ global $cookie_file_path,$loginData; $url = "https://secure.nicovideo.jp/secure/login?site=niconico"; touch($cookie_file_path); $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSLVERSION,3); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $loginData); curl_exec($ch); curl_close($ch); }//login function getPlayersStatus($lvID){ global $cookie_file_path; $url = "http://live.nicovideo.jp/api/getplayerstatus?v=".$lvID; $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSLVERSION,3); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); $data = curl_exec($ch); curl_close($ch); return $data; }//getPlayersStatus($lvID)

 

 

QRコード
QRコード
  • ライブドアブログ