revert to "Probably fix filler fetching"

This commit is contained in:
scigward 2025-08-19 09:00:49 +03:00
parent 4f28f785bf
commit 8e21c669cb
6 changed files with 3 additions and 83 deletions

View file

@ -152,7 +152,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
private var malID: Int?
private var skipIntervals: (op: CMTimeRange?, ed: CMTimeRange?) = (nil, nil)
private var preloadedSkipInfo: SkipInfo? = nil
private var skipIntroButton: UIButton!
private var skipOutroButton: UIButton!
@ -267,7 +266,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
onWatchNext: @escaping () -> Void,
subtitlesURL: String?,
aniListID: Int,
skipInfo: SkipInfo? = nil,
totalEpisodes: Int,
episodeImageUrl: String,headers:[String:String]?) {
@ -282,7 +280,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
self.onWatchNext = onWatchNext
self.subtitlesURL = subtitlesURL
self.aniListID = aniListID
self.preloadedSkipInfo = skipInfo
self.headers = headers
self.totalEpisodes = totalEpisodes
@ -396,11 +393,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
view.bringSubviewToFront(subtitleStackView)
subtitleStackView.isHidden = !SubtitleSettingsManager.shared.settings.enabled
if let info = preloadedSkipInfo {
if let s = info.opStart, let e = info.opEnd { self.skipIntervals.op = CMTimeRange(start: CMTime(seconds: s, preferredTimescale: 600), end: CMTime(seconds: e, preferredTimescale: 600)) }
if let s = info.edStart, let e = info.edEnd { self.skipIntervals.ed = CMTimeRange(start: CMTime(seconds: s, preferredTimescale: 600), end: CMTime(seconds: e, preferredTimescale: 600)) }
self.updateSegments()
}
AniListMutation().fetchMalID(animeId: aniListID) { [weak self] result in
switch result {
case .success(let mal):

View file

@ -55,18 +55,6 @@ enum DownloadType: String, Codable {
case .episode:
return "Episode"
}
// MARK: - Skip Information
struct SkipInfo: Codable, Equatable {
let opStart: Double?
let opEnd: Double?
let edStart: Double?
let edEnd: Double?
let introURL: String?
let outroURL: String?
}
}
}
@ -82,7 +70,6 @@ struct DownloadedAsset: Identifiable, Codable, Equatable {
// New fields for subtitle support
let subtitleURL: URL?
let localSubtitleURL: URL?
let skipInfo: SkipInfo?
// For caching purposes, but not stored as part of the codable object
private var _cachedFileSize: Int64? = nil
@ -426,7 +413,6 @@ struct AssetMetadata: Codable {
let showPosterURL: URL? // Main show poster URL (distinct from episode-specific images)
let episodeTitle: String?
let seasonNumber: Int?
let anilistId: Int?
init(
title: String,

View file

@ -20,11 +20,10 @@ struct DownloadRequest {
let episode: Int?
let subtitleURL: URL?
let showPosterURL: URL?
let anilistId: Int?
init(url: URL, headers: [String: String], title: String? = nil, imageURL: URL? = nil,
isEpisode: Bool = false, showTitle: String? = nil, season: Int? = nil,
episode: Int? = nil, subtitleURL: URL? = nil, showPosterURL: URL? = nil, anilistId: Int? = nil) {
episode: Int? = nil, subtitleURL: URL? = nil, showPosterURL: URL? = nil) {
self.url = url
self.headers = headers
self.title = title
@ -35,7 +34,6 @@ struct DownloadRequest {
self.episode = episode
self.subtitleURL = subtitleURL
self.showPosterURL = showPosterURL
self.anilistId = anilistId
}
}
@ -410,7 +408,6 @@ extension JSController {
episode: request.episode,
subtitleURL: request.subtitleURL,
showPosterURL: request.showPosterURL,
anilistId: request.anilistId,
completionHandler: completionHandler
)
}

View file

@ -1208,31 +1208,6 @@ extension JSController: AVAssetDownloadDelegate {
// Add to saved assets and save
DownloadPersistence.upsert(newAsset)
// Fetch skip info in background if we know AniList ID & episode number
if let meta = newAsset.metadata, let aId = meta.anilistId, let ep = meta.episodeNumber {
self.fetchSkipInfo(anilistId: aId, episodeNumber: ep) { info in
guard let info = info else { return }
let updated = DownloadedAsset(
id: newAsset.id,
name: newAsset.name,
downloadDate: newAsset.downloadDate,
originalURL: newAsset.originalURL,
localURL: newAsset.localURL,
imageURL: newAsset.imageURL,
fileSize: newAsset.fileSize,
type: newAsset.type,
progress: newAsset.progress,
headers: newAsset.headers,
referer: newAsset.referer,
userAgent: newAsset.userAgent,
metadata: newAsset.metadata,
subtitleURL: newAsset.subtitleURL,
localSubtitleURL: newAsset.localSubtitleURL,
skipInfo: info
)
DownloadPersistence.upsert(updated)
}
}
DispatchQueue.main.async { [weak self] in
self?.savedAssets = DownloadPersistence.load()
self?.objectWillChange.send()
@ -1671,35 +1646,4 @@ enum DownloadQueueStatus: Equatable {
case downloading
/// Download has been completed
case completed
// MARK: - Offline Skip Info (lightweight)
private struct _AniSkipEntry: Codable { let interval: _Interval }
private struct _Interval: Codable { let startTime: Double; let endTime: Double }
private struct _AniSkipAPIResponse: Codable { let found: Bool; let results: [String:[_AniSkipEntry]]? }
private func fetchSkipInfo(anilistId: Int, episodeNumber: Int, completion: @escaping (SkipInfo?) -> Void) {
// Convert AniList -> MAL
AniListMutation().fetchMalID(animeId: anilistId) { res in
guard case .success(let malId) = res, let malId = malId else { completion(nil); return }
// Build requests for OP and ED
let types = ["op","ed"]
var info = SkipInfo(opStart: nil, opEnd: nil, edStart: nil, edEnd: nil, introURL: nil, outroURL: nil)
let group = DispatchGroup()
for t in types {
group.enter()
let urlStr = "https://api.aniskip.com/v2/skip-times/" + String(malId) + "?episode=" + String(episodeNumber) + "&types=" + t + "&anilistID=" + String(anilistId)
guard let url = URL(string: urlStr) else { group.leave(); continue }
URLSession.shared.dataTask(with: url) { data, _, _ in
defer { group.leave() }
guard let data = data, let resp = try? JSONDecoder().decode(_AniSkipAPIResponse.self, from: data), resp.found else { return }
if let entries = resp.results?[t], let first = entries.first {
if t == "op" { info = SkipInfo(opStart: first.interval.startTime, opEnd: first.interval.endTime, edStart: info.edStart, edEnd: info.edEnd, introURL: nil, outroURL: nil) }
if t == "ed" { info = SkipInfo(opStart: info.opStart, opEnd: info.opEnd, edStart: first.interval.startTime, edEnd: first.interval.endTime, introURL: nil, outroURL: nil) }
}
}.resume()
}
group.notify(queue: .main) { completion((info.opStart != nil || info.edStart != nil) ? info : nil) }
}
}
}

View file

@ -34,7 +34,6 @@ extension JSController {
showTitle: String? = nil,
season: Int? = nil,
episode: Int? = nil,
anilistId: Int? = nil,
subtitleURL: URL? = nil,
showPosterURL: URL? = nil,
completionHandler: ((Bool, String) -> Void)? = nil

View file

@ -976,6 +976,8 @@ private extension EpisodeCell {
}
}.resume()
}
// Removed Jikan fetching from EpisodeCell. All filler/Jikan handling is now in MediaInfoView and passed in via `fillerEpisodes`.
func handleFetchFailure(error: Error) {
Logger.shared.log("Episode details fetch error: \(error.localizedDescription)", type: "Error")