ようつべのコメントバックアップ機能性
このコミットが含まれているのは:
コミット
e5aad4f0a4
|
@ -35,12 +35,14 @@ class Prayer {
|
|||
|
||||
$comments = DB::table('blg_comments')->where('video_id', $vid)->orderBy('id', 'asc')->get()->toArray();
|
||||
$ytslug = explode('?v=', $res->youtube);
|
||||
$res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1]) : array());
|
||||
$res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1], $slugger) : array());
|
||||
if (isset($res->ytcomment['nextPage']) && $res->ytcomment['nextPage'] != '') {
|
||||
while ($res->ytcomment['nextPage'] != '') {
|
||||
$res->ytcomment = $this->checkYouTubeCome($res->ytcomment, $ytslug[1], $res->ytcomment['nextPage']);
|
||||
}
|
||||
}
|
||||
|
||||
$res->ytcomment = $this->backupYTComment($slugger, $res->ytcomment);
|
||||
$res->nicocomment = array();
|
||||
$res->bccomment = array();
|
||||
$res->lbcomment = array();
|
||||
|
@ -78,7 +80,7 @@ class Prayer {
|
|||
}
|
||||
|
||||
function checkYouTubeCome ($res, $slug, $next='') {
|
||||
$come = $this->getYouTubeCome($slug, $next);
|
||||
$come = $this->getYouTubeCome($slug, '', $next);
|
||||
foreach ($come['come'] as $com) { $res['come'][] = $com; }
|
||||
$res['total'] += $come['total'];
|
||||
$res['nextPage'] = $come['nextPage'];
|
||||
|
@ -86,7 +88,7 @@ class Prayer {
|
|||
return $res;
|
||||
}
|
||||
|
||||
function getYouTubeCome ($slug, $page='') {
|
||||
function getYouTubeCome ($slug, $tslug, $page='') {
|
||||
$ch = curl_init();
|
||||
$url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=published&videoId='.$slug.'&key='.env('YOUTUBE_API').'&pageToken='.$page;//.'&order=date&pageToken='.$page;
|
||||
|
||||
|
@ -99,15 +101,23 @@ class Prayer {
|
|||
|
||||
$come = array();
|
||||
$get = json_decode($get, false);
|
||||
if (isset($get->error)) return array();
|
||||
$come['come'] = array();
|
||||
|
||||
if (isset($get->error)) {
|
||||
if ($tslug != '') {
|
||||
if (!$get = DB::table('vid_ytcomment')->where('vid', $tslug)->first()) return array();
|
||||
$come = unserialize($get->come);
|
||||
return $come;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($get->items as $g) {
|
||||
$g->comment = new \stdClass();
|
||||
$g->comment->id = $g->id;
|
||||
$g->comment->name = $g->snippet->topLevelComment->snippet->authorDisplayName;
|
||||
$g->comment->channel = $g->snippet->topLevelComment->snippet->authorChannelUrl;
|
||||
$g->comment->icon = $g->snippet->topLevelComment->snippet->authorProfileImageUrl;
|
||||
$g->comment->createdTS = strtotime($g->snippet->topLevelComment->snippet->publishedAt);
|
||||
$g->comment->created = date('Y年m月d日 H:i:s', strtotime($g->snippet->topLevelComment->snippet->publishedAt));
|
||||
$g->comment->message = strip_tags($g->snippet->topLevelComment->snippet->textDisplay, array('<br />'));
|
||||
$g->comment->replyCount = (isset($g->snippet->totalReplyCount) ? $g->snippet->totalReplyCount : 0);
|
||||
|
@ -116,12 +126,13 @@ class Prayer {
|
|||
if (isset($g->replies)) {
|
||||
$g->comment->replies = array();
|
||||
foreach ($g->replies->comments as $k => $c) {
|
||||
$g->comment->replies[$k]['id'] = $c->id;
|
||||
$g->comment->replies[$k]['name'] = $c->snippet->authorDisplayName;
|
||||
$g->comment->replies[$k]['channel'] = $c->snippet->authorChannelUrl;
|
||||
$g->comment->replies[$k]['icon'] = $c->snippet->authorProfileImageUrl;
|
||||
$g->comment->replies[$k]['created'] = date('Y年m月d日 H:i:s', strtotime($c->snippet->publishedAt));
|
||||
$g->comment->replies[$k]['message'] = strip_tags($c->snippet->textDisplay, array('<br />'));
|
||||
$g->comment->replies[$k]['id'] = (isset($c->id) ? $c->id : $c['id']);
|
||||
$g->comment->replies[$k]['name'] = (isset($c->snippet->authorDisplayName) ? $c->snippet->authorDisplayName : $c['snippet']['authorDisplayName']);
|
||||
$g->comment->replies[$k]['channel'] = (isset($c->snippet->authorChannelUrl) ? $c->snippet->authorChannelUrl : $c['snippet']['authorChannelUrl']);
|
||||
$g->comment->replies[$k]['icon'] = (isset($c->snippet->authorProfileImageUrl) ? $c->snippet->authorProfileImageUrl : $c['snippet']['authorProfileImageUrl']);
|
||||
$g->comment->replies[$k]['createdTS'] = strtotime((isset($c->snippet->publishedAt) ? $c->snippet->publishedAt : $c['snippet']['publishedAt']));
|
||||
$g->comment->replies[$k]['created'] = date('Y年m月d日 H:i:s', strtotime((isset($c->snippet->publishedAt) ? $c->snippet->publishedAt : $c['snippet']['publishedAt'])));
|
||||
$g->comment->replies[$k]['message'] = strip_tags((isset($c->snippet->textDisplay) ? $c->snippet->textDisplay : $c['snippet']['textDisplay']), array('<br />'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,4 +145,33 @@ class Prayer {
|
|||
|
||||
return $come;
|
||||
}
|
||||
}
|
||||
|
||||
function backupYTComment ($slug, $com) {
|
||||
foreach ($com['come'] as $c) {
|
||||
$icon = substr($c->icon, 0, strpos($c->icon, "="));
|
||||
$icon = str_replace('https://yt3.ggpht.com/ytc/', '', $icon).'.jpg';
|
||||
if ($icon != '.jpg') {
|
||||
$isicon = array_diff(scandir(dirname(__DIR__, 4).'/storage/app/public/yt_icon'), array('..', '.'));
|
||||
if (!in_array($icon, $isicon)) passthru('wget -O '.dirname(__DIR__, 4).'/storage/app/public/yt_icon/'.$icon.' '.$c->icon);
|
||||
$c->icon = '/storage/yt_icon/'.$icon;
|
||||
}
|
||||
|
||||
if (isset($c->replies)) {
|
||||
foreach ($c->replies as $i => $r) {
|
||||
$icon = substr($r['icon'], 0, strpos($r['icon'], "="));
|
||||
$icon = str_replace('https://yt3.ggpht.com/ytc/', '', $icon).'.jpg';
|
||||
if ($icon != '.jpg') {
|
||||
$isicon = array_diff(scandir(dirname(__DIR__, 4).'/storage/app/public/yt_icon'), array('..', '.'));
|
||||
if (!in_array($icon, $isicon)) passthru('wget -O '.dirname(__DIR__, 4).'/storage/app/public/yt_icon/'.$icon.' '.$r['icon']);
|
||||
$c->replies[$i]['icon'] = '/storage/yt_icon/'.$icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($chk = DB::table('vid_ytcomment')->where('vid', $slug)->first()) DB::table('vid_ytcomment')->where('vid', $slug)->update(['come' => serialize($com)]);
|
||||
else DB::table('vid_ytcomment')->insert(['vid' => $slug, 'come' => serialize($com)]);
|
||||
|
||||
return $com;
|
||||
}
|
||||
}
|
新しいイシューから参照