Skip to content

Instantly share code, notes, and snippets.

@doulmi
Created June 21, 2017 07:49
Show Gist options
  • Save doulmi/0713d6a8d38bc43679fe1f4b4321ea26 to your computer and use it in GitHub Desktop.
Save doulmi/0713d6a8d38bc43679fe1f4b4321ea26 to your computer and use it in GitHub Desktop.
RFI Downloader.php
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Exception;
use Illuminate\Console\Command;
require_once app_path('simple_html_dom.php');
class rfi extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'download:rfi {date}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'format [2017-02-04]';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$start = $this->argument('date');
if($start) {
$carbon = new Carbon($start);
} else {
$carbon = Carbon::now();
}
for ($i = 0; $i < 365; $i++) {
$carbon->subDay(1);
$url = 'https://savoirs.rfi.fr/fr/apprendre-enseigner/langue-francaise/journal-en-francais-facile-' . $carbon->format('dm') . '-20h00-gmt';
$date = $carbon->toDateString();
try {
$nodes = file_get_html($url);
} catch(Exception $e) {
var_dump($date . ' failed');
continue;
}
if ($nodes) {
$content = strip_tags(str_replace("<br />", "<br />\n", html_entity_decode(trim($nodes->find('div[class=field field-name-field-descriptif-trad field-type-text-long field-label-hidden]', 0)->innertext))));
$mp3 = file_get_contents("http://telechargement.rfi.fr/rfi/francais/audio/jff/201702/journal_francais_facile_20h00_-_20h10_tu_20170206.mp3");
file_put_contents(public_path('rfi/audios/' . $date . '.mp3'), $mp3);
file_put_contents(public_path('rfi/texts/' . $date . '.lrc'), '[00:00:00]' . $content);
var_dump($date);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment