mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-17 23:01:38 +00:00
remove TMDB that somewhy doesnt work
This commit is contained in:
parent
427102ecd8
commit
9d45c12a6e
3 changed files with 10 additions and 135 deletions
|
|
@ -20,8 +20,6 @@ struct EpisodeCell: View {
|
|||
let episodeID: Int
|
||||
let progress: Double
|
||||
let itemID: Int
|
||||
let useAnilist: Bool
|
||||
let tmdbID: Int?
|
||||
|
||||
let onTap: (String) -> Void
|
||||
let onMarkAllPrevious: () -> Void
|
||||
|
|
@ -32,15 +30,12 @@ struct EpisodeCell: View {
|
|||
@State private var currentProgress: Double = 0.0
|
||||
|
||||
init(episodeIndex: Int, episode: String, episodeID: Int, progress: Double,
|
||||
itemID: Int, useAnilist: Bool = true, tmdbID: Int? = nil,
|
||||
onTap: @escaping (String) -> Void, onMarkAllPrevious: @escaping () -> Void) {
|
||||
itemID: Int, onTap: @escaping (String) -> Void, onMarkAllPrevious: @escaping () -> Void) {
|
||||
self.episodeIndex = episodeIndex
|
||||
self.episode = episode
|
||||
self.episodeID = episodeID
|
||||
self.progress = progress
|
||||
self.itemID = itemID
|
||||
self.useAnilist = useAnilist
|
||||
self.tmdbID = tmdbID
|
||||
self.onTap = onTap
|
||||
self.onMarkAllPrevious = onMarkAllPrevious
|
||||
}
|
||||
|
|
@ -140,11 +135,7 @@ struct EpisodeCell: View {
|
|||
}
|
||||
|
||||
private func fetchEpisodeDetails() {
|
||||
if useAnilist {
|
||||
fetchAnimeEpisodeDetails()
|
||||
} else {
|
||||
fetchTMDBEpisodeDetails()
|
||||
}
|
||||
fetchAnimeEpisodeDetails()
|
||||
}
|
||||
|
||||
private func fetchAnimeEpisodeDetails() {
|
||||
|
|
@ -195,66 +186,4 @@ struct EpisodeCell: View {
|
|||
}
|
||||
}.resume()
|
||||
}
|
||||
|
||||
private func fetchTMDBEpisodeDetails() {
|
||||
guard let tmdbID = tmdbID else {
|
||||
isLoading = false
|
||||
return
|
||||
}
|
||||
|
||||
let seasonNumber = 1
|
||||
let apiKey = "738b4edd0a156cc126dc4a4b8aea4aca"
|
||||
let urlString = "https://api.themoviedb.org/3/tv/\(tmdbID)/season/\(seasonNumber)/episode/\(episodeID + 1)?api_key=\(apiKey)"
|
||||
|
||||
guard let url = URL(string: urlString) else {
|
||||
isLoading = false
|
||||
return
|
||||
}
|
||||
|
||||
URLSession.custom.dataTask(with: url) { data, response, error in
|
||||
if let error = error {
|
||||
Logger.shared.log("Failed to fetch TMDB episode details: \(error)", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
self.isLoading = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
guard let data = data else {
|
||||
DispatchQueue.main.async {
|
||||
self.isLoading = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
|
||||
guard let episodeDetails = jsonObject as? [String: Any],
|
||||
let name = episodeDetails["name"] as? String else {
|
||||
Logger.shared.log("Invalid TMDB response format", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
self.isLoading = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let imageBasePath = "https://image.tmdb.org/t/p/w300"
|
||||
var imageUrl = ""
|
||||
if let stillPath = episodeDetails["still_path"] as? String {
|
||||
imageUrl = imageBasePath + stillPath
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.episodeTitle = name
|
||||
self.episodeImageUrl = imageUrl
|
||||
self.isLoading = false
|
||||
}
|
||||
} catch {
|
||||
Logger.shared.log("Error parsing TMDB data: \(error)", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
self.isLoading = false
|
||||
}
|
||||
}
|
||||
}.resume()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,8 +241,6 @@ struct MediaInfoView: View {
|
|||
episodeID: ep.number - 1,
|
||||
progress: progress,
|
||||
itemID: itemID ?? 0,
|
||||
useAnilist: UserDefaults.standard.string(forKey: "metadataProviders") == "AniList",
|
||||
tmdbID: tmdbID,
|
||||
onTap: { imageUrl in
|
||||
if !isFetchingEpisode {
|
||||
selectedEpisodeNumber = ep.number
|
||||
|
|
@ -293,8 +291,6 @@ struct MediaInfoView: View {
|
|||
episodeID: ep.number - 1,
|
||||
progress: progress,
|
||||
itemID: itemID ?? 0,
|
||||
useAnilist: UserDefaults.standard.string(forKey: "metadataProviders") == "AniList",
|
||||
tmdbID: tmdbID,
|
||||
onTap: { imageUrl in
|
||||
if !isFetchingEpisode {
|
||||
selectedEpisodeNumber = ep.number
|
||||
|
|
@ -376,25 +372,13 @@ struct MediaInfoView: View {
|
|||
DropManager.shared.showDrop(title: "Fetching Data", subtitle: "Please wait while fetching.", duration: 0.5, icon: UIImage(systemName: "arrow.triangle.2.circlepath"))
|
||||
fetchDetails()
|
||||
|
||||
if UserDefaults.standard.string(forKey: "metadataProviders") == "AniList" {
|
||||
fetchItemID(byTitle: cleanTitle(title)) { result in
|
||||
switch result {
|
||||
case .success(let id):
|
||||
itemID = id
|
||||
case .failure(let error):
|
||||
Logger.shared.log("Failed to fetch AniList ID: \(error)")
|
||||
AnalyticsManager.shared.sendEvent(event: "error", additionalData: ["error": error, "message": "Failed to fetch AniList ID"])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fetchTMDBID(byTitle: cleanTitle(title)) { result in
|
||||
switch result {
|
||||
case .success(let id):
|
||||
tmdbID = id
|
||||
case .failure(let error):
|
||||
Logger.shared.log("Failed to fetch TMDB ID: \(error)")
|
||||
AnalyticsManager.shared.sendEvent(event: "error", additionalData: ["error": error, "message": "Failed to fetch TMDB ID"])
|
||||
}
|
||||
fetchItemID(byTitle: cleanTitle(title)) { result in
|
||||
switch result {
|
||||
case .success(let id):
|
||||
itemID = id
|
||||
case .failure(let error):
|
||||
Logger.shared.log("Failed to fetch AniList ID: \(error)")
|
||||
AnalyticsManager.shared.sendEvent(event: "error", additionalData: ["error": error, "message": "Failed to fetch AniList ID"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -873,42 +857,4 @@ struct MediaInfoView: View {
|
|||
}
|
||||
}.resume()
|
||||
}
|
||||
|
||||
private func fetchTMDBID(byTitle title: String, completion: @escaping (Result<Int, Error>) -> Void) {
|
||||
let encodedTitle = title.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
|
||||
let apiKey = "738b4edd0a156cc126dc4a4b8aea4aca"
|
||||
|
||||
let urlString = "https://api.themoviedb.org/3/search/multi?api_key=\(apiKey)&query=\(encodedTitle)"
|
||||
|
||||
guard let url = URL(string: urlString) else {
|
||||
completion(.failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"])))
|
||||
return
|
||||
}
|
||||
|
||||
URLSession.custom.dataTask(with: url) { data, _, error in
|
||||
if let error = error {
|
||||
completion(.failure(error))
|
||||
return
|
||||
}
|
||||
|
||||
guard let data = data else {
|
||||
completion(.failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "No data received"])))
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any],
|
||||
let results = json["results"] as? [[String: Any]],
|
||||
let firstResult = results.first,
|
||||
let id = firstResult["id"] as? Int {
|
||||
completion(.success(id))
|
||||
} else {
|
||||
let error = NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "No matching TMDB content found"])
|
||||
completion(.failure(error))
|
||||
}
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}.resume()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ struct SettingsViewGeneral: View {
|
|||
@AppStorage("mediaColumnsPortrait") private var mediaColumnsPortrait: Int = 2
|
||||
@AppStorage("mediaColumnsLandscape") private var mediaColumnsLandscape: Int = 4
|
||||
|
||||
private let metadataProvidersList = ["AniList", "TMDB"]
|
||||
private let metadataProvidersList = ["AniList"]
|
||||
@EnvironmentObject var settings: Settings
|
||||
|
||||
var body: some View {
|
||||
|
|
|
|||
Loading…
Reference in a new issue