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
369cba97
Commit
369cba97
authored
4 years ago
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cập nhật nhạc sĩ từ NCT
parent
e0c7e6a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
37 deletions
+96
-37
UpdateTrackArtistCommand.php
app/Console/Commands/Update/UpdateTrackArtistCommand.php
+45
-34
TrackRepository.php
app/Repositories/TrackRepository.php
+51
-3
No files found.
app/Console/Commands/Update/UpdateTrackArtistCommand.php
View file @
369cba97
...
@@ -118,7 +118,7 @@ class UpdateTrackArtistCommand extends Command
...
@@ -118,7 +118,7 @@ class UpdateTrackArtistCommand extends Command
case
'nct'
:
case
'nct'
:
$track_id
=
[];
$track_id
=
[];
$track_id_singer
=
[];
$track_id_singer
=
[];
//
Lấy top 100 ---------
--------------------------------------------------------------------------------
//
Xử lý cập nhật ca sĩ
--------------------------------------------------------------------------------
$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'
);
$tracks
=
$this
->
trackRepository
->
processNctGetTrackInfoFromTop100
(
$url
);
$tracks
=
$this
->
trackRepository
->
processNctGetTrackInfoFromTop100
(
$url
);
...
@@ -138,6 +138,16 @@ class UpdateTrackArtistCommand extends Command
...
@@ -138,6 +138,16 @@ class UpdateTrackArtistCommand extends Command
$this
->
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_singer
);
$this
->
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_singer
);
}
}
// Xử lý cập nhật nhạc sĩ ------------------------------------------------------------------------------
$tracks_nct
=
$this
->
trackRepository
->
getTrackBySource
(
$src
,
null
,
100
,
true
);
$track_id_composer
=
$this
->
trackRepository
->
getComposerBySource
(
$src
,
$tracks_nct
);
if
(
count
(
$track_id_composer
)
>
0
)
{
$this
->
privateUpdateTrackSinger
(
$src
,
$tracks_nct
,
[],
$track_id_composer
);
}
else
{
echo
"
\n
- Thông tin Nhạc sĩ đã cập nhật đầy đủ trước đó."
;
}
break
;
break
;
case
'keeng'
:
case
'keeng'
:
$track_id
=
[];
$track_id
=
[];
...
@@ -166,19 +176,15 @@ class UpdateTrackArtistCommand extends Command
...
@@ -166,19 +176,15 @@ class UpdateTrackArtistCommand extends Command
$this
->
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_singer
,
$track_id_composer
);
$this
->
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_singer
,
$track_id_composer
);
}
}
//print_r($track_id_composer); die();
break
;
case
'all'
:
break
;
break
;
case
'all'
:
break
;
default
:
default
:
}
}
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_singer
,
$track_id_composer
=
null
)
private
function
privateUpdateTrackSinger
(
$src
,
$track_db
,
$track_id_singer
=
[],
$track_id_composer
=
[]
)
{
{
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
();
...
@@ -189,36 +195,41 @@ class UpdateTrackArtistCommand extends Command
...
@@ -189,36 +195,41 @@ class UpdateTrackArtistCommand extends Command
case
'keeng'
:
$src_track_id
=
$track
->
id_keeng
;
break
;
case
'keeng'
:
$src_track_id
=
$track
->
id_keeng
;
break
;
default
:
return
false
;
default
:
return
false
;
}
}
$user
=
User
::
updateOrCreate
(
[
'full_name'
=>
$track_id_singer
[
$src_track_id
]],
[
'user_type'
=>
2
,
'updated_at'
=>
Carbon
::
now
()]
);
TrackUser
::
updateOrCreate
(
[
'track_id'
=>
$track
->
id
,
'user_id'
=>
$user
->
id
],
[
'name'
=>
$track_id_singer
[
$src_track_id
]]
);
// Cập nhật sáng tác
if
(
count
(
$track_id_singer
)
>
0
&&
array_key_exists
(
$src_track_id
,
$track_id_singer
))
{
switch
(
$src
)
{
$user
=
User
::
updateOrCreate
(
case
'zing'
:
break
;
[
'full_name'
=>
$track_id_singer
[
$src_track_id
]],
case
'nct'
:
break
;
[
'user_type'
=>
2
,
'updated_at'
=>
Carbon
::
now
()]
case
'keeng'
:
);
TrackArtist
::
updateOrCreate
(
[
TrackUser
::
updateOrCreate
(
'track_id'
=>
$track
->
id
,
[
'user_id'
=>
$user
->
id
'track_id'
=>
$track
->
id
,
],
'user_id'
=>
$user
->
id
[
'name'
=>
$track_id_composer
[
$src_track_id
]]
],
);
[
'name'
=>
$track_id_singer
[
$src_track_id
]]
break
;
);
default
:
echo
"
\n
- Cập nhật xong Ca sĩ (ID: "
.
(
isset
(
$user
->
id
)
?
$user
->
id
:
''
)
.
") cho bài hát (ID: "
.
(
isset
(
$track
->
id
)
?
$track
->
id
:
''
)
.
")."
;
}
}
echo
"
\n
- Cập nhật xong Ca sĩ (ID:
$user->id
) cho bài hát (ID:
$track->id
)"
;
// Cập nhật sáng tác
if
(
count
(
$track_id_composer
)
>
0
&&
array_key_exists
(
$track
->
id
,
$track_id_composer
))
{
$user
=
User
::
updateOrCreate
(
[
'full_name'
=>
$track_id_composer
[
$track
->
id
]],
[
'user_type'
=>
2
,
'updated_at'
=>
Carbon
::
now
()]
);
TrackArtist
::
updateOrCreate
(
[
'track_id'
=>
$track
->
id
,
'user_id'
=>
$user
->
id
],
[
'name'
=>
$track_id_composer
[
$track
->
id
]]
);
echo
"
\n
- Cập nhật xong Nhạc sĩ (ID: "
.
(
isset
(
$user
->
id
)
?
$user
->
id
:
''
)
.
") cho bài hát (ID: "
.
(
isset
(
$track
->
id
)
?
$track
->
id
:
''
)
.
")."
;
}
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
app/Repositories/TrackRepository.php
View file @
369cba97
...
@@ -299,9 +299,9 @@ class TrackRepository extends BaseRepository
...
@@ -299,9 +299,9 @@ class TrackRepository extends BaseRepository
*
*
* @return array
* @return array
*/
*/
public
function
getTrackBySource
(
$src
=
'zing'
,
$crawlered
,
$limit
=
Constants
::
CRAWLER_LISTEN_LIMIT
)
public
function
getTrackBySource
(
$src
=
'zing'
,
$crawlered
,
$limit
=
Constants
::
CRAWLER_LISTEN_LIMIT
,
$is_update_composer
=
false
)
{
{
$query
=
Track
::
select
([
'id'
,
'id_zing'
,
'id_nct'
,
'id_nhacvn'
,
'id_keeng'
,
'title'
]);
$query
=
Track
::
select
([
'id'
,
'id_zing'
,
'id_nct'
,
'id_nhacvn'
,
'id_keeng'
,
'title'
,
'link_nct'
]);
if
(
is_array
(
$crawlered
)
&&
count
(
$crawlered
)
>
0
)
{
if
(
is_array
(
$crawlered
)
&&
count
(
$crawlered
)
>
0
)
{
$query
->
whereNotIn
(
'id'
,
$crawlered
);
$query
->
whereNotIn
(
'id'
,
$crawlered
);
...
@@ -309,7 +309,12 @@ class TrackRepository extends BaseRepository
...
@@ -309,7 +309,12 @@ class TrackRepository extends BaseRepository
switch
(
$src
)
{
switch
(
$src
)
{
case
'zing'
:
$query
->
whereNotNull
(
'id_zing'
)
->
where
(
'id_zing'
,
'<>'
,
''
);
break
;
case
'zing'
:
$query
->
whereNotNull
(
'id_zing'
)
->
where
(
'id_zing'
,
'<>'
,
''
);
break
;
case
'nct'
:
$query
->
whereNotNull
(
'id_nct'
)
->
where
(
'id_nct'
,
'<>'
,
''
);
break
;
case
'nct'
:
$query
->
whereNotNull
(
'id_nct'
)
->
where
(
'id_nct'
,
'<>'
,
''
);
if
(
$is_update_composer
)
{
$query
->
whereNull
(
'composer_list'
);
}
break
;
case
'nhacvn'
:
$query
->
whereNotNull
(
'id_nhacvn'
)
->
where
(
'id_nhacvn'
,
'<>'
,
''
);
break
;
case
'nhacvn'
:
$query
->
whereNotNull
(
'id_nhacvn'
)
->
where
(
'id_nhacvn'
,
'<>'
,
''
);
break
;
case
'keeng'
:
$query
->
whereNotNull
(
'id_keeng'
)
->
where
(
'id_keeng'
,
'<>'
,
''
);
break
;
case
'keeng'
:
$query
->
whereNotNull
(
'id_keeng'
)
->
where
(
'id_keeng'
,
'<>'
,
''
);
break
;
}
}
...
@@ -318,6 +323,10 @@ class TrackRepository extends BaseRepository
...
@@ -318,6 +323,10 @@ class TrackRepository extends BaseRepository
$query
->
take
(
$limit
);
$query
->
take
(
$limit
);
}
}
if
(
$is_update_composer
)
{
return
$query
->
get
();
}
return
$query
->
get
()
->
toArray
();
return
$query
->
get
()
->
toArray
();
}
}
...
@@ -388,5 +397,43 @@ class TrackRepository extends BaseRepository
...
@@ -388,5 +397,43 @@ class TrackRepository extends BaseRepository
->
get
();
->
get
();
}
}
/**
* Hàm lấy ds Nhạc sĩ ở các trang nhạc, đặc biệt lấy ở NCT
*
* @param $src
* @param $tracks_nct
* @param int $limit
*
* @return array
*/
public
function
getComposerBySource
(
$src
,
$tracks_nct
,
$limit
=
500
)
{
$tracks
=
[];
switch
(
$src
)
{
case
'zing'
:
break
;
case
'nct'
:
foreach
(
$tracks_nct
as
$key
=>
$track
)
{
$dom
=
new
Htmldom
(
$track
[
'link_nct'
]);
//
$element_track_composer
=
'div#_divLyricHtml div.pd_name_lyric p.name_post'
;
foreach
(
$dom
->
find
(
$element_track_composer
)
as
$data
)
{
if
(
strpos
(
$data
->
innertext
,
'Nhạc sĩ:'
)
!==
false
)
{
$tracks
[
$track
[
'id'
]]
=
trim
(
str_replace
([
'Nhạc sĩ:'
],
[
''
],
$data
->
innertext
));
}
}
if
(
empty
(
$tracks
[
$track
[
'id'
]]))
{
$tracks
[
$track
[
'id'
]]
=
'Đang Cập Nhật'
;
}
}
break
;
case
'keeng'
:
break
;
default
:
}
return
$tracks
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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