From 49fa3781b555bd8616ecaaa978ef34d921d20734 Mon Sep 17 00:00:00 2001 From: uttiya10 <56562649+uttiya10@users.noreply.github.com> Date: Sun, 25 Apr 2021 09:49:53 -0400 Subject: [PATCH] Various parser fixes (#245) * Fix Pantsudrive Parser * Fix StreamSB parser * Fix XStreamCDN Parser * Fix FastStreamParser --- .../hanime.tv/HAnime+Featured.swift | 14 +++++++++--- .../Media/Parser/FastStreamParser.swift | 4 +++- .../Media/Parser/PantsudriveParser.swift | 8 +++---- .../Models/Media/Parser/StreamSBParser.swift | 22 +++++++++++++++++-- .../Models/Media/Parser/XStreamParser.swift | 4 ++-- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/NineAnimator/Models/Anime Source/hanime.tv/HAnime+Featured.swift b/NineAnimator/Models/Anime Source/hanime.tv/HAnime+Featured.swift index 341ea2871..3cf6c8a89 100644 --- a/NineAnimator/Models/Anime Source/hanime.tv/HAnime+Featured.swift +++ b/NineAnimator/Models/Anime Source/hanime.tv/HAnime+Featured.swift @@ -128,8 +128,16 @@ extension NASourceHAnime { let tempUrl = try URL(string: url).tryUnwrap(.urlError) let realUrl = "\(tempUrl.path)?quality=\(quality)" - return cdn == "cps" - ? "https://i1.wp.com/static-assets.droidbuzz.top\(realUrl)" - : "https://i1.wp.com/dynamic-assets.imageg.top\(realUrl)" + if cdn == "cps" { + let cdns = [ + "https://i1.wp.com/static-assets.airharte.top\(realUrl)", + "https://i1.wp.com/static-assets.akidoo.top\(realUrl)", + "https://i1.wp.com/static-assets.mobilius.top\(realUrl)" + ] + + return cdns.randomElement()! + } + + return "https://i1.wp.com/dynamic-assets.imageg.top\(realUrl)" } } diff --git a/NineAnimator/Models/Media/Parser/FastStreamParser.swift b/NineAnimator/Models/Media/Parser/FastStreamParser.swift index 8cb00dde8..4c3cbf4d5 100644 --- a/NineAnimator/Models/Media/Parser/FastStreamParser.swift +++ b/NineAnimator/Models/Media/Parser/FastStreamParser.swift @@ -54,7 +54,9 @@ class FastStreamParser: VideoProviderParser { throw NineAnimatorError.providerError("Cannot find a streambale resource in the selected page") } - guard let resourceUrl = URL(string: resourceUrlString) else { + guard let resourceUrl = URL( + string: resourceUrlString, + relativeTo: URL(string: "https://www1.animeultima.to")) else { throw NineAnimatorError.urlError } diff --git a/NineAnimator/Models/Media/Parser/PantsudriveParser.swift b/NineAnimator/Models/Media/Parser/PantsudriveParser.swift index 6fefa0eeb..3067b52a5 100644 --- a/NineAnimator/Models/Media/Parser/PantsudriveParser.swift +++ b/NineAnimator/Models/Media/Parser/PantsudriveParser.swift @@ -23,7 +23,7 @@ import Foundation class PantsudriveParser: VideoProviderParser { var aliases: [String] { [] } - private static let apiURL = URL(string: "https://play.api-web.site/anime/videourl.php")! + private static let apiURL = URL(string: "https://gogo-stream.com/ajax.php")! private func getVideoID(url: URL) -> String? { guard let url = URLComponents(string: url.absoluteString) else { @@ -33,7 +33,7 @@ class PantsudriveParser: VideoProviderParser { } private struct APIResponse: Codable { - let url: [PlaybackFiles] + let source: [PlaybackFiles] } private struct PlaybackFiles: Codable { @@ -63,8 +63,8 @@ class PantsudriveParser: VideoProviderParser { case .success(let response): do { let videoURLString = try response - .url - .first + .source + .last .tryUnwrap(.decodeError("First Video URL")) .file diff --git a/NineAnimator/Models/Media/Parser/StreamSBParser.swift b/NineAnimator/Models/Media/Parser/StreamSBParser.swift index d10f80823..d792e6f3f 100644 --- a/NineAnimator/Models/Media/Parser/StreamSBParser.swift +++ b/NineAnimator/Models/Media/Parser/StreamSBParser.swift @@ -23,13 +23,31 @@ import Foundation class StreamSBParser: VideoProviderParser { var aliases: [String] { [] } - let videoSourceRegex = try! NSRegularExpression( + private let apiPath = URL(string: "https://streamsb.net/play")! + + private let videoSourceRegex = try! NSRegularExpression( pattern: #"file:"([^"]+)"#, options: .caseInsensitive ) + private let embedIDRegex = try! NSRegularExpression( + pattern: #"(?<=embed-).+?(?=\.)"#, + options: .caseInsensitive + ) + + private func retrieveId(from path: String) -> String? { + self.embedIDRegex + .firstMatch(in: path)? + .first + } + func parse(episode: Episode, with session: Session, forPurpose purpose: Purpose, onCompletion handler: @escaping NineAnimatorCallback) -> NineAnimatorAsyncTask { - session.request(episode.target).responseString { + let videoID = retrieveId(from: episode.target.absoluteString) ?? episode.target.absoluteString + let requestURL = apiPath.appendingPathComponent(videoID) + return session.request( + requestURL, + parameters: [ "auto": 1, "referer": episode.link.identifier ] + ).responseString { response in do { let responseContent: String diff --git a/NineAnimator/Models/Media/Parser/XStreamParser.swift b/NineAnimator/Models/Media/Parser/XStreamParser.swift index 2cfe30e88..76768d625 100644 --- a/NineAnimator/Models/Media/Parser/XStreamParser.swift +++ b/NineAnimator/Models/Media/Parser/XStreamParser.swift @@ -24,7 +24,7 @@ import Foundation class XStreamParser: VideoProviderParser { var aliases: [String] { [ "XStream", "XStreamCDN", "fembed" ] } - private static let apiBaseSourceURL = URL(string: "https://www.xstreamcdn.com/api/source/")! + private static let apiBaseSourceURL = URL(string: "https://fcdn.stream/api/source/")! private struct SourcesAPIResponse: Codable { var success: Bool @@ -51,7 +51,7 @@ class XStreamParser: VideoProviderParser { return session.request( XStreamParser.apiBaseSourceURL.appendingPathComponent(resourceIdentifier), method: .post, - parameters: [ "r": "", "d": "www.xstreamcdn.com" ], + parameters: [ "r": "", "d": "fcdn.stream" ], encoding: URLEncoding.default ) .responseJSON { response in