Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfortier authored Oct 12, 2024
1 parent 2da1841 commit f1a0167
Showing 1 changed file with 21 additions and 101 deletions.
122 changes: 21 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,47 @@ Loom doesn't provide an official API for video downloads. This package fills tha

Use responsibly and only for videos you have the right to download and store.

## 🎬 Quick Start
## 🔧 Usage Examples

The `LoomDownloader` class provides two main methods for working with Loom videos: `downloadVideo` and `saveVideo`.

Here's a quick example to get you started:
### Download Video Content

To download the video content and get it as a binary:

```php
use LoomDownloader\LoomDownloader;

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

echo "Video saved to: " . $filePath;
// $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
```

## 🔧 Usage Examples

### Download Video Content
### Save Video to File

To get the video content as a string:
To download the video and save it directly to a file:

```php
use LoomDownloader\LoomDownloader;

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

### Save Video to File
echo "Video saved to: " . $filePath;
```

To save the video directly to a file:
If you don't specify a destination, the video will be saved to a temporary directory:

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

## 🛠 Laravel Integration

While this package can be used in any PHP project, it integrates smoothly with Laravel. Here are some examples of how you can use the Loom Video Downloader in your Laravel application:
While this package can be used in any PHP project, here are some examples of how you can integrate it with Laravel:

### Basic Usage in a Controller

Expand Down Expand Up @@ -83,68 +88,8 @@ class LoomController extends Controller
}
```

### Integration with Laravel's File Storage

Use Laravel's `Storage` facade to save the downloaded video:

```php
use Illuminate\Support\Facades\Storage;
use LoomDownloader\LoomDownloader;

class LoomController extends Controller
{
public function store(Request $request)
{
$downloader = new LoomDownloader();
$videoContent = $downloader->downloadVideo($request->loom_url);

$path = Storage::put('videos/loom-video.mp4', $videoContent);

return response()->json(['message' => 'Video stored successfully', 'path' => $path]);
}
}
```

### Background Processing with Laravel Queues

Create a job to download videos in the background:

```php
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use LoomDownloader\LoomDownloader;

class DownloadLoomVideo implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $loomUrl;
protected $savePath;

public function __construct($loomUrl, $savePath)
{
$this->loomUrl = $loomUrl;
$this->savePath = $savePath;
}

public function handle()
{
$downloader = new LoomDownloader();
$downloader->saveVideo($this->loomUrl, $this->savePath);
}
}

// In your controller:
DownloadLoomVideo::dispatch($loomUrl, storage_path('app/videos/loom_video.mp4'));
```

### Error Handling with Laravel Logging

Wrap the download process in a try-catch block and use Laravel's logging:

```php
use Illuminate\Support\Facades\Log;
use LoomDownloader\LoomDownloader;
Expand All @@ -165,31 +110,6 @@ class LoomController extends Controller
}
```

### Caching Downloaded Videos

Use Laravel's Cache facade to store downloaded videos:

```php
use Illuminate\Support\Facades\Cache;
use LoomDownloader\LoomDownloader;

class LoomController extends Controller
{
public function getCachedVideo(Request $request)
{
$videoId = $request->video_id;
$videoContent = Cache::remember('loom_video_' . $videoId, 3600, function () use ($request) {
$downloader = new LoomDownloader();
return $downloader->downloadVideo($request->loom_url);
});

return response($videoContent)
->header('Content-Type', 'video/mp4')
->header('Content-Disposition', 'inline; filename="loom_video.mp4"');
}
}
```

## ℹ️ Important Information

Before using this package, please be aware of the following:
Expand All @@ -200,7 +120,7 @@ Before using this package, please be aware of the following:

3. **Video Quality**: Videos are downloaded in the format provided by Loom's API. There are no options to select different qualities or formats.

4. **Large Videos**: While the package can handle large files, there are no specific optimizations or progress indicators for lengthy downloads.
4. **Large Videos**: While the package can handle large files, be cautious when using the `downloadVideo` method as it loads the entire video into memory. For large videos, prefer the `saveVideo` method which streams the video directly to a file.

5. **Legal and Ethical Considerations**: Ensure you have the right to download and use the Loom videos. This package does not enforce access controls or address legal concerns related to video downloading. Always respect copyright and privacy rights.

Expand Down

0 comments on commit f1a0167

Please sign in to comment.