Skip to content

Instantly share code, notes, and snippets.

@serihiro
Created August 17, 2012 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serihiro/3383478 to your computer and use it in GitHub Desktop.
Save serihiro/3383478 to your computer and use it in GitHub Desktop.
cronko.php (for internal)
<?php
include "sitesetting.php";
include "setting.php";
$db = mysqli_connect( $dbHost, $dbUser, $dbPass, $dbName );
if( mysqli_connect_errno() ){
die("データベースとの接続に失敗しました。:" . mysqli_connect_error());
}else{
mysqli_set_charset($db,"utf8");
}
$mydateformat = "Y-m-d H:i:s";
$now = time(); // 現在時刻
$t_start = date( "Y-m-d H:i:s", $now );
$logfilename = $event_code . "-" . date( "Ymd-His", $now ) . ".txt";
$log = fopen( $logdir_local . DS . $logfilename, "w" );
$deleteLog = fopen( $logdir_local . DS . 'deleted.log' , "a" );
$errorLog = fopen( $logdir_local . DS . 'error.log' , "a" );
fprintf( $log, "=== cronko start at " . date($mydateformat, $now ) . "\n" );
/*データ集計モードを設定する。
delee公式マイリスト集計モード
* 2:APIを逐一叩いてデータを取得する集計モード
*/
$crm = getconfig( $db, "cronko_mode" );
if($crm == null){
fprintf( $log, "=== FATAL ERROR! Data total mode is not set! " . date($mydateformat, $now ) . "\n" );
die('=== FATAL ERROR! Data total mode is not set!');
}
$loadcnt = 0;
$elist = array();
$eelist = array();
//公式マイリストからデータを取得してマスタを更新する
if( $crm == 2 ){
fprintf( $log, "--- mode=2 公式マイリス\n" );
$loadcnt = 0;
foreach( $event_mylists as $m ){
$url = sprintf( "http://www.nicovideo.jp/mylist/%s?rss=2.0&numbers=1", $m );
fprintf( $log, "--- checking: %s ⇒ %s\n", $m, $url );
$xml = simplexml_load_file( $url );
if( $xml === false ){
fprintf( $log, "simplexml_load_file(%s): error\n", $url );
continue;
}
fprintf( $log, "--- xml_load %d items\n", count( $xml->channel->item ) );
foreach( $xml->channel->item as $i ){
$e = array();
$loadcnt = $loadcnt + 1;
$sla = strrpos( $i->link, "/" );
if( $sla === false ){
fprintf( $log, "error link-parse: %s\n", $i->link );
continue;
}
$smno = substr( $i->link, strrpos( $i->link, "/" )+1 );
array_push( $elist, $smno );
$desc = $i->description;
$view = getnumfromrss( $desc, "nico-numbers-view\">", "</strong>" );
$comme = getnumfromrss( $desc, "nico-numbers-res\">", "</strong>" );
$mylist = getnumfromrss( $desc, "nico-numbers-mylist\">", "</strong>" );
fprintf( $log, "read-rss %s: %d %d %d\n", $smno, $view, $comme, $mylist );
$e["smno"] = $smno;
$e["view"] = $view;
$e["comme"] = $comme;
$e["mylist"] = $mylist;
array_push( $eelist, $e );
}
}
fprintf( $log, "=== elist %d at %s\n", count($elist), date($mydateformat) );
fprintf( $log, "--- %d 件が配列 elist に準備できました。\n", count($elist) );
fprintf( $log, "--- %d 件が配列 eelist に準備できました。\n", count($eelist) );
$ups = 0;
foreach( $eelist as $e ){
fprintf( $log, "update: %s %d %d %d\n", $e["smno"], $e["view"], $e["comme"], $e["mylist"] );
printf( "ec: %s\n", $event_code );
$ups = $ups + updatenum( $db, $event_code, $e["smno"], $e["view"], $e["comme"], $e["mylist"], $crm, $t_start );
}
fprintf( $log, "eee\n" );
$t_end = date( "Y-m-d H:i:s", time() );
$mode = 2;
$num_db = count($elist);
fprintf( $log, "---%d / %d 件を updateしました。at %s\n", $ups, $num_db, $t_end );
$q = "insert into cronkologs (t_start,t_end, mode, num_db, num_update, value, eventcode) values ";
$q = $q . "( '$t_start', '$t_end', '$mode', '$num_db', '$ups', '$logfilename', '$event_code' );";
$result = mysqli_query( $db, $q );
fprintf( $log, "=== completed. at %s\n", date($mydateformat) );
fclose( $log );
exit();
//APIから動画データを取得してマスタを更新する
}else if($crm == 1){
fprintf( $log, "--- mode=1 森下リスト\n" );
$query = "SELECT nicono, view, comme, mylist from videolist where eventcode='$event_code' ;";
$result = mysqli_query($db, $query );
$rows = mysqli_num_rows($result);
fprintf( $log, ": %d entries on DB\n", $rows );
while( $row = mysqli_fetch_assoc($result) ){
array_push( $elist, $row["nicono"] );
}
fprintf( $log, "=== elist %d at %s\n", count($elist), date($mydateformat) );
fprintf( $log, "--- %d 件が配列 elist に準備できました。\n", count($elist) );
mysqli_free_result($result);
$cnt = 0; $ups = 0;
$thumbinfo = "http://www.nicovideo.jp/api/getthumbinfo/";
foreach( $elist as $e ){
$cnt = $cnt +1;
fprintf( $log, "%5d : %s check for [%s]...\n", $cnt, date($mydateformat), $e );
$target = $thumbinfo . $e;
fprintf( $log, "target:[%s]\n", $target );
$xml = simplexml_load_file( $target );
if( $xml === false ){
fprintf( $log, "error!!! : Can't load xml [%s] maybe deleted?\n", $e );
} else {
$info = $xml->thumb;
$ups = $ups + updatenum( $db, $event_code, $e, $info->view_counter, $info->comment_num, $info->mylist_counter, $calc_point, $t_start );
}
}
fprintf( $log, "=== completed. at %s\n", date($mydateformat) );
$t_end = date( "Y-m-d H:i:s", time() );
$mode = 1;
$num_db = count($elist);
fprintf( $log, "---%d / %d 件を updateしました。at %s\n", $ups, $num_db, $t_end );
$q = "insert into cronkologs (t_start,t_end, mode, num_db, num_update, value, eventcode ) values ";
$q = $q . "( '$t_start', '$t_end', '$mode', '$num_db', '$ups', '$logfilename', '$event_code' );";
fprintf( $log, "q[%s]\n", $q );
$result = mysqli_query( $db, $q );
fprintf( $log, "result: %s\n", mysqli_error( $db ) );
fprintf( $log, "=== completed. at %s\n", date($mydateformat) );
fclose( $log );
exit();
}else if($crm == 3){
/*
* @seri_k作魔改造モード
* 以下の処理順で動画追加・更新を完全自動化する
* 1 公式マイリスから登録動画のIDのみを取得(RSSフィードXMLのitem->linkから正規表現でぶっこ抜く
* 2 1で取得した動画IDそれぞれに対し、getthumbinfoAPIを使用して動画情報を取得する
* 3 2で取得したデータをマージする。新規動画の場合はinsert, 既存動画の場合はupdateになる
* ※その際、ok列が0になっている不正の動画と同じ動画IDであれば、ポイントは強制的に0にして更新する
* 4 もし新規動画が含まれていたらサムネ画像をcurlでDLしに行く(curl使うから何も設定してないWindowsだと動かないかも?)
*/
fprintf( $log, "--- mode=3 ハイブリット動作モード\n" );
$t_start = date( "Y-m-d H:i:s", time() );
$videoIdList = array();
fprintf( $log, "--- 公式マイリストから動画IDのみを取得 開始\n" );
//大会公式マイリスから登録されている動画の動画IDを取得
foreach( $event_mylists as $m ){
$url = sprintf( "http://www.nicovideo.jp/mylist/%s?rss=2.0&numbers=1", $m );
fprintf( $log, "--- checking: %s ⇒ %s\n", $m, $url );
$xml = simplexml_load_file( $url );
if( $xml === false ){
fprintf( $log, "simplexml_load_file(%s): error\n", $url );
continue;
}
foreach( $xml->channel->item as $item ){
$videoID = array();
$rawURL = $item->link;
preg_match('/[a-z]{2}[0-9]+/' , $rawURL , $videoID);
$videoIdList[] = $videoID[0];
}
}
fprintf( $log, "--- 公式マイリストから動画IDのみを取得 完了\n" );
//データ差分があればサムネ画像を取得しに行く
$oldVideoIdList = getVideoList($db);
$diff = array_diff($videoIdList ,$oldVideoIdList);
//マイリスから削除された動画を抽出する
$reverseDiff = array_diff($oldVideoIdList , $videoIdList);
$oldVideoIdList = null;
if(count($diff) >= 1){
fprintf( $log, "--- 新規動画有り、サムネ画像取得 開始\n");
getThumbImage($diff , $thumbdir_local);
fprintf( $log, "--- 新規動画有り、サムネ画像取得 終了\n");
}
$diff = null;
$reverseDiff = array_unique($reverseDiff);
if(count($reverseDiff) >= 1){
fprintf( $log, "--- マイリスから削除された動画をDBから削除 開始\n");
foreach($reverseDiff as $willDeleteVideo){
fprintf( $log, "--- 削除対象:" . $willDeleteVideo ." \n");
}
deleteVideo($db , $reverseDiff , $deleteLog);
fprintf( $log, "--- マイリスから削除された動画をDBから削除 終了\n");
}
$reverseDiff = null;
//不正動画リストを取得
$invalidVideoList = getInvalidVideoList($db);
$thumbinfoURL = "http://www.nicovideo.jp/api/getthumbinfo/";
/*
* <nicovideo_thumb_response status="ok">
<thumb>
<video_id>sm18407693</video_id>
<title>【第9回MMD杯予選】またMMDモデルに挑戦【モデル配布予定】</title>
<description>
こんにちは! またモデルを作ってみた。まだ調整中だけど……。本選では隣に隠れているキャラに踊って頂きたいと思いますので、最終投稿日までに終わるように頑張ります。 追記「提督」じゃなくて「総督」でした(汗)【Theme:食】 【name:蒼黒】MMD杯公式サイト=https://sites.google.com/site/mmdcuphp/お借りしたモーション・音楽 【MMD】 WAVEFILE fullver. 【モーション完成】http://www.nicovideo.jp/watch/sm18065127 オリジナル曲:ラマーズP WAVEFILE/初音ミク fullver.http://www.nicovideo.jp/watch/sm14257396
</description>
<thumbnail_url>http://tn-skr2.smilevideo.jp/smile?i=18407693</thumbnail_url>
<first_retrieve>2012-07-21T19:53:57+09:00</first_retrieve>
<length>0:42</length>
<movie_type>mp4</movie_type>
<size_high>3194024</size_high>
<size_low>2278399</size_low>
<view_counter>1153</view_counter>
<comment_num>12</comment_num>
<mylist_counter>38</mylist_counter>
<last_res_body>がんばれー かわいい どこが食? 右で踊ってるのはなん 日常ネタがアレだった</last_res_body>
<watch_url>http://www.nicovideo.jp/watch/sm18407693</watch_url>
<thumb_type>video</thumb_type>
<embeddable>1</embeddable>
<no_live_play>0</no_live_play>
<tags domain="jp">
<tag category="1" lock="1">その他</tag>
<tag lock="1">MMD杯9予-食</tag>
<tag>第9回MMD杯予選</tag>
<tag>MMDユーザーモデル</tag>
</tags>
<user_id>5666580</user_id>
</thumb>
</nicovideo_thumb_response>
*/
fprintf( $log, "--- APIから動画情報取得 開始\n");
$videoInfoList = array( array() );
//APIを使用して動画情報を取得
foreach($videoIdList as $key => $videoId){
$xml = simplexml_load_file( $thumbinfoURL . $videoId );
if( $xml === false ){
fprintf( $log, "simplexml_load_file(%s): error\n", $thumbinfoURL . $videoId );
continue;
}
//削除済み、又は非公開の動画の場合(ってかこういうのやめてマジで・・)
if( property_exists($xml , 'error') == true){
fprintf( $log, "非公開or削除済み動画発見 :" . $videoId . "\n" );
continue;
}
$videoInfo = $xml->thumb;
$videoInfoList[$key]['eventcode'] = $event_code;
$videoInfoList[$key]['nicono'] = (String)$videoInfo->video_id;
$videoInfoList[$key]['watch_url'] = (String)$videoInfo->watch_url;
$videoInfoList[$key]['postdate'] = substr( $videoInfo->first_retrieve , 0 , strlen($videoInfo->first_retrieve) - 6 );
$videoInfoList[$key]['length'] = (String)$videoInfo->length;
$videoInfoList[$key]['title'] = (String)$videoInfo->title;
//length生成
$rawLength = explode(":" , $videoInfo->length);
$length = $rawLength[0] * 60 + $rawLength[1];
$videoInfoList[$key]['time'] = $length;
$videoInfoList[$key]['userid'] = (String)$videoInfo->user_id;
$videoInfoList[$key]['niconame'] = getNicoName((String)$videoInfo->user_id);
//username抽出
$username = '';
$rawDescription = (String)$videoInfo->description;
//半角カナを全角カナに、全角英数を半角英数に変換
$rawDescription = mb_convert_kana( preg_replace('/\s/' , '' , $rawDescription), "rnKHV", "utf-8");
$result = preg_match('/(【name|【Name).*?】/i' , $rawDescription , $match);
if( $result == 0 ){
$username = '';
}else{
$username = preg_replace('/(【name(:|:))|(【Name(:|:) )/i' , '' , $match[0]);
$username = str_replace('】' , '' , $username);
}
//Theme抽出
$theme = '';
$tmpTheme = '';
$themeCount = 0;
$regulationPattern = '/' . implode($reg_theme , '|') . '/i';
$themeCheckResultMessage = '';
$result = preg_match_all('/(【Theme|【theme).*?】/i' , $rawDescription , $matches);
if( $result != 0){
foreach($matches[0] as $match){
$tmpTheme = preg_replace('/(【Theme(:|:))|(【theme(:|:) )/i' , '' , $match);
$tmpTheme = str_replace('】' , '' , $tmpTheme);
$result = preg_match($regulationPattern , $tmpTheme);
if($result == 0){
continue;
}else{
$themeCount++;
}
}
$theme = $tmpTheme;
}
if( $themeCount > 1){
fprintf( $log, " テーマが複数個セットされています。 : " . (String)$videoInfo->video_id . "\n" );
fprintf( $errorLog, date( "Y-m-d H:i:s") . " テーマが複数個セットされています。 : " . (String)$videoInfo->video_id . "\n" );
$themeCheckResultMessage = 'テーマが2個以上設定されています。';
}
//tag抽出
$tag = '';
$tagArray = array();
$vi = 0;
$attribute = null;
foreach($videoInfo->tags->tag as $tag){
//もしロックタグであれば頭に★を付ける
$attribute = (String)$videoInfo->tags->tag[$vi]->attributes()->lock;
if( $attribute == '1' ){
$tagArray[] = '★' . (String)$tag;
}else{
$tagArray[] = (String)$tag;
}
$vi++;
}
//タグを半角スペースで分割する
if(count($tagArray) != 0){
$tag = implode(' ' , $tagArray);
}
$videoInfoList[$key]['tag'] = $tag;
$videoInfoList[$key]['username'] = $username;
$videoInfoList[$key]['theme'] = $theme;
$videoInfoList[$key]['descript'] = $rawDescription;
$videoInfoList[$key]['thumbnail'] = (String)$videoInfo->video_id . '.jpg';
$videoInfoList[$key]['view'] = (int)$videoInfo->view_counter;
//もし不正動画であればポイントに0を強制的にセットする
if( array_search($videoId , $invalidVideoList) !== false ){
$videoInfoList[$key]['point'] = 0;
}else{
$videoInfoList[$key]['point'] = calclulePoint( (int)$videoInfo->view_counter , (int)$videoInfo->comment_num , (int)$videoInfo->mylist_counter);
}
$videoInfoList[$key]['comme'] = (int)$videoInfo->comment_num;
$videoInfoList[$key]['mylist'] = (int)$videoInfo->mylist_counter;
$videoInfoList[$key]['viewprev'] = (int)$videoInfo->view_counter;
$videoInfoList[$key]['ok'] = 1;//固定値で1をセット。0だと不正動画扱いになる。
//TODO 今の所はテーマが複数セットされた場合に限定して使用するが、将来的には汎用化する必要有り
$videoInfoList[$key]['memo'] = $themeCheckResultMessage;
}
fprintf( $log, "--- APIから動画情報取得 終了\n");
fprintf( $log, "--- 動画更新 開始\n");
$updateCount = updateVideoList($db, $videoInfoList);
fprintf( $log, "--- 動画更新 終了\n");
fprintf( $log, $updateCount . "件の動画を更新\n");
$t_end = date( "Y-m-d H:i:s", time() );
//cronkologテーブルを更新
$updateCronkoLog = "INSERT INTO cronkologs (t_start,t_end, mode, num_db, num_update, value, eventcode) VALUES "
. "( '$t_start', '$t_end', '$crm', '$updateCount', '$updateCount', '$logfilename', '$event_code' );";
$result = mysqli_query( $db, $updateCronkoLog );
fprintf( $log, $t_end . " --- cronko処理終了\n");
exit();
}//end - if
function updatenum( $db, $ec, $smno, $view, $comme, $mylist, $ct, $t_start ){
if( $ct == 2 ){
$point = $view + $comme + ($mylist*20);
} else {
$point = $mylist;
}
$updateVideoListQuery = "UPDATE videolist SET "
. "view = $view , "
. "comme = $comme , "
. "mylist = $mylist , "
. "point = $point "
. "WHERE eventcode = '$ec' AND nicono = '$smno' ";
$result = mysqli_query($db, $updateVideoListQuery );
if( $result === false ){
printf( "⇒SQL : error!\n" );
return 0;
} else{
printf( "⇒OK\n" );
}
$ett = "tblnums_" . $ec;
//$t_start = date( "Y-m-d H:i:s", $now );
//// t_start =は cronko開始時の奴を採用
$insertRawDataQuery = "INSERT INTO $ett ( t_start, eventcode, nicono, view, comme, mylist ) "
. "VALUES "
. "('$t_start', '$ec', '$smno', '$view', '$comme', '$mylist' )";
$result = mysqli_query($db, $insertRawDataQuery );
printf( "L(%s):%d\n", $insertRawDataQuery, $result );
return 0;
}
function getconfig( $db, $key ){
$q = "select * from mlconfig where name = '$key';" ;
$result = mysqli_query( $db, $q );
if( $result === false ){
return false;
}
$n = mysqli_num_rows($result);
if( $n < 1){
mysqli_free_result($result);
return false;
}
$rows = mysqli_fetch_assoc( $result );
$ans = $rows['value'];
mysqli_free_result($result);
return $ans;
}
function getnumfromrss( $desc, $ss, $es ){
$n1 = strpos( $desc, $ss );
$d1 = substr( $desc, $n1+strlen($ss) );
$n2 = strpos( $d1, $es );
$d2 = substr( $d1, 0, $n2 );
$ans = intval( str_replace(array(',','.'),array('',''),$d2) );
return $ans;
}
/*
* 動画情報を更新する。
* 既存の場合は以下の項目のみを最新のデータで更新する
* title
* theme
* descript
* username
* tag
* view
* point
* comme
* mylist
* viewprev
*/
function updateVideoList($db , $videoInfoList){
if($db == null || empty($videoInfoList) ){
return false;
}
$updateRowCount = 0;
$sql = 'INSERT INTO videolist('
. 'eventcode,'
. 'nicono,'
. 'title,'
. 'watch_url,'
. 'postdate,'
. 'time,'
. 'length,'
. 'userid,'
. 'niconame,'
. 'username,'
. 'theme , '
. 'descript,'
. 'thumbnail,'
. 'tag,'
. 'view,'
. 'point,'
. 'memo,'
. 'ok,'
. 'comme,'
. 'mylist,'
. 'viewprev) '
. 'VALUES('
. '?,' //eventcode@string
. '?,' //nicono@string
. '?,' //title@string
. '?,' //watch_url@string
. '?,' //postdate@string
. '?,' //time@int
. '?,' //length@string
. '?,' //userid@string
. '?,' //niconame@string
. '?,' //username@string
. '?,' //theme@string
. '?,' //descript@string
. '?,' //thumbnail@string
. '?,' //tag@string
. '?,' //view@int
. '?,' //point@int
. '?,' //memo@string
. '?,' //ok@tinyint
. '?,' //comme@int
. '?,' //mylist@int
. 'view' //viewprev
. ') '
. 'ON DUPLICATE KEY UPDATE '
. 'title = ?,' //string
. 'theme = ?,' //string
. 'descript = ?,' //string
. 'niconame = ?,' //string
. 'username = ?,' //string
. 'tag = ?,' //string
. 'view = ?,' //int
. 'point = ?,' //int
. 'memo = ?,' //string
. 'comme = ?,' //int
. 'mylist = ?,' //int
. 'viewprev = view'
;
$stmt = mysqli_prepare($db , $sql);
if($stmt == false){
return false;
}
foreach($videoInfoList as $videoParameter){
//values句
$stmt->bind_param("sssssissssssssiisiiissssssiisii" ,
$videoParameter['eventcode'] ,
$videoParameter['nicono'] ,
$videoParameter['title'] ,
$videoParameter['watch_url'],
$videoParameter['postdate'],
$videoParameter['time'],
$videoParameter['length'],
$videoParameter['userid'],
$videoParameter['niconame'],
$videoParameter['username'],
$videoParameter['theme'],
$videoParameter['descript'],
$videoParameter['thumbnail'],
$videoParameter['tag'],
$videoParameter['view'],
$videoParameter['point'],
$videoParameter['memo'],
$videoParameter['ok'],//okの値は初期値は固定で1をセット
$videoParameter['comme'],
$videoParameter['mylist'],
//以下update時
$videoParameter['title'] ,
$videoParameter['theme'],
$videoParameter['descript'],
$videoParameter['niconame'],
$videoParameter['username'],
$videoParameter['tag'],
$videoParameter['view'],
$videoParameter['point'],
$videoParameter['memo'],
$videoParameter['comme'],
$videoParameter['mylist']
);
$result = $stmt->execute();
if($result == true){
$updateRowCount++;
}else{
echo "update error\n";
echo mysqli_stmt_error($stmt)."\n\n";
}
}
$stmt->close();
return $updateRowCount;
}
/*
* ポイントを計算する
*/
function calclulePoint($view , $comme , $mylist){
//return $view + $comme + $mylist * 20;
return $mylist;
}
/*
* 指定のniconoの動画のサムネ画像をダウンロードし
* 所定のフォルダ($thumbdir_local)に保存する
*/
function getThumbImage($videoList , $thumbdir_local){
$baseUrl = 'http://tn-skr3.smilevideo.jp/smile?i=';
foreach($videoList as $videoId){
$connectedUrl = $baseUrl . substr($videoId ,2);
$result = doRequest($connectedUrl);
if($result != false){
$saveFileName = $thumbdir_local . DS . $videoId . '.jpg';
file_put_contents($saveFileName , $result);
}
}
}
/*
* curlを利用してGETリクエストを実行する
* ※サムネ画像を取得するのに使用する
*/
function doRequest($url){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
$data = curl_exec( $ch );
return $data;
}
/*
* 新規との差分を調べるために現在のnicono一覧を取得する
*/
function getVideoList($db){
if($db == null){
return false;
}
$selectAllVideoIdQuery = "SELECT nicono FROM videolist";
$result = mysqli_query($db,$selectAllVideoIdQuery);
$videoIdList = array();
while ( $row = mysqli_fetch_assoc($result) ){
$videoIdList[] = $row['nicono'];
}
return $videoIdList;
}
/*
* videolistからok列がfalseになっている不正動画のniconoのみを取得する
*/
function getInvalidVideoList($db){
if($db == null){
return false;
}
$selectInvalidVideoIdQuery = "SELECT nicono FROM videolist where ok = 0";
$result = mysqli_query($db,$selectInvalidVideoIdQuery);
$videoIdList = array();
while ( $row = mysqli_fetch_assoc($result) ){
$videoIdList[] = $row['nicono'];
}
return $videoIdList;
}
/*
* 指定したniconoの動画を削除する
* @input DB Connection $db
* Array $niconos
*/
function deleteVideo($db , $niconos , $deleteLog){
if($db == null){
return false;
}
foreach($niconos as $nicono){
$deleteVideoQuery = "DELETE FROM videolist where nicono = '$nicono'";
$result = mysqli_query($db,$deleteVideoQuery);
if($result == true){
fprintf( $deleteLog, date("Y-m-d h:i:s") . "---Video deleted : target:" . $nicono );
}else{
fprintf( $deleteLog, date("Y-m-d h:i:s") . "---Failed to delete video : target:" . $nicono );
}
}
}
/*
* ユーザーのニコ動登録名を取得する
* @input String $nicono
*/
function getNicoName($nicono){
if($nicono == null){
return false;
}
$URL = 'http://ext.nicovideo.jp/thumb_user/' . $nicono;
$HTML = doRequest($URL);
if($HTML == false){
return "非公開ユーザ";
}
$result = preg_match('/(<strong>).*?(<\/strong><\/a>)/' , $HTML , $matched);
if( $result == false){
return "非公開ユーザ";
}else{
$tmp = str_replace("<strong>" , "" , $matched[0]);
return str_replace("</strong></a>" , "" , $tmp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment