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
bb3d023e
Commit
bb3d023e
authored
Mar 25, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test tải ảnh bài hát
parent
1860cae1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
1 deletion
+108
-1
ZingCrawlerTrackImageCommand.php
app/Console/Commands/Zing/ZingCrawlerTrackImageCommand.php
+76
-0
Kernel.php
app/Console/Kernel.php
+2
-0
Constants.php
app/Helpers/Constants.php
+8
-0
TrackRepository.php
app/Repositories/TrackRepository.php
+22
-1
No files found.
app/Console/Commands/Zing/ZingCrawlerTrackImageCommand.php
0 → 100644
View file @
bb3d023e
<?php
namespace
App\Console\Commands\Zing
;
use
App\Helpers\Constants
;
use
App\Models\Crontjob
;
use
App\Models\Track
;
use
App\Repositories\TrackRepository
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
class
ZingCrawlerTrackImageCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'zing:get-track-image'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Lấy ảnh đại diện của bài hát từ nguồn zing'
;
protected
$trackRepository
;
/**
* Create a new command instance.
*
* ZingCrawlerTrackImageCommand constructor.
* @param TrackRepository $trackRepository
*/
public
function
__construct
(
TrackRepository
$trackRepository
)
{
parent
::
__construct
();
$this
->
trackRepository
=
$trackRepository
;
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$tracks
=
$this
->
trackRepository
->
getTrackImageEmpty
();
echo
"
\n
Tổng số bài hát cần lấy ảnh về: "
.
count
(
$tracks
);
if
(
is_array
(
$tracks
)
&&
count
(
$tracks
)
>
0
)
{
foreach
(
$tracks
as
$key
=>
$track
)
{
if
(
$track
[
'src_thumbnail_medium'
])
{
$file_name
=
md5
(
$track
[
'id'
])
.
'.png'
;
$file_path
=
Constants
::
VMUSICCHART_IMG_TRACKS
.
$file_name
;
@
copy
(
Constants
::
VMUSICCHART_IMG_EMPTY_PNG
,
$file_path
);
@
file_put_contents
(
$file_path
,
@
file_get_contents
(
$track
[
'src_thumbnail_medium'
]));
$track
=
Track
::
find
(
$track
[
'id'
]);
if
(
$track
)
{
$track
->
art
=
Constants
::
VMUSICCHART_IMG_TRACKS_DB
.
$file_name
;
$track
->
save
();
}
}
}
}
echo
"
\n
Tải ảnh kết thúc."
;
// Ghi log
Crontjob
::
create
([
'message'
=>
'ZingCrawlerTrackImageCommand is called at '
.
Carbon
::
now
()]);
}
}
app/Console/Kernel.php
View file @
bb3d023e
...
...
@@ -4,6 +4,7 @@ namespace App\Console;
use
App\Console\Commands\CrontjobCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackCommand
;
use
App\Console\Commands\Zing\ZingCrawlerTrackImageCommand
;
use
Illuminate\Console\Scheduling\Schedule
;
use
Illuminate\Foundation\Console\Kernel
as
ConsoleKernel
;
...
...
@@ -17,6 +18,7 @@ class Kernel extends ConsoleKernel
protected
$commands
=
[
CrontjobCommand
::
class
,
ZingCrawlerTrackCommand
::
class
,
ZingCrawlerTrackImageCommand
::
class
,
];
...
...
app/Helpers/Constants.php
View file @
bb3d023e
...
...
@@ -110,4 +110,11 @@ class Constants
const
STORAGE_THUMBNAIL_ARTISTS_DB
=
'storage/artists/thumbnails/'
;
const
STORAGE_THUMBNAIL_ARTISTS
=
'storage/app/public/artists/thumbnails/'
;
const
VMUSICCHART_IMG_TRACKS_DB
=
'uploads/tracks/arts/'
;
const
VMUSICCHART_IMG_TRACKS
=
'/home/aseanvn/public_html/vmusicchart.dcv.vn/uploads/tracks/arts/'
;
const
VMUSICCHART_IMG_EMPTY_PNG
=
'/home/aseanvn/public_html/vmusicchart.dcv.vn/uploads/empty-1x1-png.png'
;
const
VMUSICCHART_IMG_EMPTY_JPG
=
'/home/aseanvn/public_html/vmusicchart.dcv.vn/uploads/empty-1x1-jpg.jpg'
;
const
VMUSICCHART_IMG_EMPTY_GIF
=
'/home/aseanvn/public_html/vmusicchart.dcv.vn/uploads/empty-1x1-gif.gif'
;
}
\ No newline at end of file
app/Repositories/TrackRepository.php
View file @
bb3d023e
...
...
@@ -11,6 +11,17 @@ class TrackRepository extends BaseRepository
}
/**
* Lấy ds bài hát đã insert
*
* doanpv - 24/03/2020
*
* @param string $pluck_by_field
* @param string $type
* @param array $select_fields
*
* @return array
*/
public
function
getTrackInserted
(
$pluck_by_field
=
'all'
,
$type
=
'original'
,
array
$select_fields
)
{
if
(
count
(
$select_fields
)
==
0
)
$select_fields
=
[
'id'
,
'title'
,
'slug'
];
...
...
@@ -37,9 +48,19 @@ class TrackRepository extends BaseRepository
}
}
/**
* Lấy ds bài hát chưa có ảnh đại diện (trường art: null)
*
* doanpv - 24/03/2020
*
* @return array
*/
public
function
getTrackImageEmpty
()
{
$query
=
Track
::
select
([
'id'
,
'art'
,
'id_zing'
,
'id_nct'
,
'id_keeng'
,
'src_thumbnail_medium'
])
->
whereNull
(
'art'
);
$query
=
Track
::
select
([
'id'
,
'art'
,
'id_zing'
,
'id_nct'
,
'id_keeng'
,
'src_thumbnail_medium'
])
->
whereNull
(
'art'
)
->
whereNotNull
(
'src_thumbnail_medium'
);
return
$query
->
get
()
->
toArray
();
}
...
...
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