Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crawler.vmusicchart.vn
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phạm Văn Đoan
crawler.vmusicchart.vn
Commits
12f15b9a
Commit
12f15b9a
authored
Apr 06, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task cập nhật thông tin ca sĩ cho bài hát lấy từ zing
parent
2194ab71
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
1 deletion
+190
-1
UpdateTrackArtistCommand.php
app/Console/Commands/Update/UpdateTrackArtistCommand.php
+159
-0
Kernel.php
app/Console/Kernel.php
+3
-0
TrackArtist.php
app/Models/TrackArtist.php
+4
-0
TrackUser.php
app/Models/TrackUser.php
+17
-0
User.php
app/User.php
+7
-1
No files found.
app/Console/Commands/Update/UpdateTrackArtistCommand.php
0 → 100644
View file @
12f15b9a
<?php
namespace
App\Console\Commands\Update
;
use
App\Models\Track
;
use
App\Models\TrackUser
;
use
App\Repositories\TrackRepository
;
use
App\User
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
class
UpdateTrackArtistCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'track:update-artist {src?}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Cập nhật thông tin ca sĩ, nhạc sĩ của bài hát.'
;
protected
$trackRepository
;
/**
* Create a new command instance.
*
* CalculateDailyListenCommand constructor.
* @param TrackRepository $trackRepository
*/
public
function
__construct
(
TrackRepository
$trackRepository
)
{
parent
::
__construct
();
ini_set
(
'max_execution_time'
,
-
1
);
$this
->
trackRepository
=
$trackRepository
;
}
/**
* Cập nhật thông tin ca sĩ cho bài hát theo từng hệ thống: zing, nct, keeng
*
* B1: Lấy thông tin ca sĩ về
* B2: Check trong bảng users xem đã có chưa, có thì lấy ID, chưa có thì tạo và lấy ID
* B3: Check trong bảng track_user:
* - Check cặp (track_id, name): nếu tồn tại thì update user_id, nếu chưa thì insert (track_id, user_id, name)
* - Check cặp (track_id, user_id): nếu có thì thôi, nếu chưa thì insert (track_id, usser_id, name)
*
* @return mixed
*/
public
function
handle
()
{
$src
=
$this
->
argument
(
'src'
);
if
(
empty
(
$src
)
||
!
in_array
(
$src
,
[
'zing'
,
'nct'
,
'keeng'
,
'all'
]))
{
$src
=
$this
->
choice
(
'Chọn nguồn cập nhật '
,
[
'zing'
,
'nct'
,
'keeng'
,
'all'
]);
}
echo
"
\n
Bắt đầu cập nhật ca sĩ cho bài hát."
;
switch
(
$src
)
{
case
'zing'
:
$track_id
=
[];
$track_id_fullname
=
[];
// Lấy playlist ----------------------------------------------------------------------------------------
$url
=
config
(
'api.zing.chart_realtime'
);
$curl
=
curlZingMp3
(
$url
);
$data
=
json_decode
(
$curl
);
$tracks
=
$data
->
data
->
items
;
if
(
$tracks
)
{
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
;
}
}
}
// Xử lý cập nhật
if
(
count
(
$track_id_fullname
)
>
0
)
{
$track_db
=
Track
::
select
([
'id'
,
'id_zing'
,
'title'
])
->
whereIn
(
'id_zing'
,
$track_id
)
->
get
();
$this
->
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_fullname
);
}
// Lấy bài mới xuất bản --------------------------------------------------------------------------------
$track_id
=
[];
$track_id_fullname
=
[];
$url_new_release
=
config
(
'api.zing.new_release'
);
$curl_new_release
=
curlZingMp3
(
$url_new_release
);
$data_new_release
=
json_decode
(
$curl_new_release
);
$tracks_new_release
=
$data_new_release
->
data
->
items
;
if
(
$tracks_new_release
)
{
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
;
}
}
}
// Xử lý cập nhật
if
(
count
(
$track_id_fullname
)
>
0
)
{
$track_db
=
Track
::
select
([
'id'
,
'id_zing'
,
'title'
])
->
whereIn
(
'id_zing'
,
$track_id
)
->
get
();
$this
->
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_fullname
);
}
break
;
case
'nct'
:
break
;
case
'keeng'
:
break
;
case
'all'
:
break
;
default
:
}
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
();
foreach
(
$track_db
as
$key
=>
$track
)
{
$user
=
User
::
updateOrCreate
(
[
'full_name'
=>
$track_id_fullname
[
$track
->
id_zing
]],
[
'user_type'
=>
2
,
'updated_at'
=>
Carbon
::
now
()]
);
TrackUser
::
updateOrCreate
(
[
'track_id'
=>
$track
->
id
,
'user_id'
=>
$user
->
id
],
[
'name'
=>
$track_id_fullname
[
$track
->
id_zing
]]
);
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
;
}
}
}
app/Console/Kernel.php
View file @
12f15b9a
...
...
@@ -11,6 +11,7 @@ use App\Console\Commands\Keeng\KeengCrawlerNewRealeaseCommand;
use
App\Console\Commands\Keeng\KeengCrawlerTrackCommand
;
use
App\Console\Commands\Nct\NctCrawlerTrackCommand
;
use
App\Console\Commands\NhacVn\NhacVnCrawlerTrackCommand
;
use
App\Console\Commands\Update\UpdateTrackArtistCommand
;
use
App\Console\Commands\Zing\ZingCrawlerNewRealeaseCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackCommand
;
use
App\Console\Commands\CrawlerTrackImageCommand
;
...
...
@@ -42,6 +43,8 @@ class Kernel extends ConsoleKernel
CalculateReportCommand
::
class
,
UpdateTrackArtistCommand
::
class
,
];
...
...
app/Models/TrackArtist.php
View file @
12f15b9a
...
...
@@ -9,5 +9,9 @@ class TrackArtist extends Model
{
protected
$table
=
Constants
::
TABLE_TRACK_ARTIST
;
public
$timestamps
=
false
;
protected
$fillable
=
[
'track_id'
,
'user_id'
,
'name'
,
'status'
];
}
app/Models/TrackUser.php
0 → 100644
View file @
12f15b9a
<?php
namespace
App\Models
;
use
App\Helpers\Constants
;
use
Illuminate\Database\Eloquent\Model
;
class
TrackUser
extends
Model
{
protected
$table
=
Constants
::
TABLE_TRACK_USER
;
public
$timestamps
=
false
;
protected
$fillable
=
[
'track_id'
,
'user_id'
,
'name'
,
'status'
];
}
app/User.php
View file @
12f15b9a
...
...
@@ -2,6 +2,7 @@
namespace
App
;
use
App\Helpers\Constants
;
use
Illuminate\Notifications\Notifiable
;
use
Illuminate\Foundation\Auth\User
as
Authenticatable
;
...
...
@@ -9,13 +10,18 @@ class User extends Authenticatable
{
use
Notifiable
;
protected
$table
=
Constants
::
TABLE_USERS
;
public
$timestamps
=
true
;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected
$fillable
=
[
'name'
,
'email'
,
'password'
,
'username'
,
'password'
,
'email'
,
'full_name'
,
'avatar'
,
'cover'
,
'active'
,
'user_type'
,
'link'
,
'link_nct'
,
'link_keeng'
,
'zing_id'
,
'nct_id'
,
'keeng_id'
];
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment