From d5abd35bebbb145c5c364ea887a6ac9cf69b3c02 Mon Sep 17 00:00:00 2001 From: Francesco <100066266+cranci1@users.noreply.github.com> Date: Sun, 13 Apr 2025 12:11:54 +0200 Subject: [PATCH] yeah weird ass things --- Sora/Views/MediaInfoView/MediaInfoView.swift | 100 +++++++++++++++++-- Sulfur.xcodeproj/project.pbxproj | 16 +++ 2 files changed, 109 insertions(+), 7 deletions(-) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 70d52f4..9b08b39 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -50,6 +50,8 @@ struct MediaInfoView: View { @EnvironmentObject private var libraryManager: LibraryManager @State private var selectedRange: Range = 0..<100 + @State private var showSettingsMenu = false + @State private var customAniListID: Int? private var isGroupedBySeasons: Bool { return groupedEpisodes().count > 1 @@ -127,6 +129,55 @@ struct MediaInfoView: View { .padding(4) .background(Capsule().fill(Color.accentColor.opacity(0.4))) } + + Menu { + Button(action: { + showCustomIDAlert() + }) { + Label("Set Custom AniList ID", systemImage: "number") + } + + if let customID = customAniListID { + Button(action: { + customAniListID = nil + itemID = nil + 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)") + } + } + }) { + Label("Reset AniList ID", systemImage: "arrow.clockwise") + } + } + + if let id = itemID ?? customAniListID { + Button(action: { + if let url = URL(string: "https://anilist.co/anime/\(id)") { + openSafariViewController(with: url.absoluteString) + } + }) { + Label("Open in AniList", systemImage: "link") + } + } + + Divider() + + Button(action: { + Logger.shared.log("Debug Info:\nTitle: \(title)\nHref: \(href)\nModule: \(module.metadata.sourceName)\nAniList ID: \(itemID ?? -1)\nCustom ID: \(customAniListID ?? -1)", type: "Debug") + DropManager.shared.showDrop(title: "Debug Info Logged", subtitle: "", duration: 1.0, icon: UIImage(systemName: "terminal")) + }) { + Label("Log Debug Info", systemImage: "terminal") + } + } label: { + Image(systemName: "ellipsis.circle") + .resizable() + .frame(width: 20, height: 20) + .foregroundColor(.primary) + } } } } @@ -372,13 +423,19 @@ 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() - 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"]) + if let savedID = UserDefaults.standard.object(forKey: "custom_anilist_id_\(href)") as? Int { + customAniListID = savedID + itemID = savedID + Logger.shared.log("Using custom AniList ID: \(savedID)", type: "Debug") + } else { + 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"]) + } } } @@ -857,4 +914,33 @@ struct MediaInfoView: View { } }.resume() } + + private func showCustomIDAlert() { + let alert = UIAlertController(title: "Set Custom AniList ID", message: "Enter the AniList ID for this media", preferredStyle: .alert) + + alert.addTextField { textField in + textField.placeholder = "AniList ID" + textField.keyboardType = .numberPad + if let customID = customAniListID { + textField.text = "\(customID)" + } + } + + alert.addAction(UIAlertAction(title: "Cancel", style: .cancel)) + alert.addAction(UIAlertAction(title: "Save", style: .default) { _ in + if let text = alert.textFields?.first?.text, + let id = Int(text) { + customAniListID = id + itemID = id + UserDefaults.standard.set(id, forKey: "custom_anilist_id_\(href)") + Logger.shared.log("Set custom AniList ID: \(id)", type: "General") + } + }) + + if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, + let window = windowScene.windows.first, + let rootVC = window.rootViewController { + findTopViewController.findViewController(rootVC).present(alert, animated: true) + } + } } diff --git a/Sulfur.xcodeproj/project.pbxproj b/Sulfur.xcodeproj/project.pbxproj index 9bc5cec..a66215a 100644 --- a/Sulfur.xcodeproj/project.pbxproj +++ b/Sulfur.xcodeproj/project.pbxproj @@ -141,6 +141,7 @@ 13103E802D589D6C000F0673 /* Tracking Services */ = { isa = PBXGroup; children = ( + 13E62FBF2DABC3A20007E259 /* Trakt */, 13103E812D589D77000F0673 /* AniList */, ); path = "Tracking Services"; @@ -395,6 +396,21 @@ path = MediaPlayer; sourceTree = ""; }; + 13E62FBF2DABC3A20007E259 /* Trakt */ = { + isa = PBXGroup; + children = ( + 13E62FC02DABC3A90007E259 /* Auth */, + ); + path = Trakt; + sourceTree = ""; + }; + 13E62FC02DABC3A90007E259 /* Auth */ = { + isa = PBXGroup; + children = ( + ); + path = Auth; + sourceTree = ""; + }; 13EA2BD02D32D97400C1EBD7 /* CustomPlayer */ = { isa = PBXGroup; children = (