diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Anime.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Anime.swift index 0784303a..2f045c5b 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Anime.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Anime.swift @@ -29,10 +29,10 @@ extension NASourceMonosChinos { ) .responseString.then { responseContent -> Anime in let bowl = try SwiftSoup.parse(responseContent) - let animeTitle = try bowl.select("header > .row > div > h1.Title").text() + let animeTitle = try bowl.select(".chapterdetails > h1").text() let animeArtworkUrl = URL( - string: try bowl.select("header > .row > div:first-child > .Image > figure > img").attr("src") + string: try bowl.select(".chapterpic > img").attr("src") ) ?? link.image let reconstructedAnimeLink = AnimeLink( title: animeTitle, @@ -42,13 +42,16 @@ extension NASourceMonosChinos { ) // Obtain the list of episodes - let episodeList = try bowl.select(".SerieCaps > a").compactMap { + let episodeList = try bowl.select(".allanimes > .row > .col-item").compactMap { episodeElement -> (identifier: String, episodeName: String) in - let episodeIdentifier = try episodeElement.attr("href") + let episodeIdentifier = try episodeElement.select("a").attr("href") let episodeName = try episodeElement.text() .trimmingCharacters(in: .whitespacesAndNewlines) return (episodeIdentifier, episodeName) } + print("\n\n") + print(episodeList) + print("\n\n") if episodeList.isEmpty { throw NineAnimatorError.responseError("No episode found for this anime") @@ -57,24 +60,23 @@ extension NASourceMonosChinos { // Collection of episodes var episodeCollection = Anime.EpisodesCollection() var episodeAttributes = [EpisodeLink: Anime.AdditionalEpisodeLinkInformation]() - + for (serverIdentifier, _) in NASourceMonosChinos.knownServers { var currentCollection = [EpisodeLink]() for (episodeIdentifier, episodeName) in episodeList { var conventionalEpisodeName = episodeName - let matchingRegex = try NSRegularExpression( - pattern: "(\\d+)\\sSub|Latino\\s(\\d+)", + pattern: "(\\d+)", options: [.caseInsensitive] ) + // error in tryUnwrap() let episodeNumberMatch = try matchingRegex .firstMatch(in: episodeName) .tryUnwrap() .firstMatchingGroup .tryUnwrap() let inferredEpisodeNumber = Int(episodeNumberMatch) - if let eNumber = inferredEpisodeNumber { conventionalEpisodeName = "\(eNumber) - \(episodeName)" } @@ -100,7 +102,7 @@ extension NASourceMonosChinos { episodeCollection[serverIdentifier] = currentCollection.reversed() } - + // Information let animeSynopsis = try bowl .select("header > .row > div > .Description > p") @@ -115,7 +117,7 @@ extension NASourceMonosChinos { .trimmingCharacters(in: .whitespacesAndNewlines) .components(separatedBy: " ") - additionalAnimeAttributes[.airDate] = date[1] +// additionalAnimeAttributes[.airDate] = date[0] return Anime( reconstructedAnimeLink, diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Episode.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Episode.swift index 46650b01..65ba79fc 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Episode.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Episode.swift @@ -21,6 +21,16 @@ import Foundation import NineAnimatorCommon import SwiftSoup +// server constants, probably a much better way to do this +let FEMBED = "Fembed" +let UQLOAD = "uqload" +let PLAYERSB = "playersb" +let STREAMTAPE = "streamtape" +let VIDEOBIN = "videobin" +let MP4UPLOAD = "mp4upload" +let serverList = [FEMBED, UQLOAD, PLAYERSB, STREAMTAPE, VIDEOBIN, MP4UPLOAD] + + extension NASourceMonosChinos { static let knownServers = [ "Cloud": "MonosChinos", @@ -29,11 +39,11 @@ extension NASourceMonosChinos { "Clipwatching": "ClipWatching", "Uqload": "Uqload", "Mp4upload": "Mp4Upload", -// "Ok": "Ok", Note: Commenting for now + // "Ok": "Ok", Note: Commenting for now "Videobin": "Videobin", "Senvid2": "SendVid" ] - + func episode(from link: EpisodeLink, with anime: Anime) -> NineAnimatorPromise { NineAnimatorPromise.firstly { URL(string: link.identifier) @@ -47,22 +57,42 @@ extension NASourceMonosChinos { episodeUrl, responseContent in let bowl = try SwiftSoup.parse(responseContent) - let playerId = try bowl.select("li[title=\(link.server)]").attr("data-tplayernv") + var encodedPlayerId = ""; // because variable can't be guaranteed to have a value, needs further fixing from the loop below + + let episodeList = try bowl.select("#play-video > a").compactMap { + episodeElement -> (serverId: String, sourceId: String) in + let serverName = try episodeElement.text() + let dataPlayerId = try episodeElement.attr("data-player") + + return (serverName, dataPlayerId ) + } + + for (serverName, dataPlayerId) in episodeList { + for server in serverList { + // link.server is the server the NineAnimator user selected +// print(String(format: "------------\nServer Name: %@\nUser Selected Server: %@\nServer Being Checked: %@\n----------------", serverName, link.server, server)) + if serverName.caseInsensitiveCompare(server) == .orderedSame && link.server.caseInsensitiveCompare(server) == .orderedSame { + encodedPlayerId = dataPlayerId + } + } + } + + let decodedData = Data(base64Encoded: encodedPlayerId)! + let decodedString = String(data: decodedData, encoding: .utf8)! + // Check if server is available for this episode - guard !playerId.isEmpty else { + guard !encodedPlayerId.isEmpty else { throw NineAnimatorError.responseError("This episode is not available on the selected server") } - let playerElement = try bowl.select("#\(playerId)").html() - let urlMatchingRegex = try NSRegularExpression( - pattern: "\\?url=(.*)(?:&|&)id", + pattern: "\\?url=(.*)", options: [] ) let urlParamMatch = try urlMatchingRegex - .firstMatch(in: playerElement) + .firstMatch(in: decodedString) .tryUnwrap(.responseError("Cannot find a valid URL to the resource")) .firstMatchingGroup .tryUnwrap() diff --git a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Search.swift b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Search.swift index 407a489d..fbef123f 100644 --- a/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Search.swift +++ b/Modules/Sources/NineAnimatorNativeSources/AnimeSources/MonoSchinos/MonosChinos+Search.swift @@ -41,21 +41,21 @@ extension NASourceMonosChinos { func more() { if performingTask == nil { performingTask = parent.requestManager.request( - "/search", + "/buscar", handling: .browsing, query: [ "q": title ] ) .responseString.then { [parent] responseContent -> [AnimeLink]? in try SwiftSoup.parse(responseContent) - .select(".row > article > a") + .select(".row > .col-6 > a") .compactMap { container -> AnimeLink? in - if let imageContainer = try container.select(".cover > img").first(), - let titleContainer = try container.select("h3.Title").first() { + if let imageContainer = try container.select(".series > .seriesimg > img").first(), + let titleContainer = try container.select(".series > .seriesdetails > h5").first() { let animeTitle = titleContainer .ownText() .trimmingCharacters(in: .whitespacesAndNewlines) - + let animeUrl = try URL(string: try container.attr("href")).tryUnwrap() let artworkUrl = try URL(string: try imageContainer.attr("src")).tryUnwrap()