Skip to content

Instantly share code, notes, and snippets.

@jasonmccreary
Created October 4, 2021 12:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonmccreary/b2a04f7cfad2bdb323f9264fb1daf109 to your computer and use it in GitHub Desktop.
Save jasonmccreary/b2a04f7cfad2bdb323f9264fb1daf109 to your computer and use it in GitHub Desktop.
Command to update your Vimeo thumbnail links

This artisan command will update your Vimeo video thumbnails for their recent link change (September 2021).

To run:

  1. Add the command to your Laravel project.
  2. Update any references for your application (model name, column names, thumbnail size, thumnail type)
  3. Install vimeo/laravel
  4. Configure your environment with you Vimeo app credentials
<?php
namespace App\Console\Commands;
use App\Models\Video;
use Illuminate\Console\Command;
use Vimeo\Laravel\Facades\Vimeo;
class UpdateVimeoThumbnails extends Command
{
protected $signature = 'videos:thumbnails';
protected $description = 'Update video thumbnail links';
public function handle()
{
$videos = Video::whereNotNull('vimeo_id')->get();
foreach ($videos as $video) {
$data = Vimeo::request('/videos/' . $video->vimeo_id);
if (!isset($data['body']['pictures']['sizes'])) {
$this->warn('Failed to retrieve data for video: ' . $video->vimeo_id);
continue;
}
$download_links = collect($data['body']['pictures']['sizes'])->mapWithKeys(function ($size) {
return [$size['width'] . 'x' . $size['height'] => $size];
});
$video->thumbnail = $download_links['295x166']['link_with_play_button'];
$video->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment