PHP code example of ianfortier / loom-downloader

1. Go to this page and download the library: Download ianfortier/loom-downloader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ianfortier / loom-downloader example snippets


use LoomDownloader\LoomDownloader;

$downloader = new LoomDownloader();
$videoContent = $downloader->downloadVideo('https://www.loom.com/share/your-video-id');

// $videoContent now contains the binary data of the video
// Be cautious with this method for large videos as it loads the entire video into memory

use LoomDownloader\LoomDownloader;

$downloader = new LoomDownloader();
$filePath = $downloader->saveVideo('https://www.loom.com/share/your-video-id', '/path/to/save/video.mp4');

echo "Video saved to: " . $filePath;

$filePath = $downloader->saveVideo('https://www.loom.com/share/your-video-id');
echo "Video saved to: " . $filePath;

use LoomDownloader\LoomDownloader;

class LoomController extends Controller
{
    public function download(Request $request)
    {
        $downloader = new LoomDownloader();
        $filePath = $downloader->saveVideo($request->loom_url, storage_path('app/videos/loom_video.mp4'));
        
        return response()->download($filePath);
    }

    public function stream(Request $request)
    {
        $downloader = new LoomDownloader();
        $videoContent = $downloader->downloadVideo($request->loom_url);
        
        return response($videoContent)
            ->header('Content-Type', 'video/mp4')
            ->header('Content-Disposition', 'inline; filename="loom_video.mp4"');
    }
}

use Illuminate\Support\Facades\Log;
use LoomDownloader\LoomDownloader;

class LoomController extends Controller
{
    public function download(Request $request)
    {
        try {
            $downloader = new LoomDownloader();
            $filePath = $downloader->saveVideo($request->loom_url, storage_path('app/videos/loom_video.mp4'));
            return response()->download($filePath);
        } catch (\Exception $e) {
            Log::error('Failed to download Loom video: ' . $e->getMessage());
            return response()->json(['error' => 'Failed to download video'], 500);
        }
    }
}