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
d1a50548
Commit
d1a50548
authored
Jun 15, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lấy lịch sử lượt nghe từ NCT
parent
6ad20bc1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
4 deletions
+90
-4
CrawlerNctTrackListenCommand.php
app/Console/Commands/CrawlerNctTrackListenCommand.php
+52
-3
Constants.php
app/Helpers/Constants.php
+1
-0
Functions.php
app/Helpers/Functions.php
+16
-0
CrawlerListenNct.php
app/Models/CrawlerListenNct.php
+21
-0
TrackRepository.php
app/Repositories/TrackRepository.php
+0
-1
No files found.
app/Console/Commands/CrawlerNctTrackListenCommand.php
View file @
d1a50548
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
namespace
App\Console\Commands
;
namespace
App\Console\Commands
;
use
App\Models\CrawlerListenNct
;
use
App\Repositories\TrackRepository
;
use
App\Repositories\TrackRepository
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\Command
;
class
CrawlerNctTrackListenCommand
extends
Command
class
CrawlerNctTrackListenCommand
extends
Command
...
@@ -46,7 +48,8 @@ class CrawlerNctTrackListenCommand extends Command
...
@@ -46,7 +48,8 @@ class CrawlerNctTrackListenCommand extends Command
$from_page
=
'nct'
;
$from_page
=
'nct'
;
$limit
=
10
;
$limit
=
10
;
$crawlered
=
$this
->
trackRepository
->
getCrawlerListenInserted
(
$from_page
,
false
);
//$crawlered = $this->trackRepository->getCrawlerListenInserted($from_page, false);
$crawlered
=
CrawlerListenNct
::
groupBy
(
'track_id'
)
->
pluck
(
'track_id'
)
->
all
();
echo
"
\n
Tổng số bài hát đã lấy lượt nghe hôm nay: "
.
count
(
$crawlered
);
echo
"
\n
Tổng số bài hát đã lấy lượt nghe hôm nay: "
.
count
(
$crawlered
);
...
@@ -56,11 +59,57 @@ class CrawlerNctTrackListenCommand extends Command
...
@@ -56,11 +59,57 @@ class CrawlerNctTrackListenCommand extends Command
echo
"
\n
Tổng số bài hát cần lấy lượt nghe: "
.
$total
;
echo
"
\n
Tổng số bài hát cần lấy lượt nghe: "
.
$total
;
foreach
(
$inserted
as
$key
=>
$track
)
{
$listen
[]
=
$this
->
privateGetListen
(
$from_page
,
$track
);
echo
"
\n
"
.
(
$key
+
1
)
.
"/"
.
$total
.
": Đã lấy lịch sử lượt nghe bài hát có ID= "
.
$track
[
'id'
];
}
$data
=
$this
->
trackRepository
->
getNctTrackListen
(
$inserted
);
if
(
count
(
$listen
)
>
0
)
{
foreach
(
$listen
as
$key
=>
$array_listen
)
{
if
(
count
(
$array_listen
)
>
0
)
{
foreach
(
$array_listen
as
$val
)
{
CrawlerListenNct
::
updateOrCreate
(
[
'track_id'
=>
$val
[
'track_id'
],
'date_chart'
=>
$val
[
'date_chart'
]
],
[
'cumu_chart'
=>
$val
[
'cumu_chart'
],
'daily_chart'
=>
$val
[
'daily_chart'
],
'created_at'
=>
Carbon
::
now
(),
'updated_at'
=>
Carbon
::
now
()
]
);
}
}
}
}
print_r
(
$data
);
die
();
echo
"
\n
Kết thúc.
\n
"
;
}
private
function
privateGetListen
(
$src
,
$track
)
{
$listen
=
[];
/* Xử lý mới sau khi bị chặn */
$url
=
getNctUrlGetCounterForChart
(
$track
[
'id_nct'
]);
$curl
=
cURL
(
$url
);
$response
=
json_decode
(
$curl
);
if
(
isset
(
$response
->
status
)
&&
$response
->
status
==
'Success'
)
{
if
(
isset
(
$response
->
dailyChart
)
&&
isset
(
$response
->
dateChart
)
&&
isset
(
$response
->
cumuChart
)
&&
is_array
(
$response
->
dailyChart
)
&&
is_array
(
$response
->
dateChart
)
&&
is_array
(
$response
->
cumuChart
))
{
foreach
(
$response
->
dailyChart
as
$key
=>
$val
)
{
$listen
[
$key
][
'track_id'
]
=
$track
[
'id'
];
$listen
[
$key
][
'daily_chart'
]
=
$val
;
$listen
[
$key
][
'date_chart'
]
=
date
(
'Y-m-d'
,
strtotime
(
str_replace
(
'/'
,
'-'
,
$response
->
dateChart
[
$key
])));
$listen
[
$key
][
'cumu_chart'
]
=
$response
->
cumuChart
[
$key
];
}
}
}
return
$listen
;
}
}
}
}
app/Helpers/Constants.php
View file @
d1a50548
...
@@ -7,6 +7,7 @@ class Constants
...
@@ -7,6 +7,7 @@ class Constants
const
TABLE_ARTISTS
=
'artists'
;
const
TABLE_ARTISTS
=
'artists'
;
const
TABLE_COUNT_VIEWS
=
'count_views'
;
const
TABLE_COUNT_VIEWS
=
'count_views'
;
const
TABLE_CRAWLER_LISTEN_HISTORIES
=
'crawler_listen_histories'
;
const
TABLE_CRAWLER_LISTEN_HISTORIES
=
'crawler_listen_histories'
;
const
TABLE_CRAWLER_LISTEN_NCTS
=
'crawler_listen_ncts'
;
const
TABLE_CRAWLER_LISTENS
=
'crawler_listens'
;
const
TABLE_CRAWLER_LISTENS
=
'crawler_listens'
;
const
TABLE_CRONTJOBS
=
'crontjobs'
;
const
TABLE_CRONTJOBS
=
'crontjobs'
;
...
...
app/Helpers/Functions.php
View file @
d1a50548
...
@@ -245,6 +245,22 @@ if (!function_exists('getNctUrlGetCounter')) {
...
@@ -245,6 +245,22 @@ if (!function_exists('getNctUrlGetCounter')) {
}
}
}
}
if
(
!
function_exists
(
'getNctUrlGetCounterForChart'
))
{
/**
* Hàm tạo URL cho từng bài hát dựa vào ID của nó để lấy lượt nghe
* https://www.nhaccuatui.com/ajax/chart?songId=6290700
*
* @param $id
* @return string
*/
function
getNctUrlGetCounterForChart
(
$id
)
{
$url
=
'https://www.nhaccuatui.com/ajax/chart?'
;
$url
.=
'songId='
.
$id
;
return
$url
;
}
}
if
(
!
function_exists
(
'getKeengUrlGetCounter'
))
{
if
(
!
function_exists
(
'getKeengUrlGetCounter'
))
{
/**
/**
* Hàm tạo URL cho từng bài hát dựa vào ID của nó để lấy lượt nghe
* Hàm tạo URL cho từng bài hát dựa vào ID của nó để lấy lượt nghe
...
...
app/Models/CrawlerListenNct.php
0 → 100644
View file @
d1a50548
<?php
namespace
App\Models
;
use
App\Helpers\Constants
;
use
Illuminate\Database\Eloquent\Model
;
class
CrawlerListenNct
extends
Model
{
protected
$table
=
Constants
::
TABLE_CRAWLER_LISTEN_NCTS
;
public
$timestamps
=
true
;
protected
$fillable
=
[
'track_id'
,
'date_chart'
,
'cumu_chart'
,
'daily_chart'
,
'is_get_reporting'
];
}
app/Repositories/TrackRepository.php
View file @
d1a50548
...
@@ -437,7 +437,6 @@ class TrackRepository extends BaseRepository
...
@@ -437,7 +437,6 @@ class TrackRepository extends BaseRepository
public
function
getNctTrackListen
(
$inserted
)
public
function
getNctTrackListen
(
$inserted
)
{
{
return
file_get_contents
(
'https://www.nhaccuatui.com/interaction/api/counter?listSongIds=6217224'
);
$tracks
=
[];
$tracks
=
[];
//
//
...
...
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