Welcome back, guys.
In today's lecture, we're going to work on the model for the movies, so that will be the movie that
we're going to select here.
So this is the final version.
So I open up this one in Firefox in the version that we are working.
I've opened up here in Google.
Right.
So that's how I would know which one is which.
So we've got to work on this one.
But this is a complete version using E, including the views and controller.
So are we going to work on the model here?
So the model will be here and actually create this class movie that gets to please create this class
new file movie that so here it should have its capital movie.
Right.
Stick to that convention here.
Are we going to export
before class called movie.
Right.
And actually in the index, in the controller, I'm going to report it right away, because I'm going
to forget after that here is going to I'm going to look bad if I do this now.
It's the same folder, right?
Just import it nice.
Here in this class, we're going to have a constructor.
We need the IMDB ID here.
Here.
I'm going to set the constructor.
I'm going to set that.
I'm PBI equal to the I am PBI to the one that we are passing here, WKU.
So every time we create an object for this guy, this will be first things called no, let's create
async function here that will get the movies actually get movie, not movies.
And this will be async function any side we need const key.
And actually the actual key is in our search here is this one.
So I'm going to copy and paste it here.
But look what's happening.
I have this one in probably I need to copy this as well because we need to try and catch block here
as well in here.
Instead of alerting the error here, I'm going to say allured.
Something went wrong loading the movie.
Right.
OK, now the result and this and this part here is pretty much seen.
So we are just making things not good.
That is called go dry.
We are repeating the code too much.
So this constant key and actually this you are out here, we can just store it somewhere else so we
can create a file folder here first in the Geass.
So make sure that you can just create a folder called Config and inside we can create a file called
Copy.
But Dodgiest.
But this file I don't recommend because it's in the source folder and this is a client site, everyone
will have access.
So that's not good.
But for this project, because it's small, you're not going to do any major things here, it's completely
fine.
But maybe the API, if it's coming from your servers, it will be more secure and you don't need to
store all the details like this.
Now, here I'm talking too much, but I need to explain you.
I'm just going to put this one const key here and what else I have here.
I do have these.
And I'm going to put it as a const API and I'm going to put it like this, so until the question mark,
because the searching with search query and by the idea, it's a little bit different.
We need the key for both.
But this part is different, right?
Nice.
So that is from the documentation.
You can go back and read it here and we need to do something like this.
So I'm on I'm Dibia API, so we need something like this question mark equal the idea of the movie.
OK, I think we are clear now.
I'm just going to close this search and don't forget here to do the export so we need to export this
one.
Nice.
Now in the movie we actually we need to import it so import it here in the curly brackets.
I'm going to say key is API in that will be from now.
We need to get out from this folder here, models and we need to go into the config folder.
Right.
So double dots, forward slash config and config.
We don't need to pass the just the extension.
OK, now I don't really need this one and I can't cut this one until here.
Dollar sign an API then.
I don't need the API key here.
Actually I need the API here but I don't need this one.
So it was I equal to what the I equal to the movie ID and we already have this movie so I'm going to
copy this one here based it.
Oops.
Without that too much space and we are done now the data will be there and actually I don't need this
part, I need just control of the data back.
Yep, nice.
So how are we going to test this, because we already have included I'm going to copy this search controller,
so I'm going to put it here and I'm going to say movie controller and I'm going to create an instance
here, const movie, equal new movie.
But here I need to pass that IMDB idea.
Right, because the constructor requires that.
So how I'm going to get it.
So search for oblivion or whatever movie you want, click it here and on top without the hash you don't
need the hash with on the top.
We do have videos, right.
Copy that one and put it here.
Nice.
Now the movie does get movie, it should bring out some results.
Go inspect.
It comes a lot.
Then let's see what's happening here.
It is so I do have the object with actors, Tom Cruise, Morgan words, and we have a bunch of information
now.
I'm going to do a couple of things here.
We need to grab all of this and save it in our get movie method here.
And I'm just going to do it like this.
So actually, we need that one to see what we are going to save.
So I have the title Oblivion Here.
Now I just want to grab the title.
Most of the things we're going to grab, we're going to use it here in the description.
That's why I'm just casting crew media reviews overview.
Right.
That's going to be the movie Main Actors, stuff like that.
Now I know how to get this thing, so you need to just follow me and everything will be pretty much
OK, since I don't wanna waste your time here.
Now these that title equal data, that title right to DataDot Capital T and why what's happening this.
Because the title is Save It Like The Capital Works, here it is Capital T. Everything is pretty much
capital here, right?
So make sure that you don't make a mistake here.
The title with this because.
Yeah, it's not going to work.
Now read it equal.
DataDot read it.
The stock.
I am dbe reading.
We need that rating.
So DataDot I am DeeVee rating.
Cool.
Now these these that runtime equals data that runtime nice.
These actors.
Now we're going to change this one and you will see what we are going to do in just shortly.
But because the actors we don't have we don't have who is the main actor and the main actor is always
first.
We do have these actors.
So I am going to redo this board and I'm going to save it in an area and I'm going to expect the first
element of that area.
You will see how I'm going to do it with a method here outside.
Now, these are production,
so we're not going to use this, but it's good to have it right.
So these that poster, we need this one.
So you can call it IMG if you want, but I'm going to stick with the they are named that poster.
This I need to plot these dot plot, equal data dot plot.
You know, we pretty much we're almost there these that box office box office equal data, that box.
Office, these that were a lot of things we are saving here, ladies and gentlemen, are words and make
sure this has asked as well this that you are out.
OK, we're going to we're going to fix this one leader now.
How are we going to get the money?
So that director one more.
We're going to so everything we're going to miss now, we're going to just add it later on
the director.
Good.
So how are we going to get the you are out like the movie you, Earl?
It's obviously on MTV, so I'm going to show you something.
So I'm going to copy.
I'm just going to go, I don't know, Tarzan.
I really don't know.
I have watched a lot of movies, but for this reason, I really don't know which movies that.
So when I click here on watch the trailer actually going to go to the IMDB.
So look what's happening on MTV.
I am Disney dot com slash title slash video so I can create knowing this, I can create any URL I want
because I do have the idea and every time his goal slash title slash that idiot.
So what are we going to go here?
I'm going to say export.
Export const.
I'm Debbie, I'm going to see a movie you out here, I'm going to say it like this until the title,
right?
That's pretty much it.
So I do have the new movie, You, Earl, so I can add it here.
Nice.
So what I can do here, I can say this.
You órale and I will say movie you, Earl, because I already have that one.
Right.
And I can grab it like this movie you are actually I don't need it, I just need it like that.
All right.
Actually, we need to use that back to over their template literals and we can grab the movie URL and
after that what we need is finishing with that forward slash.
So what we need is actually the IMDB here, these IMDB.
That's pretty much it.
We need that one as well.
And four, which is pretty much it.
I think he's going to work now.
So movie you Eurail this time DVD movie Earl is coming from the conflict file and this that I'm coming
for from the constructor.
Nice here.
What else we need here.
So we need a couple of more things.
The first thing is to get the main actor.
So I'm going to say these that get me an actor and this will be a function here.
So this function will go outside here.
And I say, get me actor.
And what we will do in this function is I'm going to create a constant called new actor and that will
be these actors.
So I'm going to get all of the actors.
I'm going to use the split method here, and that will give me and I'm going to see is going to split
me with the comma here, right.
Because I have just I'm going to save this one way and save this one.
And I need to go here.
OK, recompiling movie, movie field lawsuit against Refresh.
And we do have some error in this happening because we have unexpected tokin expected semicolon on that
line.
So what I suggest here is just to grab it here and we need to pass below here below where these get
movie function is ending.
Now, I think it is now, I think that will be done.
So here all of these actors are separated by a comma.
So I'm going to use this method on them like that.
So that will create an area.
And what I need now is to save these actors.
These are not actors to the new actor, that area.
So these here later on when we have our object, these actors get off passing for the first time here.
Actually, they are going to be replaced by this night.
So we are overwriting that one.
And how I'm going to get the main actor, I'm going to set these that mean actor from here.
And that will be the new actor.
And it's starting from the position zero because this is an area.
Right.
Cool.
So actually, this will have this kind of very Tom Cruise and the second here will go.
And I'm basically getting this point here right from the very nice.
So we have said the main actors are what we need to do is actually yet create another error here.
They start a movie crew.
We're going to use this movie crew.
But here I'm going to use something else.
Now, here, I already said the these actors.
Right.
But here I don't have the movie crew.
So what I'm going to pass in here is I'm going to say data the writer, I'm going to pass that data
in now here.
I can easily do that same thing with here in this part, because now I'm showing you how you can override
what you said before with the function.
And I'm going to set this one again to the new area here.
Right.
Movie crew in here, I'm going to say right around me.
And this not right there.
It will be right there.
That split again.
I'm going to use the split method here and with the comma, because we have the writers you will see
here we have the writers again separated with comma and this will create additional error here.
Now, that is pretty much it for this lecture and for from the next lecture, we're going to continue
working.
I hope you enjoyed this one.
So now you know how to grab all of the data from the movie.
We've created two separate functions.
And if we have some error here, for example, let's API has we will have something wrong with the loading
the movie.
Right.
Good.
So this is coming from the conflict in the config.
We put this one now.
You can also change where it is.
You can also change the search.
OK, let's do it both together.
Now, I'm going to go in the movie.
I'm just going to get this one else and I'm going to paste it here.
But we don't need that movie.
You are.
All right.
So I don't need actually this key here and I'm going to actually use that one in the API.
Actually, we need to replace that one.
API, but before we need a dollar sign.
So if I save it now, everything should work the same if I search for a movie slice.
OK, where is that one search movie view?
Twenty seven.
OK, let's load another one.
OK, I paused the video in a pond error, so it saying we kind of do a slice of undefined search movie
view.
So that is where we display the results.
Right.
And the reason why it's happening this is because in our county, we did include that part, the question
mark and sorry.
And here we did include again, that's why I can't find the movie.
And that's why when we do search movie, you slice method.
We just getting that result.
And we don't have nothing to slice.
We don't have the disarrayed.
Now, let's search for movie again.
Here is it's working.
Oh, good.
Now, ladies and gentlemen, we know how to do this.
We've created we imported this one and that's pretty much it.
Yeah.
I will see you in the next one.
I hope you enjoy this.
And that was pretty much and you can add more things here that you want to use them, but make sure
that you follow and also just include this part.
Right.
Thank you very much.
And I'll see you next one.