Transcript
Hello friends. So as you know, I've got the YouTube channel where you can view my videos, and I also have my own video platform, supers.com. Now this video is actually an embedded YouTube video within Supers, and you see it has a lot of YouTube brand, 1, 2, 3, 4. And if I start playing a video, hello and pause. I also have this ribbon that has recommendations not only for my content, but for other creators content. So you embed the player, but you don't really own the player, and that is the price of the free GI hosting. Now if you look at another video that I have here, you see it doesn't have any YouTube brand. What is, and uh, it looks quite, uh, good. Now, it isn't an HTML five player. It isn't, uh, wrapped in JavaScript and I don't use active storage in this application at all. Actually, I'm using Vimeo and uh, I'm embedded the video via Vimeo. Why did I choose Vimeo? Uh, first of all, it is, uh, quite, uh, cheap. So I'm paying around $60 per year for hosting all my videos, and it is a fixed cost. So no matter how many videos I have and how much they have been watched, it is a fixed cost. So I got all my videos here. Other cool things are that, um, I get to customize my play without writing any additional code, and it's quite a nice thing to outsource. And there is some basic, uh, uh, security here. So, for example, I go to the embed settings of my videos and you see, I allow embedded in the videos on, on specific, uh, domains and, uh, it makes them a bit more secure from, uh, virus, I guess. And, uh, I've got like the video, I've got thumbnails, title, description, uh, I can add tags and I can import all this information from Vimeo into my client application. Now, there are also other tools, uh, for premium video hosting, unlike Vimeo, for example. I think these guys, uh, are using, uh, MUX. And if you go to the pricing of MUX, you say there is a fixed cost that can be like seven, 3000 per month. And uh, yeah, that's like smaller plan, but uh, bigger plans for them, for example, I think would be at least 3000 per month. And uh, you see, you pay for the storage. So the more videos you have, the more you have to pay and the more viewers you have, the more you have to pay. So it is a very variable cost. And uh, again, the cool thing here, I don't even have to have active storage or an uh, Amazon S3 account. I'm just storing everything, uh, on uh, Vimeo. Now another thing that Vimeo is quite good at is the API. So let's try using the Mu API to get my videos and uh, uh, get the general feeling how you can use it. So first of all, I'm gonna create an API application. Let's create one. Let's give it a timestamped name, 1858. Now, it's not going to be an or out application, it's just going to be me accessing my content. So I'm answering no here create application. And now I can create an access token, send an unauthenticated access token Will have access only to public videos. But I want to get my private videos. So I'm going to say authenticated. Basically I'm going to get with authenticated, I'm going to get my private information and I'm going to say that I want to access private videos, uh, generate the token here, have the token, and let's use it with the API. So here's the API reference and the basic API calls. So then this is the root of the API. We can get something about a user, we can get the metadata of a specific video, or we can get all the videos of a user, for example, let's try using it. So here have, I have a new rails application. I'm going to create a job, let's say rails generate job vmo and let's open VMO job. I will say access token equals the one that they have just created. The URL of the API is, uh, uh, this one. So URL equals a pcon. And uh, I'm going to use third day GEM to make a P request. So I will install the gem third day bundle. At third day, it'll add the gem third day to my gem file and run bundle to add the gem. And now I'm going to use fairday. So I will say connection equals fairday. UURL equals this URL uh, do fairday. And now I'm going to add the authentication. So I will say Faraday dofest authorization, it'll be with bearer and it'll be with this access, uh, token. And now let's try making an API call. So the most simple API call that they can make as an authenticated user is get slash me. Uh, let's say, uh, response equals connection Do get slash me and let's run this job. Let's, uh, open the rails console and let's say result equals uh, vijo dot perform. Now we have the result. Uh, let's get result body. Let's pass the result body. Let's actually do it here. Let's say if response success, let's say return, unless response success, we are going to continue only if it was a successful response. If we'll say, uh, body equals J pass response body. Let's, uh, reload because we've done some changes in files and, uh, run the job again, result, you see we have the information about this user. Let's get result, uh, URI and we have this, uh, endpoint slash users and our own user id. Let's try make a request to our own user id. I suppose it would give more or less the same. Let's say, uh, user ID equals body, uh, URI. And we're going to make a request to this endpoint. Let's again copy all of this. Reload. Now we are making a request not to uh, just myself, but to a user by id. And we get the kind of the same information because we made the request about the same user. And now let's try getting all the videos of a specific user. Now, one way we could do it would be well for ourselves, we can just get slash me slash videos or we could get the it with a slash I think, uh, uh, users, uh, slash the idea of the user slash videos. Let's get just our videos. So again, I will, um, make the request. I will, uh, pass the results and display them. We don't need the this. So reload. And let's get all our videos result. You see in total we have 520 videos uploaded. We have 25, uh, per page with this API endpoint. And the in data we have the videos themselves. Let's see results data, uh, dot count first. So we have the name of the video, the description, we have the layer embedded URL that I'm actually using. And you see the ID of the video, uh, here it is, is not the same as the ID of the embed URL. You see there is some additional character that we need to add that is quite unique for each of the Vimeo videos. And if it'll go further, we can also see the URLs of, uh, Vimeo images. So, uh, we have some different variant of Vimeo images that we can also import into our application. So I can kind of host both the videos and the thumbnails and descriptions and tags on Vimeo and input them all into my application. Okay? So, uh, have, have, uh, a list of videos and we get the first video. Let's just try to find one video by id. Let's have a look at, uh, this first video and let's get its URI. Okay, let's try making a request to get just this video by id. I will, uh, say, uh, response, uh, equals connection, get uh, slash videos and the id and let's get the video body. I will again reload 'cause I've done some changes in the file. I will run the job. And in the result we have just, uh, this video. So we managed to get this fun video by Id. Looks, uh, quite good. So yeah, this is the basics of how you can use the Vimeo API. Now let's try storing this information in our application. Now, uh, we could store the name, the description, and so on as separate attributes on a video or on a post model. But we can also store them all in, uh, Jason for example. So let's create a video model that will not have a separate attribute for everything. It'll just have, uh, uh, it'll just adjacent with this payload. So I will say re generate modal, uh, video. And the video will have a Vimeo payload. JSON B. Now JBI think exists only in, uh, PostGresQ. It doesn't exist on escalate, I think, but it is a like more performant, uh, way to pass. Uh, Jason, I think. So let's go to our migration, create videos and we'll just have, uh, female payload. Let's make it JS B. Oh, actually here I have escalate. So it's gonna to be js o relatively migrate. And uh, let's try storing, uh, let's try creating a video in our application and storing this, uh, uh, payload. So I will say, um, video equals video dot great. And Vimeo payload will be body two hash. Now it is important to make it to hash, otherwise it'll not be stored properly. So, uh, this would create a Vimeo, uh, object in our application. That's first Try Rails console video. Do count none. Now I will run the job, um, Vimeo job perform now, and let's say video first. And you see we have, uh, this v Vimeo payload. We have stored all the information and we can pause it. Let's, uh, uh, get the URI, uh, yeah, we need to get within the payload, so video first dot v, payload, and inside we can get the, uh, name or your I and So on. So I think it is a good, uh, um, idea not to store like just 10 attributes that you might need, but store the whole payload of, uh, the object that you, that you got from the API and be able to do anything with it that you want. Okay? That's about it. So we manage to play with the vm, OAPI. We got the information about our user. We got all the videos of a user, we got, uh, information of one specific video and created a video object in our database. Thanks for watching and see you in the next one.
1