Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Fix MonosChinos search, anime, episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ExuApplePie committed Jan 22, 2022
1 parent 104be62 commit 8ceb109
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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)"
}
Expand All @@ -100,7 +102,7 @@ extension NASourceMonosChinos {

episodeCollection[serverIdentifier] = currentCollection.reversed()
}

// Information
let animeSynopsis = try bowl
.select("header > .row > div > .Description > p")
Expand All @@ -115,7 +117,7 @@ extension NASourceMonosChinos {
.trimmingCharacters(in: .whitespacesAndNewlines)
.components(separatedBy: " ")

additionalAnimeAttributes[.airDate] = date[1]
// additionalAnimeAttributes[.airDate] = date[0]

return Anime(
reconstructedAnimeLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<Episode> {
NineAnimatorPromise.firstly {
URL(string: link.identifier)
Expand All @@ -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=(.*)(?:&amp;|&)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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8ceb109

Please sign in to comment.