Commit 91b7bcc2 by Phạm Văn Đoan

tạo api lấy thông tin nhạc sĩ top 100 ở zing

parent d30690e2
...@@ -292,6 +292,35 @@ if (!function_exists('getZingSongInfoUrl')) { ...@@ -292,6 +292,35 @@ if (!function_exists('getZingSongInfoUrl')) {
} }
} }
if (!function_exists('getZingSongInfo')) {
function getZingSongInfo($api_url)
{
$composer_name = [];
if ($api_url) {
$curl = curlZingMp3($api_url);
if ($curl) {
$response = json_decode($curl);
if (isset($response->err) && $response->err == 0) {
$data = $response->data;
if (isset($data->composers)) {
$composers = $data->composers;
foreach ($composers as $key => $composer) {
$composer_name[] = $composer->name;
}
}
}
}
}
if (count($composer_name) > 0) {
return implode(', ', $composer_name);
}
return null;
}
}
if (!function_exists('convertViews')) { if (!function_exists('convertViews')) {
/** /**
* Hàm tính toán quy đổi lượt nghe thành điểm từ các hệ thống nhạc: zing/nc/nhacvn/keeng * Hàm tính toán quy đổi lượt nghe thành điểm từ các hệ thống nhạc: zing/nc/nhacvn/keeng
......
...@@ -66,6 +66,54 @@ class NctController extends Controller ...@@ -66,6 +66,54 @@ class NctController extends Controller
]); ]);
} }
/**
* API: http://localhost:8000/api/get-zing-top100
* Deploy: https://vmusicchart.vn/crawler/api/get-zing-top100
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function getZingTop100(Request $request)
{
$url = config('api.zing.playlist');
$curl = curlZingMp3($url);
$response = json_decode($curl);
//
$array_tracks = [];
if (isset($response->data) && isset($response->data->song) && isset($response->data->song->items)) {
$tracks = $response->data->song->items;
if ($tracks) {
$index = 0;
foreach ($tracks as $key => $track) {
if ($key >= 50) {
$index = 1;
}
$array_tracks[$index][] = $track;
//$zing_id = $track->id;
//$api_url = getZingSongInfoUrl($zing_id);
//$array_composer[] = getZingSongInfo($api_url);
}
}
}
//
$array_composer = [];
if (count($array_tracks) > 0) {
foreach ($array_tracks as $index => $tracks) {
foreach ($tracks as $key => $track) {
$zing_id = $track->id;
$api_url = getZingSongInfoUrl($zing_id);
$array_composer[] = getZingSongInfo($api_url);
}
}
}
return response()->json([
'code' => 200,
'message' => 'Lấy thông tin top 100 bài hát Zing thành công.',
'data' => $array_composer
]);
}
private function privateGeTrackLink($tracks_playlist, $track_id) private function privateGeTrackLink($tracks_playlist, $track_id)
{ {
if (is_array($tracks_playlist) && count($tracks_playlist) > 0) { if (is_array($tracks_playlist) && count($tracks_playlist) > 0) {
......
...@@ -18,3 +18,4 @@ Route::middleware('auth:api')->get('/user', function (Request $request) { ...@@ -18,3 +18,4 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
}); });
Route::get('/get-nct-top100', 'Api\NctController@getNctTop100'); Route::get('/get-nct-top100', 'Api\NctController@getNctTop100');
Route::get('/get-zing-top100', 'Api\NctController@getZingTop100');
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