Downloading video to correct directory and displaying it on a chapter page.
This commit is contained in:
@@ -11,8 +11,6 @@ class ChapterController extends Controller
|
||||
{
|
||||
$symfonyCastDlService->videoSize($chapter);
|
||||
$symfonyCastDlService->downloadFile($chapter);
|
||||
// $symfonyCastDlService->videoSize($chapter);
|
||||
// file_put_contents('movie.avi', file_get_contents($chapter->video_link));
|
||||
dd($chapter->toArray());
|
||||
return view('chapter.index', compact('chapter'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\Chapter;
|
||||
use App\Models\Course;
|
||||
use GuzzleHttp\TransferStats;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SymfonyCastDlService
|
||||
{
|
||||
@@ -54,7 +55,6 @@ 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];
|
||||
@@ -66,16 +66,17 @@ class SymfonyCastDlService
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
public function downloadFile(Chapter $chapter): bool
|
||||
public function downloadFile(Chapter $chapter): void
|
||||
{
|
||||
if (!is_dir($chapter->course_id . '/')) {
|
||||
mkdir($chapter->course_id);
|
||||
if (!is_dir($chapter->directory_path)) {
|
||||
mkdir($chapter->directory_path);
|
||||
}
|
||||
if (!is_file($chapter->video_path)) {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
$chapter->video_link,
|
||||
['sink' => $chapter->video_path],
|
||||
);
|
||||
}
|
||||
$this->client->request(
|
||||
'GET',
|
||||
$chapter->video_link,
|
||||
['sink' => $chapter->course_id . '/' . $chapter->id . '.mp4']
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -15,6 +16,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
* @property string $duration
|
||||
* @property integer $course_id
|
||||
* @property bool $sync_offline
|
||||
* @property string $video_path
|
||||
* @property string $directory_path
|
||||
*/
|
||||
class Chapter extends Model
|
||||
{
|
||||
@@ -35,4 +38,18 @@ class Chapter extends Model
|
||||
{
|
||||
return $this->belongsTo(Course::class);
|
||||
}
|
||||
|
||||
protected function videoPath(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->directory_path . '/' . $this->id . '.' . $this->link . '.mp4'
|
||||
);
|
||||
}
|
||||
|
||||
protected function directoryPath(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->course_id . '.' . $this->course->link
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user