r/programmingrequests • • Jun 17 '18

Making this API code bring through more relevant data?

I have this code I have written here:

https://jsfiddle.net/dfwq57pz/

However the code does not bring up relevant/modern movies, it brings up random movies that I have never heard of, also I can't get it to skip the movies it does not find.

I wanted to do something like on this website:

https://www.randomlists.com/random-movies?qty=1&dup=false

But it is impossible to contact the owner, view the sites source code etc... I presume they have done it on the backend.

I am thinking I would need to do something as per:

https://developers.themoviedb.org/3/discover/movie-discover

However, when I try to amend my code in the above JSFiddle it does not work. An attempt as such can viewed here:

https://pastebin.com/RkrZ2WKz

Overall to reiterate I want to:

1 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jun 17 '18

UPDATE: So I tried to work this out myself, ideally it would be something like page=all pages, but you can't do this on the API, so I am stumped, I then tried page=1&2 and page=1&page=2 etc... for the rest of the pages, then to select a random film and only show one film on the DOM / HTML at random, just completely stumped how to achieve this, am I right in thinking that the API will not let me retrieve that many results? Perhaps Discover is not the best method, where: https://jsfiddle.net/dfwq57pz/ using this method but greatly improved to show more accurate results somehow is the way forward?

1

u/[deleted] Jun 17 '18

UPDATE 2: I just noticed in your code you took the genre part out, I tried to get this working according to the docs but I failed:

https://jsfiddle.net/rgqtbLnu/

1

u/tresteo Jun 17 '18

The problem with the genres is, that you only get the ids of the genres.

You will probably need to get the list of genres before loading the movies. The list is available from this endpoint: https://developers.themoviedb.org/3/genres/get-movie-list

You can then lookup the correct name for each genre_id per result.

1

u/tresteo Jun 17 '18

To retrieve results from all pages you would need to loop over the page variable in separate queries.

So first request with page=1, then another request with page=2 and so on. You can find the total number of pages in the total_pages field of the response. If you request page x, you can decide if you need to request another page by checking if x < total_pages.