Commit ed4c258c by Phạm Văn Đoan

Code thêm đoạn lấy ds bài hát ở yeunhacvang.com

parent 18f26e6c
<?php
namespace App\Console\Commands\Ynv;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class YnvCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ynv:get-track {page_index?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$page_index = $this->argument('page_index');
$page_index = intval($page_index);
echo "\n Starting...";
$results = [];
$domain = 'http://www.yeunhacvang.com/';
//$page_index = 34;
//for ($page = 1; $page <= 140; $page++) {
for ($page = $page_index; $page <= $page_index; $page++) {
echo "\n - Processing page " . $page;
$title = [];
$link = [];
$singer = [];
$url = $domain . '?pg=list&page='.$page;
$dom = getDom($url);
/* Lấy tên bài hát */
$element_track_title = 'div.main table#table1 tr td a';
foreach ($dom->find($element_track_title) as $data) {
$title[] = str_replace([], [], $data->innertext);
}
/* Lấy link bài hát */
$element_track_title = 'div.main table#table1 tr td a';
foreach ($dom->find($element_track_title) as $data) {
$link[] = $domain . str_replace([], [], $data->href);
}
/* Lấy tên ca sĩ */
$element_track_title = 'div.main table#table1 tr td';
foreach ($dom->find($element_track_title) as $data) {
if ($data->width == "40%") {
$singer[] = str_replace([], [], $data->innertext);
}
}
echo "\n -> Số bài " . count($title);
for ($i=0; $i < count($title); $i++) {
preg_match("/-([0-9]+)$/", $link[$i], $ids);
$results[] = [
'page_index' => $page_index,
'track_id' => (is_array($ids) && count($ids) == 2) ? $ids[1] : null,
'title' => $title[$i],
'singer' => $singer[$i+1],
'detail_link' => $link[$i],
'is_checking' => 0,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
];
}
}
//print_r($results);
if (count($results) > 0) {
DB::table('ynvs')->insert($results);
}
echo "\n Done.";
}
}
...@@ -14,6 +14,7 @@ use App\Console\Commands\Nct\NctCrawlerTrackCommand; ...@@ -14,6 +14,7 @@ use App\Console\Commands\Nct\NctCrawlerTrackCommand;
use App\Console\Commands\NhacVn\NhacVnCrawlerTrackCommand; use App\Console\Commands\NhacVn\NhacVnCrawlerTrackCommand;
use App\Console\Commands\SendWarningCommand; use App\Console\Commands\SendWarningCommand;
use App\Console\Commands\Update\UpdateTrackArtistCommand; use App\Console\Commands\Update\UpdateTrackArtistCommand;
use App\Console\Commands\Ynv\YnvCommand;
use App\Console\Commands\Zing\ZingCrawlerNewRealeaseCommand; use App\Console\Commands\Zing\ZingCrawlerNewRealeaseCommand;
use App\Console\Commands\Zing\ZingCrawlerTrackCommand; use App\Console\Commands\Zing\ZingCrawlerTrackCommand;
use App\Console\Commands\CrawlerTrackImageCommand; use App\Console\Commands\CrawlerTrackImageCommand;
...@@ -29,6 +30,7 @@ class Kernel extends ConsoleKernel ...@@ -29,6 +30,7 @@ class Kernel extends ConsoleKernel
*/ */
protected $commands = [ protected $commands = [
CrontjobCommand::class, CrontjobCommand::class,
YnvCommand::class,
ZingCrawlerTrackCommand::class, ZingCrawlerTrackCommand::class,
ZingCrawlerNewRealeaseCommand::class, ZingCrawlerNewRealeaseCommand::class,
......
<?php
namespace App\Models\Ynv;
use Illuminate\Database\Eloquent\Model;
class Ynv extends Model
{
protected $table = 'ynvs';
public $timestamps = true;
protected $fillable = [
'page_index',
'track_id',
'title',
'singer',
'detail_link',
'mp3_link',
'lyric',
'is_checking'
];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment