Added total time of a course, marking chapters and courses to sync offline.
This commit is contained in:
@@ -22,4 +22,11 @@ class CourseController extends Controller
|
||||
|
||||
dd($chapter->toArray());
|
||||
}
|
||||
|
||||
public function sync(Course $course)
|
||||
{
|
||||
$course->chapters->each->update(['sync_offline' => 1]);
|
||||
return redirect(route('course.index', ['course' => $course]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ class HtmlParser
|
||||
$course->course_id = $courseItem->attr('data-id');
|
||||
$course->numberofchapters = $courseItem->attr('data-chapter-count');
|
||||
$course->timeswatched = $courseItem->attr('data-times-watched');
|
||||
$course->course_duration = $courseItem->first('.font-blue.fal.fa-clock.pr-1')?->parent()?->text();
|
||||
$course->published_at = $courseItem->attr('data-date') > 0 ? Carbon::createFromTimestamp(
|
||||
$courseItem->attr('data-date')
|
||||
) : null;
|
||||
@@ -55,10 +56,10 @@ class HtmlParser
|
||||
$chapter->duration = $chapterItem->first('.length-styling')?->text();
|
||||
$chapter->order = $chapterId;
|
||||
$chapter->course_id = $courseId;
|
||||
$chapter->link = config('symfonycast.base_url') . $chapterItem->first('a')->attr('href');
|
||||
$chapter->video_link = config('symfonycast.base_url') . $chapterItem->first('a')->attr(
|
||||
'href'
|
||||
) . '/download/video';
|
||||
if ($link = trim($chapterItem->first('a')->attr('href'), '#')) {
|
||||
$chapter->link = config('symfonycast.base_url') . $link;
|
||||
$chapter->video_link = config('symfonycast.base_url') . $link . '/download/video';
|
||||
}
|
||||
$chapter->title = preg_replace('/\v(?:[\v\h]+)/', '', $chapterItem->first('.col')->text());
|
||||
$chapter->video_size = 0;
|
||||
$chapters->add($chapter);
|
||||
|
||||
@@ -41,24 +41,27 @@ class SymfonyCastDlService
|
||||
|
||||
$courses = $this->htmlParser->getCourses($coursePage);
|
||||
$courses->each(fn($course) => $course->save());
|
||||
$singleCoursePage = $this->client->get($courses[3]->link);
|
||||
// $singleCoursePage = $this->client->get($courses[3]->link);
|
||||
/** @var Course $course */
|
||||
foreach ($courses as $course) {
|
||||
$singleCoursePage = $this->client->get($course->link);
|
||||
$chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id);
|
||||
$chapters->each(fn($chapter) => $this->videoSize($chapter)->save());
|
||||
// $chapters->each(fn($chapter) => $this->videoSize($chapter)->save());
|
||||
$chapters->each(fn($chapter) => $chapter->save());
|
||||
}
|
||||
}
|
||||
|
||||
public function videoSize(Chapter $chapter): Chapter
|
||||
{
|
||||
try {
|
||||
$response = $this->client->head($chapter->video_link);
|
||||
if ($response->hasHeader('Content-Length')) {
|
||||
$chapter->video_size = $response->getHeader('Content-Length')[0];
|
||||
if (!$chapter->video_size) {
|
||||
$response = $this->client->head($chapter->video_link);
|
||||
if ($response->hasHeader('Content-Length')) {
|
||||
$chapter->video_size = $response->getHeader('Content-Length')[0];
|
||||
}
|
||||
$chapter->save();
|
||||
}
|
||||
} catch (\GuzzleHttp\Exception\ClientException $exception) {
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
* @property string $title
|
||||
* @property string $duration
|
||||
* @property integer $course_id
|
||||
* @property bool $sync_offline
|
||||
*/
|
||||
class Chapter extends Model
|
||||
{
|
||||
@@ -27,6 +28,7 @@ class Chapter extends Model
|
||||
'title',
|
||||
'duration',
|
||||
'course_id',
|
||||
'sync_offline',
|
||||
];
|
||||
|
||||
public function course(): BelongsTo
|
||||
|
||||
Reference in New Issue
Block a user