The Movie Database Support

Hi,

I'm working on an app that generates Radom movies. I know that it's not possible with your API; to bypass that the app generates random numbers, then cross references that with the id's from movies. Via this methode it works, I don't know how to filter it with popular movies yet, but it works.

The issue is: I can't get the movie posters, genre and other stuff with it. Only the titels appear. Any idea what I'm doing wrong?

I'm using swiftUI btw:

ScrollView(.horizontal, showsIndicators: false) {
                    HStack {
                        ForEach(movieTitles.indices, id: \.self) { index in
                            Text(movieTitles[index])
                                .font(.headline)
                                .padding()
                        }
                    }
                }

                Button(action: {
                    var randomIds = [Int]()
                    while randomIds.count < 3 {
                        let randomId = Int.random(in: 1...803322)
                        if !randomIds.contains(randomId) {
                            randomIds.append(randomId)
                        }
                    }

                    MovieStore.shared.fetchMovies(from: .popular) { result in
                        switch result {
                        case .success(let response):
                            var movies = response.results
                            var titles = [String]()
                            for id in randomIds {
                                if let movie = movies.first(where: { $0.id == id }) {
                                    titles.append(movie.title)
                                    movies.removeAll(where: { $0.id == movie.id })
                                }
                            }
                            self.movieTitles = titles
                            self.movies = movies
                        case .failure(let error):
                            print(error.localizedDescription)
                        }
                    }
                }) {
                    Text("Get 3 Random Movies")
                        .font(.headline)
                        .foregroundColor(.white)
                        .padding()
                        .background(Color.blue)
                        .cornerRadius(10)
                }

                Spacer()

                ForEach(movieTitles.indices, id: \.self) { index in
                    HStack {
                        MoviePosterCard(movie: movies[index], imageLoader: ImageLoader())
                            .frame(width: 100, height: 60)
                            .onAppear {
                                self.imageLoader.loadImage(with: self.movies[index].posterURL)
                            }
                        Text(movieTitles[index])
                    }
                }

1 reply (on page 1 of 1)

Jump to last post

@Majinnn said:
Random movie generator
Hi,
I'm working on an app that generates Radom movies.
I know that it's not possible with your API;
to bypass that the app generates random numbers, then cross references that with the id's from movies.
Via this methode it works,
I don't know how to filter it with popular movies yet, but it works.
The issue is: I can't get the movie posters, genre and other stuff with it. Only the titels appear.
Any idea what I'm doing wrong?

What I do know is that when I make an API Request for Popular movies,
https://developers.themoviedb.org/3/movies/get-popular-movies
I get the following information on each of the movies:

page    1
results 
0   
adult   false
backdrop_path   "/hiHGRbyTcbZoLsYYkO4QiCLYe34.jpg"
genre_ids   
0   27
1   9648
2   53
id  758323
original_language   "en"
original_title  "The Pope's Exorcist"
overview    "Father Gabriele Amorth, …y tried to keep hidden."
popularity  6523.322
poster_path "/9JBEPLTPSm0d1mbEcLxULjJq9Eh.jpg"
release_date    "2023-04-05"
title   "The Pope's Exorcist"
video   false
vote_average    7.4
vote_count  554
1   
adult   false
backdrop_path   "/3CxUndGhUcZdt1Zggjdb2HkLLQX.jpg"
...

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login