Video Uploading To Vimeo

Hello Alex, you upload your videos to vimeo and cannot access these videos from the browser directly. For example we cannot access https://player.vimeo.com/video/1010746273?title=0&byline=0&autoplay=1&dnt=1&app_id=122963 directly. But when we are a member of your system, we can view the videos. Can you tell me how you did that? Thank you in advance.

nagikho Member
nagikho
0
3
244
alex Member
alex
Moderator
Solution

Sure thing! Here's a rough idea of how it works:

  1. Videos are uploaded through Vimeo API with their visibility set to private embeddable, so they can be embedded but not accessed directly.

  2. Videos are also set to only be allowed to play on the codecourse.com domain

  3. I store the vimeo_id and vimeo_hash in the episodes table of the database (obtained from the API when a new video is pushed through admin)

  4. Each episode has an API resource that looks like this:

class EpisodeResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            // Other things up here
            'vimeo_id' => ($this->free || $this->course->free || auth()->user()?->hasSubscription()) ? $this->vimeo_id : null,
            'vimeo_hash' => $this->vimeo_hash,
        ];
    }
}

This hides the vimeo_id in the response so unless you have a membership or the episode is free, you can't see it.

  1. It's then rendered on the page using Vimeo's JavaScript SDK, passing in the vimeo_id and vimeo_hash. I won't post the code for this, but any way you now embed — you've protected against the vimeo_id being visible and it'll only play on the codecourse.com domain.

Hope this helps, and let me know if you have any questions!

nagikho Member
nagikho

Thank you for the answer, now I have something in my head.

alex Member
alex
Moderator

Awesome, glad it helped!