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