maintanance and downloading files.
This commit is contained in:
@@ -26,7 +26,7 @@ class HtmlParser
|
||||
$course = Course::firstOrNew(['course_id' => $courseId]);
|
||||
$course->name = $courseItem->first('h3')->text();
|
||||
$course->thumbnail = $courseItem->first('img.course-list-item-img')->attr('src');
|
||||
$course->link = $courseItem->first('a')->attr('href');
|
||||
$course->link = last(explode('/', $courseItem->first('a')->attr('href')));
|
||||
$course->status = $courseItem->attr('data-status');
|
||||
$course->course_id = $courseItem->attr('data-id');
|
||||
$course->numberofchapters = $courseItem->attr('data-chapter-count');
|
||||
@@ -49,15 +49,12 @@ class HtmlParser
|
||||
if ($chapterItem->first('.col')) {
|
||||
$chapterId++;
|
||||
|
||||
// if(!$chapterItem->first('.length-styling')){
|
||||
// dd($chapterItem->html());
|
||||
// }
|
||||
$chapter = Chapter::firstOrNew(['course_id' => $courseId, 'order' => $chapterId]);
|
||||
$chapter->duration = $chapterItem->first('.length-styling')?->text();
|
||||
$chapter->order = $chapterId;
|
||||
$chapter->course_id = $courseId;
|
||||
if ($link = trim($chapterItem->first('a')->attr('href'), '#')) {
|
||||
$chapter->link = config('symfonycast.base_url') . $link;
|
||||
$chapter->link = last(explode('/', $link));;
|
||||
$chapter->video_link = config('symfonycast.base_url') . $link . '/download/video';
|
||||
}
|
||||
$chapter->title = preg_replace('/\v(?:[\v\h]+)/', '', $chapterItem->first('.col')->text());
|
||||
|
||||
@@ -21,10 +21,9 @@ class SymfonyCastDlService
|
||||
|
||||
$response = $this->client->get('login');
|
||||
|
||||
|
||||
$token = $htmlParser->getCsrfToken($response);
|
||||
|
||||
$response = $this->client->post('login', [
|
||||
$this->client->post('login', [
|
||||
'form_params' => [
|
||||
'email' => config('symfonycast.login'),
|
||||
'password' => config('symfonycast.password'),
|
||||
@@ -44,7 +43,7 @@ class SymfonyCastDlService
|
||||
$courses->each->save();
|
||||
/** @var Course $course */
|
||||
foreach ($courses as $course) {
|
||||
$singleCoursePage = $this->client->get($course->link);
|
||||
$singleCoursePage = $this->client->get('/screencast/' . $course->link);
|
||||
$chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id);
|
||||
$chapters->each->save();
|
||||
$chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id));
|
||||
@@ -55,6 +54,7 @@ class SymfonyCastDlService
|
||||
{
|
||||
try {
|
||||
if (!$chapter->video_size) {
|
||||
echo 1;
|
||||
$response = $this->client->head($chapter->video_link);
|
||||
if ($response->hasHeader('Content-Length')) {
|
||||
$chapter->video_size = $response->getHeader('Content-Length')[0];
|
||||
@@ -65,4 +65,17 @@ class SymfonyCastDlService
|
||||
}
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
public function downloadFile(Chapter $chapter): bool
|
||||
{
|
||||
if (!is_dir($chapter->course_id . '/')) {
|
||||
mkdir($chapter->course_id);
|
||||
}
|
||||
$this->client->request(
|
||||
'GET',
|
||||
$chapter->video_link,
|
||||
['sink' => $chapter->course_id . '/' . $chapter->id . '.mp4']
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user