diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 077bda7..c3914ef 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -580,7 +580,7 @@ struct MediaInfoView: View { let seasons = groupedEpisodes() if seasons.count > 1 { Menu { - ForEach(0.. Void) { - let query = """ - query { - Media(id: \(anilistID)) { - idMal - } - } - """ - guard let url = URL(string: "https://graphql.anilist.co") else { - completion(nil) - return - } - - var request = URLRequest(url: url) - request.httpMethod = "POST" - request.setValue("application/json", forHTTPHeaderField: "Content-Type") - request.httpBody = try? JSONSerialization.data(withJSONObject: ["query": query]) - - URLSession.shared.dataTask(with: request) { data, _, _ in - var malID: Int? = nil - if let data = data, - let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any], - let dataDict = json["data"] as? [String: Any], - let media = dataDict["Media"] as? [String: Any], - let idMal = media["idMal"] as? Int { - malID = idMal + let query = """ + query { + Media(id: \(anilistID)) { + idMal } - DispatchQueue.main.async { - completion(malID) } - }.resume() -} + """ + guard let url = URL(string: "https://graphql.anilist.co") else { + completion(nil) + return + } + + var request = URLRequest(url: url) + request.httpMethod = "POST" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + request.httpBody = try? JSONSerialization.data(withJSONObject: ["query": query]) + + URLSession.custom.dataTask(with: request) { data, _, _ in + var malID: Int? = nil + if let data = data, + let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any], + let dataDict = json["data"] as? [String: Any], + let media = dataDict["Media"] as? [String: Any], + let idMal = media["idMal"] as? Int { + malID = idMal + } + DispatchQueue.main.async { + completion(malID) + } + }.resume() + } + private func fetchTMDBPosterImageAndSet() { guard let tmdbID = tmdbID, let tmdbType = tmdbType else { return } let apiType = tmdbType.rawValue @@ -2305,14 +2301,8 @@ struct MediaInfoView: View { completion(nil as EpisodeMetadataInfo?) return } - fetchEpisodeMetadataFromNetwork(anilistId: anilistId, episodeNumber: episode.number) { info in - if let info = info, let enTitle = info.title["en"] { - DispatchQueue.main.async { - episodeTitleCache[episode.number] = enTitle - } - } - completion(info) - } + + fetchEpisodeMetadataFromNetwork(anilistId: anilistId, episodeNumber: episode.number, completion: completion) } private func fetchEpisodeMetadataFromNetwork(anilistId: Int, episodeNumber: Int, completion: @escaping (EpisodeMetadataInfo?) -> Void) {