Commit e0c7e6a2 by Phạm Văn Đoan

cập nhật lấy thông tin nghệ sĩ từ keeng

parent 14804614
......@@ -3,6 +3,7 @@
namespace App\Console\Commands\Update;
use App\Models\Track;
use App\Models\TrackArtist;
use App\Models\TrackUser;
use App\Repositories\TrackRepository;
use App\User;
......@@ -64,7 +65,7 @@ class UpdateTrackArtistCommand extends Command
switch ($src) {
case 'zing':
$track_id = [];
$track_id_fullname = [];
$track_id_singer = [];
// Lấy playlist ----------------------------------------------------------------------------------------
$url = config('api.zing.chart_realtime');
$curl = curlZingMp3($url);
......@@ -74,22 +75,22 @@ class UpdateTrackArtistCommand extends Command
foreach ($tracks as $key => $track) {
if (isset($track->title) && isset($track->artists_names) && !empty($track->artists_names)) {
$track_id[] = $track->id;
$track_id_fullname[$track->id] = $track->artists_names;
$track_id_singer[$track->id] = $track->artists_names;
}
}
}
// Xử lý cập nhật
if (count($track_id_fullname) > 0) {
$track_db = Track::select(['id', 'id_zing', 'title'])
if (count($track_id_singer) > 0) {
$track_db = Track::select(['id', 'id_zing', 'id_nct', 'id_keeng', 'title'])
->whereIn('id_zing', $track_id)
->get();
$this->privateUpdateTrackSinger($src, $track_db, $track_id_fullname);
$this->privateUpdateTrackSinger($src, $track_db, $track_id_singer);
}
// Lấy bài mới xuất bản --------------------------------------------------------------------------------
$track_id = [];
$track_id_fullname = [];
$track_id_singer = [];
$url_new_release = config('api.zing.new_release');
$curl_new_release = curlZingMp3($url_new_release);
......@@ -100,23 +101,23 @@ class UpdateTrackArtistCommand extends Command
foreach ($tracks_new_release as $key => $track) {
if (isset($track->title) && isset($track->artists_names) && !empty($track->artists_names)) {
$track_id[] = $track->id;
$track_id_fullname[$track->id] = $track->artists_names;
$track_id_singer[$track->id] = $track->artists_names;
}
}
}
// Xử lý cập nhật
if (count($track_id_fullname) > 0) {
$track_db = Track::select(['id', 'id_zing', 'title'])
if (count($track_id_singer) > 0) {
$track_db = Track::select(['id', 'id_zing', 'id_nct', 'id_keeng', 'title'])
->whereIn('id_zing', $track_id)
->get();
$this->privateUpdateTrackSinger($src, $track_db, $track_id_fullname);
$this->privateUpdateTrackSinger($src, $track_db, $track_id_singer);
}
break;
case 'nct':
$track_id = [];
$track_id_fullname = [];
$track_id_singer = [];
// Lấy top 100 -----------------------------------------------------------------------------------------
$url = config('api.nct.top100');
$url_playlist_top100 = config('api.nct.playlist_top100');
......@@ -125,21 +126,48 @@ class UpdateTrackArtistCommand extends Command
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'];
$track_id_singer[$track['id_nct']] = $track['singer'];
}
}
}
if (count($track_id_fullname) > 0) {
if (count($track_id_singer) > 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);
$this->privateUpdateTrackSinger($src, $track_db, $track_id_singer);
}
break;
case 'keeng':
$track_id = [];
$track_id_singer = [];
$track_id_composer = [];
//
$url = getKeengUrlNewRealease(1, 500);
$curl = cURL($url);
$data = json_decode($curl);
$tracks = $data->data;
if ($tracks) {
foreach ($tracks as $key => $track) {
if (isset($track->identify) && isset($track->singer) && !empty($track->singer)) {
$track_id[] = $track->identify;
$track_id_singer[$track->identify] = $track->singer;
$composer = (isset($track->info_extra) && isset($track->info_extra->author_name)) ? $track->info_extra->author_name : '?';
$track_id_composer[$track->identify] = $composer;
}
}
}
// Xử lý cập nhật
if (count($track_id_singer) > 0) {
$track_db = Track::select(['id', 'id_zing', 'id_nct', 'id_keeng', 'title'])
->whereIn('id_keeng', $track_id)
->get();
$this->privateUpdateTrackSinger($src, $track_db, $track_id_singer, $track_id_composer);
}
//print_r($track_id_composer); die();
break;
case 'all':
......@@ -147,12 +175,10 @@ 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)
private function privateUpdateTrackSinger($src, $track_db, $track_id_singer, $track_id_composer=null)
{
echo "\n Cập nhật cho tổng số bài: " . $track_db->count();
......@@ -164,7 +190,7 @@ class UpdateTrackArtistCommand extends Command
default: return false;
}
$user = User::updateOrCreate(
['full_name' => $track_id_fullname[$src_track_id]],
['full_name' => $track_id_singer[$src_track_id]],
['user_type' => 2, 'updated_at' => Carbon::now()]
);
......@@ -173,9 +199,25 @@ class UpdateTrackArtistCommand extends Command
'track_id' => $track->id,
'user_id' => $user->id
],
['name' => $track_id_fullname[$src_track_id]]
['name' => $track_id_singer[$src_track_id]]
);
// Cập nhật sáng tác
switch ($src) {
case 'zing': break;
case 'nct': break;
case 'keeng':
TrackArtist::updateOrCreate(
[
'track_id' => $track->id,
'user_id' => $user->id
],
['name' => $track_id_composer[$src_track_id]]
);
break;
default:
}
echo "\n - Cập nhật xong Ca sĩ (ID: $user->id) cho bài hát (ID: $track->id)";
}
}
......
......@@ -32,7 +32,7 @@ class Constants
const TABLE_ROLE_USER = 'role_user';
const TABLE_ROLES = 'roles';
const TABLE_TRACK_ARTIST = 'track_artist';
const TABLE_TRACK_ARTIST = 'track_artists';
const TABLE_TRACK_USER = 'track_user';
const TABLE_TRACKS = 'tracks';
......
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