Commit 14804614 by Phạm Văn Đoan

cập nhật lấy thông tin ca sĩ từ trang nct

parent 12f15b9a
......@@ -61,7 +61,6 @@ class UpdateTrackArtistCommand extends Command
echo "\n Bắt đầu cập nhật ca sĩ cho bài hát.";
switch ($src) {
case 'zing':
$track_id = [];
......@@ -116,7 +115,28 @@ class UpdateTrackArtistCommand extends Command
}
break;
case 'nct':
$track_id = [];
$track_id_fullname = [];
// Lấy top 100 -----------------------------------------------------------------------------------------
$url = config('api.nct.top100');
$url_playlist_top100 = config('api.nct.playlist_top100');
$tracks = $this->trackRepository->processNctGetTrackInfoFromTop100($url);
if ($tracks) {
foreach ($tracks as $key => $track) {
if (isset($track['title']) && isset($track['singer'])) {
$track_id[] = $track['id_nct'];
$track_id_fullname[$track['id_nct']] = $track['singer'];
}
}
}
if (count($track_id_fullname) > 0) {
$track_db = Track::select(['id', 'id_zing', 'id_nct', 'id_keeng', 'title'])
->whereIn('id_nct', $track_id)
->get();
$this->privateUpdateTrackSinger($src, $track_db, $track_id_fullname);
}
break;
case 'keeng':
......@@ -127,17 +147,24 @@ class UpdateTrackArtistCommand extends Command
default:
}
//print_r($track_id_fullname); die();
echo "\n Kết thúc cập nhật ca sĩ cho bài hát. \n";
}
private function privateUpdateTrackSinger($src, $track_db, $track_id_fullname)
{
switch ($src) {
case 'zing':
echo "\n Zing: Cập nhật cho tổng số bài: " . $track_db->count();
echo "\n Cập nhật cho tổng số bài: " . $track_db->count();
foreach ($track_db as $key => $track) {
switch ($src) {
case 'zing': $src_track_id = $track->id_zing; break;
case 'nct': $src_track_id = $track->id_nct; break;
case 'keeng': $src_track_id = $track->id_keeng; break;
default: return false;
}
$user = User::updateOrCreate(
['full_name' => $track_id_fullname[$track->id_zing]],
['full_name' => $track_id_fullname[$src_track_id]],
['user_type' => 2, 'updated_at' => Carbon::now()]
);
......@@ -146,14 +173,10 @@ class UpdateTrackArtistCommand extends Command
'track_id' => $track->id,
'user_id' => $user->id
],
['name' => $track_id_fullname[$track->id_zing]]
['name' => $track_id_fullname[$src_track_id]]
);
echo "\n - Cập nhật xong Ca sĩ (ID: $user->id) cho bài hát (ID: $track->id)";
}
break;
case 'nct': break;
case 'keeng': break;
}
}
}
......@@ -104,9 +104,14 @@ class TrackRepository extends BaseRepository
}
/* Lấy tên ca sĩ hát ---------------------------------------------------------------------------------------- */
$element_track_singer = 'div.box_info_field h4.list_name_singer a';
$element_track_singer = 'div.box_info_field h3 a';
foreach ($dom->find($element_track_singer) as $data) {
$tracks['singer'][] = str_replace([], [], $data->innertext);
$info = explode('-', $data->title);
if (count($info) >= 2) {
$tracks['singer'][] = trim($info[1]);
} else {
$tracks['singer'][] = '?';
}
}
/* Lấy url thông tin cá nhân ca sĩ -------------------------------------------------------------------------- */
......@@ -142,6 +147,7 @@ class TrackRepository extends BaseRepository
$result[$i]['title'] = $tracks['title'][$i];
$result[$i]['link'] = $tracks['link'][$i];
$result[$i]['img'] = $tracks['img'][$i];
$result[$i]['singer'] = $tracks['singer'][$i];
}
return $result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment