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
7caf7995
Commit
7caf7995
authored
Mar 25, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
thiết lập thời gian chạy cho lấy bài hát mới phát hành
parent
8063f024
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
1 deletion
+132
-1
ZingCrawlerNewRealeaseCommand.php
app/Console/Commands/Zing/ZingCrawlerNewRealeaseCommand.php
+128
-0
Kernel.php
app/Console/Kernel.php
+4
-1
No files found.
app/Console/Commands/Zing/ZingCrawlerNewRealeaseCommand.php
0 → 100644
View file @
7caf7995
<?php
namespace
App\Console\Commands\Zing
;
use
App\Helpers\Constants
;
use
App\Models\Crontjob
;
use
App\Repositories\TrackRepository
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\DB
;
class
ZingCrawlerNewRealeaseCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'zing:get-new-release-track'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Lấy những bài hát mới phát hành'
;
protected
$trackRepository
;
/**
* Create a new command instance.
*
* ZingCrawlerNewRealeaseCommand constructor.
* @param TrackRepository $trackRepository
*/
public
function
__construct
(
TrackRepository
$trackRepository
)
{
parent
::
__construct
();
$this
->
trackRepository
=
$trackRepository
;
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
echo
"
\n
Bắt đầu xử lý lấy bài hát mới phát hành từ zing mp3."
;
// Lấy mảng ID của Zing những hát đã insert
$inserted
=
$this
->
trackRepository
->
getTrackInserted
(
'title'
,
'original'
,
[]);;
// Lấy ds BXH về
$domain
=
config
(
'api.zing.domain'
);
$url
=
config
(
'api.zing.new_release'
);
$curl
=
curlZingMp3
(
$url
);
$data
=
json_decode
(
$curl
);
$tracks
=
$data
->
data
->
items
;
$bulk_track_insert
=
[];
$bulk_track_update
=
[];
$key_insert
=
0
;
$key_update
=
0
;
foreach
(
$tracks
as
$key
=>
$track
)
{
if
(
isset
(
$track
->
title
))
{
// Lấy ds ca sĩ thể hiện
$singer_list
=
'ZingMp3'
;
$artists
=
isset
(
$track
->
artists
)
?
$track
->
artists
:
[];
if
(
is_array
(
$artists
)
&&
count
(
$artists
)
>
0
)
{
$artist_list
=
collect
(
$artists
)
->
map
(
function
(
$item
){
return
$item
->
name
;
})
->
all
();
$singer_list
=
implode
(
','
,
$artist_list
);
}
// Xử lý insert/update dựa vào tên bài hát
if
(
is_array
(
$inserted
)
&&
count
(
$inserted
)
>
0
&&
in_array
(
$track
->
title
,
$inserted
))
{
$bulk_track_update
[
$key_update
][
'title'
]
=
isset
(
$track
->
title
)
?
$track
->
title
:
'unknown-title'
;
$bulk_track_update
[
$key_update
][
'slug'
]
=
isset
(
$track
->
alias
)
?
$track
->
alias
:
null
;
$bulk_track_update
[
$key_update
][
'userid'
]
=
0
;
$bulk_track_update
[
$key_update
][
'tag'
]
=
'vmusic'
;
$bulk_track_update
[
$key_update
][
'genre'
]
=
1
;
$bulk_track_update
[
$key_update
][
'download_hash'
]
=
md5
(
$track
->
alias
);
$bulk_track_update
[
$key_update
][
'time'
]
=
time
();
$bulk_track_update
[
$key_update
][
'link'
]
=
isset
(
$track
->
link
)
?
$domain
.
$track
->
link
:
null
;
$bulk_track_update
[
$key_update
][
'id_zing'
]
=
isset
(
$track
->
id
)
?
$track
->
id
:
null
;
$bulk_track_update
[
$key_update
][
'singer_list'
]
=
$singer_list
;
$bulk_track_update
[
$key_update
][
'track_duration'
]
=
isset
(
$track
->
duration
)
?
$track
->
duration
:
0
;
$bulk_track_update
[
$key_update
][
'src_thumbnail'
]
=
isset
(
$track
->
thumbnail
)
?
$track
->
thumbnail
:
null
;
$bulk_track_update
[
$key_update
][
'src_thumbnail_medium'
]
=
isset
(
$track
->
thumbnail_medium
)
?
$track
->
thumbnail_medium
:
null
;
$bulk_track_update
[
$key_update
][
'link_mv'
]
=
isset
(
$track
->
mv_link
)
?
$domain
.
$track
->
mv_link
:
null
;
$key_update
++
;
}
else
{
$bulk_track_insert
[
$key_insert
][
'title'
]
=
isset
(
$track
->
title
)
?
$track
->
title
:
'unknown-title'
;
$bulk_track_insert
[
$key_insert
][
'slug'
]
=
isset
(
$track
->
alias
)
?
$track
->
alias
:
null
;
$bulk_track_insert
[
$key_insert
][
'userid'
]
=
0
;
$bulk_track_insert
[
$key_insert
][
'tag'
]
=
'vmusic'
;
$bulk_track_insert
[
$key_insert
][
'genre'
]
=
1
;
$bulk_track_insert
[
$key_insert
][
'download_hash'
]
=
md5
(
$track
->
alias
);
$bulk_track_insert
[
$key_insert
][
'time'
]
=
time
();
$bulk_track_insert
[
$key_insert
][
'link'
]
=
isset
(
$track
->
link
)
?
$domain
.
$track
->
link
:
null
;
$bulk_track_insert
[
$key_insert
][
'id_zing'
]
=
isset
(
$track
->
id
)
?
$track
->
id
:
null
;
$bulk_track_insert
[
$key_insert
][
'singer_list'
]
=
$singer_list
;
$bulk_track_insert
[
$key_insert
][
'track_duration'
]
=
isset
(
$track
->
duration
)
?
$track
->
duration
:
0
;
$bulk_track_insert
[
$key_insert
][
'src_thumbnail'
]
=
isset
(
$track
->
thumbnail
)
?
$track
->
thumbnail
:
null
;
$bulk_track_insert
[
$key_insert
][
'src_thumbnail_medium'
]
=
isset
(
$track
->
thumbnail_medium
)
?
$track
->
thumbnail_medium
:
null
;
$bulk_track_insert
[
$key_insert
][
'link_mv'
]
=
isset
(
$track
->
mv_link
)
?
$domain
.
$track
->
mv_link
:
null
;
$bulk_track_insert
[
$key_insert
][
'crawler_at'
]
=
Carbon
::
now
();
$key_insert
++
;
}
}
}
echo
"
\n
Số bài hát insert: "
.
count
(
$bulk_track_insert
);
echo
"
\n
Số bài hát update: "
.
count
(
$bulk_track_update
);
if
(
count
(
$bulk_track_insert
)
>
0
)
{
DB
::
table
(
Constants
::
TABLE_TRACKS
)
->
insert
(
$bulk_track_insert
);
echo
"
\n
Insert thành công."
;
}
else
{
echo
"
\n
Không lấy được bài hát nào."
;
}
// Ghi log
Crontjob
::
create
([
'message'
=>
'ZingCrawlerNewRealeaseCommand is called at '
.
Carbon
::
now
()]);
}
}
app/Console/Kernel.php
View file @
7caf7995
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
App\Console
;
namespace
App\Console
;
use
App\Console\Commands\CrontjobCommand
;
use
App\Console\Commands\CrontjobCommand
;
use
App\Console\Commands\Zing\ZingCrawlerNewRealeaseCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackImageCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackImageCommand
;
use
Illuminate\Console\Scheduling\Schedule
;
use
Illuminate\Console\Scheduling\Schedule
;
...
@@ -18,6 +19,7 @@ class Kernel extends ConsoleKernel
...
@@ -18,6 +19,7 @@ class Kernel extends ConsoleKernel
protected
$commands
=
[
protected
$commands
=
[
CrontjobCommand
::
class
,
CrontjobCommand
::
class
,
ZingCrawlerTrackCommand
::
class
,
ZingCrawlerTrackCommand
::
class
,
ZingCrawlerNewRealeaseCommand
::
class
,
ZingCrawlerTrackImageCommand
::
class
,
ZingCrawlerTrackImageCommand
::
class
,
];
];
...
@@ -36,7 +38,8 @@ class Kernel extends ConsoleKernel
...
@@ -36,7 +38,8 @@ class Kernel extends ConsoleKernel
$schedule
->
command
(
'crontjob:test'
)
->
hourly
();
$schedule
->
command
(
'crontjob:test'
)
->
hourly
();
$schedule
->
command
(
'zing:get-track'
)
->
everyThirtyMinutes
();
$schedule
->
command
(
'zing:get-track'
)
->
everyThirtyMinutes
();
$schedule
->
command
(
'zing:get-track-image'
)
->
hourly
();
$schedule
->
command
(
'zing:get-new-release-track'
)
->
hourlyAt
(
10
);
$schedule
->
command
(
'zing:get-track-image'
)
->
hourlyAt
(
15
);
$schedule
->
command
(
'queue:work --once --timeout=120'
)
->
everyMinute
()
->
withoutOverlapping
();
$schedule
->
command
(
'queue:work --once --timeout=120'
)
->
everyMinute
()
->
withoutOverlapping
();
}
}
...
...
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