Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add Livetube and CaveTube support
Signed-off-by: kazy111 <kazy@kazy111.info>
  • Loading branch information
kazy111 committed May 10, 2012
1 parent 71cb810 commit 149fef9
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 18 deletions.
24 changes: 21 additions & 3 deletions assoc_define.php
Expand Up @@ -7,21 +7,27 @@
2 => 'stickam',
3 => 'nicolive',
4 => 'twitcasting',
5 => 'own3d');
5 => 'own3d',
6 => 'livetube',
7 => 'cavetube');

$service_abb_assoc = array(0 => 'Ust',
1 => 'Jst',
2 => 'Stk',
3 => 'Nic',
4 => 'Twc',
5 => 'Own');
5 => 'Own',
6 => 'Lvt',
7 => 'Cvt');

$service_org_assoc = array(0 => FALSE,
1 => FALSE,
2 => TRUE,
3 => TRUE,
4 => TRUE,
5 => FALSE);
5 => FALSE,
6 => TRUE,
7 => TRUE);

$chat_assoc = array(0 => 'c.ustream.tv',
1 => 'irc.mibbit.com',
Expand Down Expand Up @@ -67,6 +73,12 @@ function get_service_url($type, $ch_name, $ch_id)
case 5: // own3D
$ret = 'http://www.own3d.tv/live/'.$ch_id;
break;
case 6: // LiveTube
$ret = 'http://livetube.cc/'.($ch_id == '' ? $ch_name : $ch_id);
break;
case 7: // CaveTube
$ret = ($ch_id == null ? 'http://gae.cavelis.net/user/'.$ch_name : 'http://gae.cavelis.net/view/'.$ch_id);
break;
}
return $ret;
}
Expand All @@ -92,6 +104,12 @@ function get_archive_url($type, $ch_name, $opt_id)
case 5: // own3d
$ret = '';
break;
case 6: // livetube
$ret = 'http://livetube.cc/'.$ch_name;
break;
case 7: // cavetube
$ret = 'http://gae.cavelis.net/user/'.$ch_name;
break;
}
return $ret;
}
Expand Down
162 changes: 156 additions & 6 deletions check.php
Expand Up @@ -30,7 +30,8 @@ function start_tweet($data, $topic_flag = TRUE)
$topic = '';
}

if($GLOBALS['limit_keywords'] != '' && preg_match('/'.$GLOBALS['limit_keywords'].'/', $topic) == 0 ) {
$check = $topic . ' ' . $data['name'];
if($GLOBALS['limit_keywords'] != '' && preg_match('/'.$GLOBALS['limit_keywords'].'/', $check) == 0 ) {
// when set limit keywords, tweet only keyword including
return;
}
Expand Down Expand Up @@ -59,13 +60,12 @@ function end_tweet($data, $topic_flag = TRUE)
$topic = '';
}


if($GLOBALS['limit_keywords'] != '' && preg_match('/'.$GLOBALS['limit_keywords'].'/', $topic) == 0 ) {
$check = $topic . ' ' . $data['name'];
if($GLOBALS['limit_keywords'] != '' && preg_match('/'.$GLOBALS['limit_keywords'].'/', $check) == 0 ) {
// when set limit keywords, tweet only keyword including
return;
}


$cutlen = 140-strlen($hash)-mb_strlen($str, 'UTF-8')-strlen($time);
if(mb_strlen($topic, 'UTF-8') > $cutlen)
$topic = mb_substr($topic, 0, $cutlen-1, 'UTF-8').'…';
Expand Down Expand Up @@ -113,6 +113,8 @@ function check()
check_nicolive();
check_twitcasting();
check_own3d();
check_livetube();
check_cavetube();
}


Expand Down Expand Up @@ -625,7 +627,7 @@ function check_nicolive_official()
log_print('start checking nicolive(official).');


$url = 'http://live.nicovideo.jp/rss';
$url = 'http://live.nicovideo.jp/recent/rss';

log_print($url);
try{
Expand All @@ -636,14 +638,21 @@ function check_nicolive_official()
$items = $xml->channel->item;
if ($items) {
for ($i = 0; $i < count($items); $i++) {


// if already added, then skip
if ($manager->check_already_registered(3, $items[$i]->guid, NULL)) {
continue;
}
// if program type is community, then skip
$nicolive = $items[$i]->children('http://live.nicovideo.jp/');
if ($nicolive->type == 'community') {
continue;
}

// now add streamer as templrary
$check = $items[$i]->title;
$desc = addslashes(strip_tags($items[$i]->description));
$check = $items[$i]->title . ' ' . $desc;
if (preg_match('/'.$GLOBALS['limit_keywords'].'/', $check) > 0){
log_print('register to temporary '.$items[$i]->title);
$manager->register($items[$i]->title, $desc,
Expand Down Expand Up @@ -807,6 +816,147 @@ function check_own3d()



// check LiveTube function
function check_livetube()
{

global $manager, $chs, $sid_chs;

$ids = array();
$hash = array();
$live = array();

log_print('start checking LiveTube.');

foreach($chs as $k => $v){
if($v['type']==6){
$hash[$v['ch_name']] = $v['pid'];
$ids[] = $v['ch_name'];
$live[$v['pid']] = 0;
}
}

$url = 'http://livetube.cc/index.live.xml';

log_print($url);
try{
$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
if (! $xml ) throw new Exception('URL open failed : '.$url);

foreach($xml->entry as $ch){
//print_r($ch);

$name = (string)$ch->author->name;
if(!$name || $name == '' || !array_key_exists($name, $hash)) continue; // error

$title = $ch->title;
$live_id = urldecode(substr($ch->id, 19));
$viewer = 0;
$pid = $hash[$name];
$change_flag = $chs[$pid]['live'] == 'f' || $chs[$pid]['live'] == '0' || $chs[$pid]['live'] == '';
$thumb = '';

log_print("<b>name:</b> ".$name." / ".$viewer);
$manager->update_program($pid, TRUE, $viewer, $change_flag, $thumb, $title, $live_id);

if($change_flag && !check_prev_live($pid, $sid_chs[$chs[$pid]['sid']]))
start_tweet($chs[$pid]);

$live[$pid] = 1;
}

foreach($live as $k => $v){
if( $v == 0 && ($chs[$k]['live']=='t' || $chs[$k]['live']=='1') ){

$manager->update_program($k, FALSE, 0, 1, '');

$start_time = $chs[$k]['start_time'];
$manager->add_history($k, $start_time, date('Y-m-d H:i:s'));
if(!check_prev_live($k, $sid_chs[$chs[$k]['sid']]))
end_tweet($chs[$k]);

}
}
}catch(Exception $e){
print $e->getMessage();
continue;
}

log_print('finish checking LiveTube.');
}



// check CaveTube function
function check_cavetube()
{

global $manager, $chs, $sid_chs;

$ids = array();
$hash = array();
$live = array();

log_print('start checking CaveTube.');

foreach($chs as $k => $v){
if($v['type']==7){
$hash[$v['ch_name']] = $v['pid'];
$ids[] = $v['ch_name'];
$live[$v['pid']] = 0;
}
}

$url = 'http://gae.cavelis.net/index_live.xml';

log_print($url);
try{
$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
if (! $xml ) throw new Exception('URL open failed : '.$url);

foreach($xml->entry as $ch){
//print_r($ch);

$name = (string)$ch->author->name;
if(!$name || $name == '' || !array_key_exists($name, $hash)) continue; // error

$title = $ch->title . ' / ' . $ch->content;
$live_id = substr($ch->id, 28);
$viewer = 0;
$pid = $hash[$name];
$change_flag = $chs[$pid]['live'] == 'f' || $chs[$pid]['live'] == '0' || $chs[$pid]['live'] == '';
$thumb = 'http://img.cavelis.net/userthumbnails/m/'.$name.'.jpg';

log_print("<b>name:</b> ".$name." / ".$viewer);
$manager->update_program($pid, TRUE, $viewer, $change_flag, $thumb, $title, $live_id);

if($change_flag && !check_prev_live($pid, $sid_chs[$chs[$pid]['sid']]))
start_tweet($chs[$pid]);

$live[$pid] = 1;
}

foreach($live as $k => $v){
if( $v == 0 && ($chs[$k]['live']=='t' || $chs[$k]['live']=='1') ){

$manager->update_program($k, FALSE, 0, 1, '');

$start_time = $chs[$k]['start_time'];
$manager->add_history($k, $start_time, date('Y-m-d H:i:s'));
if(!check_prev_live($k, $sid_chs[$chs[$k]['sid']]))
end_tweet($chs[$k]);

}
}
}catch(Exception $e){
print $e->getMessage();
continue;
}

log_print('finish checking CaveTube.');
}



check();

Expand Down
2 changes: 1 addition & 1 deletion classes/database/IDataManager.php
Expand Up @@ -7,7 +7,7 @@ function get_streamer_info($streamer_id);

// status update
function update_chat($cid, $member, $topic);
function update_program($pid, $live, $viewer, $change_flag, $thumb, $title = null);
function update_program($pid, $live, $viewer, $change_flag, $thumb, $title = null, $live_id=null);

function increment_offline_count($pid);

Expand Down
4 changes: 2 additions & 2 deletions classes/database/MySQLDataManager.php
Expand Up @@ -55,7 +55,7 @@ function update_chat($cid, $member, $topic){
$ret = $this->db->query($sql);
}

function update_program($pid, $live, $viewer, $change_flag, $thumb, $title=null){
function update_program($pid, $live, $viewer, $change_flag, $thumb, $title=null, $live_id=null){
$sql_live = $live ? '1' : '0';
// construct time SQL
$sql_time = ', start_time = start_time, end_time = end_time ';
Expand All @@ -65,12 +65,12 @@ function update_program($pid, $live, $viewer, $change_flag, $thumb, $title=null)
$sql_time = ', start_time = \''.$now.'\' ';
}else{
$sql_time = ', end_time = \''.$now.'\' ';
// TODO add history
}
}
$sql = 'update program_table set live = '.$sql_live.' , viewer = '.$viewer
. $sql_time.', thumbnail = \''. $thumb .'\', offline_count = 0 '
. ($title != null ? ' ,title = \''. addslashes($title) .'\' ' : '')
. ($live_id != null ? ' ,optional_id = \''. addslashes($live_id) .'\' ' : '')
. ' where id = '.$pid;
print($sql);
$this->db->query($sql);
Expand Down
4 changes: 2 additions & 2 deletions classes/database/PostgreSQLDataManager.php
Expand Up @@ -55,7 +55,7 @@ function update_chat($cid, $member, $topic){
$ret = $this->db->query($sql);
}

function update_program($pid, $live, $viewer, $change_flag, $thumb, $title=null){
function update_program($pid, $live, $viewer, $change_flag, $thumb, $title=null, $live_id=null){
$sql_live = $live ? 'TRUE' : 'FALSE';
// construct time SQL
$sql_time = '';
Expand All @@ -65,12 +65,12 @@ function update_program($pid, $live, $viewer, $change_flag, $thumb, $title=null)
$sql_time = ', start_time = \''.$now.'\' ';
}else{
$sql_time = ', end_time = \''.$now.'\' ';
// TODO add history
}
}
$sql = 'update program_table set live = '.$sql_live.' , viewer = '.$viewer
. $sql_time.', thumbnail = \''. $thumb .'\', offline_count = 0 '
. ($title != null ? ' ,title = \''. addslashes($title) .'\' ' : '')
. ($live_id != null ? ' ,optional_id = \''. addslashes($live_id) .'\' ' : '')
. ' where id = '.$pid;
$this->db->query($sql);
}
Expand Down
4 changes: 2 additions & 2 deletions index_content.php
Expand Up @@ -194,8 +194,8 @@ function cmp_common( $a, $b ){
}
if($GLOBALS['limit_keywords'] != '' && $a['live'] && $b['live'] ){
// when set limit keywords, give priority to keyword including
$atitle = $a['topic'];
$btitle = $b['topic'];
$atitle = $a['topic'] . ' ' . $a['name'];
$btitle = $b['topic'] . ' ' . $b['name'];
$_keywords = '/'.$GLOBALS['limit_keywords'].'/';

if( preg_match($_keywords, $atitle) > 0 && preg_match($_keywords, $btitle) == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion js/auto_notice.js
Expand Up @@ -16,7 +16,7 @@ function notice_process(data)
else{
$('#notice').html(names.join('、')+'配信が始まりました!');
}
$('#notice').bind("click", function(){ location.reload(); })
$('#notice').bind("click", function(){ location.reload(true); })
$('#notice').slideDown();
}else{
$('#notice').slideUp();
Expand Down
2 changes: 1 addition & 1 deletion themes/Twitter/theme.css
Expand Up @@ -88,7 +88,7 @@ img{

.streamer:hover .tweet-menu{
display: block;
float: right;
text-align: right;
}

.content-arrow{
Expand Down

0 comments on commit 149fef9

Please sign in to comment.