From ee624c39350f4e6f428bbae044c2730a8547521a Mon Sep 17 00:00:00 2001 From: Marcus Zhou <7273813+SuperMarcus@users.noreply.github.com> Date: Sat, 15 Jul 2023 16:25:06 -0500 Subject: [PATCH] Bump build number --- .../GogoAnime/GogoAnime+Anime.swift | 10 +++-- .../GogoAnime/GogoAnime+ContentProvider.swift | 11 ++++-- .../GogoAnime/GogoAnime+Episode.swift | 8 ++-- .../GogoAnime/GogoAnime+Featured.swift | 11 ++++-- .../GogoAnime+SourceDescriptor.swift | 38 +++++++++++++++++++ .../AnimeSources/GogoAnime/GogoAnime.swift | 27 ++++++++++++- NineAnimator.xcodeproj/project.pbxproj | 4 +- 7 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+SourceDescriptor.swift diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Anime.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Anime.swift index 530ed7c4..701724d0 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Anime.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Anime.swift @@ -30,10 +30,12 @@ extension NASourceGogoAnime { } func anime(url: URL) -> NineAnimatorPromise { - self.requestManager - .request(url: url, handling: .browsing) - .responseString - .thenPromise { content -> NineAnimatorPromise<(String, String)> in + self.requestDescriptor() + .thenPromise { + _ in self.requestManager + .request(url: url, handling: .browsing) + .responseString + } .thenPromise { content -> NineAnimatorPromise<(String, String)> in guard let animeIdentifier = try? SwiftSoup.parse(content) .select("input#movie_id.movie_id") .attr("value") else { diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+ContentProvider.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+ContentProvider.swift index 2a3c13e9..0c090234 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+ContentProvider.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+ContentProvider.swift @@ -73,10 +73,13 @@ extension NASourceGogoAnime { return } _lastRequest = _parent - .requestManager - .request(url: url, handling: .browsing) - .responseString - .then { + .requestDescriptor() + .thenPromise { + [weak self] _ in self?._parent + .requestManager + .request(url: url, handling: .browsing) + .responseString + } .then { [weak self] content -> [AnimeLink]? in guard let self = self else { return nil } diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Episode.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Episode.swift index 742856aa..80136239 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Episode.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Episode.swift @@ -51,9 +51,11 @@ extension NASourceGogoAnime { /// Retrieve the episode information struct for the episode at the particular path func episodeInformation(for episodePath: String) -> NineAnimatorPromise { - requestManager.request(episodePath, handling: .browsing) - .responseString - .then { content in + self.requestDescriptor() + .thenPromise { + [weak self] _ in self?.requestManager.request(episodePath, handling: .browsing) + .responseString + } .then { content in let bowl = try SwiftSoup.parse(content) // Parse the streaming sources diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Featured.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Featured.swift index 4f9c5e6b..9b705173 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Featured.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+Featured.swift @@ -28,9 +28,14 @@ extension NASourceGogoAnime { try! NSRegularExpression(pattern: "\\/(.+)-episode-\\d+$", options: .caseInsensitive) func featured() -> NineAnimatorPromise { - NineAnimatorPromise<[AnimeLink]>.queue(listOfPromises: [ - popularAnimeUpdates, latestAnimeUpdates - ]) .then { results in BasicFeaturedContainer(featured: results[0], latest: results[1]) } + self.requestDescriptor() + .thenPromise { + [weak self] _ -> NineAnimatorPromise<[[AnimeLink]]>? in + guard let self else { return nil } + return NineAnimatorPromise<[AnimeLink]>.queue(listOfPromises: [ + self.popularAnimeUpdates, self.latestAnimeUpdates + ]) + } .then { results in BasicFeaturedContainer(featured: results[0], latest: results[1]) } } fileprivate var latestAnimeUpdates: NineAnimatorPromise<[AnimeLink]> { diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+SourceDescriptor.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+SourceDescriptor.swift new file mode 100644 index 00000000..177dfdbf --- /dev/null +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime+SourceDescriptor.swift @@ -0,0 +1,38 @@ +// +// This file is part of the NineAnimator project. +// +// Copyright © 2018-2023 Marcus Zhou. All rights reserved. +// +// NineAnimator is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// NineAnimator is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with NineAnimator. If not, see . +// + +import Foundation + +import Foundation +import JavaScriptCore +import NineAnimatorCommon + +extension NASourceGogoAnime { + struct SourceDescriptor: Codable { + var currentHost: String + var currentAjaxEndpoint: String + } + + func requestUncachedDescriptor() -> NineAnimatorPromise { + NineAnimator.default.cloud.requestSourceDescriptor( + source: self, + descriptorType: SourceDescriptor.self + ) + } +} diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime.swift index 1d3c44d5..0e9ea560 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/GogoAnime/GogoAnime.swift @@ -46,9 +46,19 @@ class NASourceGogoAnime: BaseSource, Source, PromiseSource { \.english } - override var endpoint: String { "https://gogoanime.vet" } + override var endpoint: String { self._cachedDescriptor?.currentHost ?? "https://gogoanime.vet" } - let ajaxEndpoint = URL(string: "https://ajax.apimovie.xyz")! + var ajaxEndpoint: URL { + var dynamicEndpoint: URL? + + if let ajaxEndpointStr = self._cachedDescriptor?.currentAjaxEndpoint { + dynamicEndpoint = URL(string: ajaxEndpointStr) + } + + return dynamicEndpoint ?? URL(string: "https://ajax.apimovie.xyz")! + } + + private var _cachedDescriptor: SourceDescriptor? func search(keyword: String) -> ContentProvider { GogoContentProvider(query: keyword, parent: self) @@ -61,4 +71,17 @@ class NASourceGogoAnime: BaseSource, Source, PromiseSource { override required init(with parent: NineAnimator) { super.init(with: parent) } + + /// Request the source descriptor object + func requestDescriptor() -> NineAnimatorPromise { + // Serve cached descriptor is possible + if let cached = self._cachedDescriptor { + return .success(cached) + } + + return requestUncachedDescriptor().then { + self._cachedDescriptor = $0 + return $0 + } + } } diff --git a/NineAnimator.xcodeproj/project.pbxproj b/NineAnimator.xcodeproj/project.pbxproj index 2111e3b2..2a6d54f7 100644 --- a/NineAnimator.xcodeproj/project.pbxproj +++ b/NineAnimator.xcodeproj/project.pbxproj @@ -2086,7 +2086,7 @@ CODE_SIGN_ENTITLEMENTS = NineAnimator/NineAnimator.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = 8WB2V923XT; ENABLE_BITCODE = NO; @@ -2119,7 +2119,7 @@ CODE_SIGN_ENTITLEMENTS = NineAnimator/NineAnimator.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = 8WB2V923XT; ENABLE_BITCODE = NO;