Created
May 24, 2019 22:31
-
-
Save WyattCast44/2f4742574fcd852deb3a24147f3eb143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Jobs; | |
use Vimeo; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Foundation\Bus\Dispatchable; | |
use App\Video; | |
class UploadVideoToVimeo implements ShouldQueue | |
{ | |
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | |
protected $video; | |
/** | |
* Create a new job instance. | |
* | |
* @return void | |
*/ | |
public function __construct(Video $video) | |
{ | |
$this->video = $video; | |
} | |
/** | |
* Execute the job. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
$path = storage_path('app/' . $this->video->source_path); | |
if (!file_exists($path)) { | |
return; | |
} | |
$vimeo_uri = Vimeo::upload($path, [ | |
'name' => $this->video->title, | |
'description' => $this->video->description | |
]); | |
$vimeo_video = Vimeo::request($vimeo_uri); | |
$this->video->vimeo_uri = $vimeo_uri; | |
$this->video->embed_code = $vimeo_video['body']['embed']['html']; | |
$this->video->duration = $vimeo_video['body']['duration']; | |
$this->video->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment