feat: resolve AniList episodes through ZokoAnime
This commit is contained in:
@@ -8,10 +8,23 @@ private struct StreamResolutionError: LocalizedError {
|
||||
enum StreamURL: Sendable {
|
||||
case youtube(URL)
|
||||
case miruro(mediaID: String, episode: Int)
|
||||
case anilist(mediaID: String, episode: Int)
|
||||
|
||||
static func parse(_ text: String) throws -> StreamURL {
|
||||
let text = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let url = try YouTubeResolver.validateURL(text)
|
||||
if url.host?.lowercased() == "zokoanime.video" {
|
||||
let invalid = StreamResolutionError(message: "Enter https://zokoanime.video/stream/ani/<AniList ID>/<episode>/sub with canonical positive numbers.")
|
||||
guard let c = URLComponents(string: text), c.scheme == "https", c.user == nil, c.password == nil,
|
||||
c.port == nil || c.port == 443, c.query == nil, c.fragment == nil,
|
||||
c.percentEncodedPath == c.path,
|
||||
!text.contains(where: { $0.isWhitespace || $0 == "\\" }) else { throw invalid }
|
||||
let p = c.path.split(separator: "/", omittingEmptySubsequences: false)
|
||||
guard p.count == 6, p[0].isEmpty, p[1] == "stream", p[2] == "ani", p[5] == "sub",
|
||||
let episode = Int(p[4]), String(episode) == p[4],
|
||||
ResolvedSource.validAniListIdentity(mediaID: String(p[3]), episode: episode) else { throw invalid }
|
||||
return .anilist(mediaID: String(p[3]), episode: episode)
|
||||
}
|
||||
if url.host?.lowercased() != "barelystarted.miruro.tv" { return .youtube(url) }
|
||||
let invalid = StreamResolutionError(message: "Enter a Miruro episode URL from barelystarted.miruro.tv with an explicit positive episode number.")
|
||||
guard !text.unicodeScalars.contains(where: {
|
||||
@@ -62,6 +75,7 @@ struct MiruroPlaybackRequirements: Sendable {
|
||||
var segmentOrigin: String? = nil
|
||||
var playlistQuery: [String: String] = [:]
|
||||
var embed = false
|
||||
var zoko = false
|
||||
}
|
||||
|
||||
struct MiruroSelection: Sendable {
|
||||
|
||||
Reference in New Issue
Block a user