WEBVTT

00:01.870 --> 00:02.680
All right.

00:02.680 --> 00:09.430
So now we are actually able to get the image URLs for all these beautiful posters for the different

00:09.430 --> 00:10.300
movies.

00:10.450 --> 00:16.360
And so now we just need to be able to save the file or save the image to our disk.

00:17.260 --> 00:24.940
And I made a folder in here that is called Posters where we will be saving the images to.

00:25.240 --> 00:27.760
So let's make another function.

00:27.760 --> 00:32.710
We call it save poster image to disk.

00:33.160 --> 00:43.390
We pass in a movie object in here and in here we are going to use the old type of request that is not

00:43.390 --> 00:45.910
using the regular promises.

00:46.030 --> 00:50.140
So I'm going to call this regular request.

00:50.260 --> 00:52.630
That's just my fancy name for it.

00:52.630 --> 00:54.430
You can call it whatever you want.

00:54.880 --> 00:58.120
And we require the request here.

00:58.450 --> 01:01.040
So regular request, I call it.

01:01.040 --> 01:04.220
And let me show you what we do.

01:05.720 --> 01:07.880
We say regular request.

01:08.800 --> 01:09.580
Get.

01:10.540 --> 01:23.290
Movie and we say poster image URL, and then we use pipe and we also need to import FS for file stream

01:23.290 --> 01:24.550
to save the file.

01:25.660 --> 01:31.270
So const FS require fs.

01:33.410 --> 01:38.900
And say FS create write stream.

01:39.200 --> 01:47.150
And in here we put the path or the URL, the file name to the file we are going to save.

01:47.150 --> 01:58.520
So I think we will save it as in posters and we are going to use the rank of the movie as the file name

01:58.520 --> 02:00.440
and end it with PNG.

02:01.370 --> 02:09.350
So I'm using the rank now because some of the titles have characters that's not so suitable for file

02:09.350 --> 02:09.710
names.

02:09.710 --> 02:16.160
So for simplicity's sake, for simplicity's sake, I'm using rank instead.

02:17.250 --> 02:18.150
Okay.

02:18.150 --> 02:21.510
And that should be it.

02:21.540 --> 02:28.500
Now, instead of going through all of the movies to get their poster image URL, you could do that.

02:28.500 --> 02:36.030
But just so we can see the results as early as possible, I'm going to call the function inside the

02:36.030 --> 02:39.180
script poster image URL function instead.

02:39.270 --> 02:47.730
So scrape, poster image or say poster image to disk and we pass in the movie object in here.

02:49.880 --> 02:54.080
Okay, So let's see if it runs.

02:54.110 --> 02:56.840
If it saves the images to the disk.

02:58.770 --> 03:06.930
So it's starting up the nightmare browser here and it's saying no such file or directory.

03:07.410 --> 03:11.370
It's because I called it poster instead of posters.

03:11.580 --> 03:16.050
So let's just correct that to posters and we try and run it again.

03:17.430 --> 03:22.290
And now, since it can find the directory, it should be able to save the file.

03:25.610 --> 03:28.730
Okay, so there we go.

03:29.660 --> 03:32.990
And we see the files is being saved here.

03:35.630 --> 03:42.020
Okay, So number one, we have Bohemian Rhapsody over here and so on and so on.

03:42.970 --> 03:46.060
So everything is working just fine now.
