diff --git a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift index 109b792..fae44fd 100644 --- a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift +++ b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift @@ -920,6 +920,24 @@ class CustomMediaPlayerViewController: UIViewController { } DispatchQueue.main.async { + if let currentItem = self.player.currentItem, currentItem.duration.seconds > 0 { + let progress = min(max(self.currentTimeVal / self.duration, 0), 1.0) + + let item = ContinueWatchingItem( + id: UUID(), + imageUrl: self.episodeImageUrl, + episodeNumber: self.episodeNumber, + mediaTitle: self.titleText, + progress: progress, + streamUrl: self.streamURL, + fullUrl: self.fullUrl, + subtitles: self.subtitlesURL, + aniListID: self.aniListID, + module: self.module + ) + ContinueWatchingManager.shared.save(item: item) + } + let remainingPercentage = (self.duration - self.currentTimeVal) / self.duration if remainingPercentage < 0.1 && self.module.metadata.type == "anime" && self.aniListID != 0 { @@ -1008,23 +1026,6 @@ class CustomMediaPlayerViewController: UIViewController { }) } } - - if let currentItem = player.currentItem, currentItem.duration.seconds > 0 { - let progress = currentTimeVal / currentItem.duration.seconds - let item = ContinueWatchingItem( - id: UUID(), - imageUrl: episodeImageUrl, - episodeNumber: episodeNumber, - mediaTitle: titleText, - progress: progress, - streamUrl: streamURL, - fullUrl: fullUrl, - subtitles: subtitlesURL, - aniListID: aniListID, - module: module - ) - ContinueWatchingManager.shared.save(item: item) - } } func repositionWatchNextButton() { @@ -1581,7 +1582,7 @@ class CustomMediaPlayerViewController: UIViewController { try audioSession.setActive(true) try audioSession.overrideOutputAudioPort(.speaker) } catch { - Logger.shared.log("Failed to set up AVAudioSession: \(error)") + Logger.shared.log("Didn't set up AVAudioSession: \(error)", type: "Debug") } } diff --git a/Sora/Utils/MediaPlayer/NormalPlayer.swift b/Sora/Utils/MediaPlayer/NormalPlayer.swift index 656eac2..dd8a5f6 100644 --- a/Sora/Utils/MediaPlayer/NormalPlayer.swift +++ b/Sora/Utils/MediaPlayer/NormalPlayer.swift @@ -55,7 +55,7 @@ class NormalPlayer: AVPlayerViewController { try audioSession.overrideOutputAudioPort(.speaker) } catch { - Logger.shared.log("Failed to set up AVAudioSession: \(error)") + Logger.shared.log("Didn't set up AVAudioSession: \(error)", type: "Debug") } } } diff --git a/Sora/Utils/MediaPlayer/VideoPlayer.swift b/Sora/Utils/MediaPlayer/VideoPlayer.swift index e26f29a..b917dd9 100644 --- a/Sora/Utils/MediaPlayer/VideoPlayer.swift +++ b/Sora/Utils/MediaPlayer/VideoPlayer.swift @@ -114,22 +114,9 @@ class VideoPlayerViewController: UIViewController { UserDefaults.standard.set(currentTime, forKey: "lastPlayedTime_\(fullURL)") UserDefaults.standard.set(duration, forKey: "totalTime_\(fullURL)") - let remainingPercentage = (duration - currentTime) / duration - - if remainingPercentage < 0.1 && self.module.metadata.type == "anime" && self.aniListID != 0 { - let aniListMutation = AniListMutation() - aniListMutation.updateAnimeProgress(animeId: self.aniListID, episodeNumber: self.episodeNumber) { result in - switch result { - case .success: - Logger.shared.log("Successfully updated AniList progress for episode \(self.episodeNumber)", type: "General") - case .failure(let error): - Logger.shared.log("Failed to update AniList progress: \(error.localizedDescription)", type: "Error") - } - } - } - if let streamUrl = self.streamUrl { - let progress = currentTime / duration + let progress = min(max(currentTime / duration, 0), 1.0) + let item = ContinueWatchingItem( id: UUID(), imageUrl: self.episodeImageUrl, @@ -144,6 +131,20 @@ class VideoPlayerViewController: UIViewController { ) ContinueWatchingManager.shared.save(item: item) } + + let remainingPercentage = (duration - currentTime) / duration + + if remainingPercentage < 0.1 && self.module.metadata.type == "anime" && self.aniListID != 0 { + let aniListMutation = AniListMutation() + aniListMutation.updateAnimeProgress(animeId: self.aniListID, episodeNumber: self.episodeNumber) { result in + switch result { + case .success: + Logger.shared.log("Successfully updated AniList progress for episode \(self.episodeNumber)", type: "General") + case .failure(let error): + Logger.shared.log("Failed to update AniList progress: \(error.localizedDescription)", type: "Error") + } + } + } } } diff --git a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift index 54ec7ed..5511d98 100644 --- a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift +++ b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift @@ -124,11 +124,6 @@ struct EpisodeCell: View { } private func fetchEpisodeDetails() { - guard episodeID != 0 else { - isLoading = false - return - } - guard let url = URL(string: "https://api.ani.zip/mappings?anilist_id=\(itemID)") else { isLoading = false return diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 6d0ee74..e714da3 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -35,6 +35,7 @@ struct MediaInfoView: View { @State var isFetchingEpisode: Bool = false @State private var refreshTrigger: Bool = false + @State private var buttonRefreshTrigger: Bool = false @State private var selectedEpisodeNumber: Int = 0 @State private var selectedEpisodeImage: String = "" @@ -169,6 +170,7 @@ struct MediaInfoView: View { .cornerRadius(10) } .disabled(isFetchingEpisode) + .id(buttonRefreshTrigger) Button(action: { libraryManager.toggleBookmark( @@ -363,6 +365,8 @@ struct MediaInfoView: View { } } .onAppear { + buttonRefreshTrigger.toggle() + if !hasFetched { DropManager.shared.showDrop(title: "Fetching Data", subtitle: "Please wait while fetching.", duration: 1.0, icon: UIImage(systemName: "arrow.triangle.2.circlepath")) fetchDetails() diff --git a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewTrackers.swift b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewTrackers.swift index 18ca0c2..6ec6b94 100644 --- a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewTrackers.swift +++ b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewTrackers.swift @@ -20,7 +20,7 @@ struct SettingsViewTrackers: View { var body: some View { Form { - Section(header: Text("AniList"), footer: Text("Sora and cranci1 are not affiliated with AniList in any way.\n\nNote that push updates may not be 100% acurate.")) { + Section(header: Text("AniList"), footer: Text("Sora and cranci1 are not affiliated with AniList in any way.\n\nNote that progresses update may not be 100% acurate.")) { HStack() { KFImage(URL(string: "https://raw.githubusercontent.com/cranci1/Ryu/2f10226aa087154974a70c1ec78aa83a47daced9/Ryu/Assets.xcassets/Listing/Anilist.imageset/anilist.png")) .placeholder { @@ -53,7 +53,7 @@ struct SettingsViewTrackers: View { } } if isLoggedIn { - Toggle("Send push updates", isOn: $isSendPushUpdates) + Toggle("Sync progreses", isOn: $isSendPushUpdates) .tint(.accentColor) } Button(isLoggedIn ? "Log Out from AniList.co" : "Log In with AniList.co") {