@@ -299,7 +299,7 @@ class NekopoiProvider : MainAPI() {
299299 val realUrl = bypassOuo(ouoUrl) ? : return @amap
300300
301301 if (linkName.contains(" Mirror" , ignoreCase = true )) {
302- val bypassedAds = bypassMirrored(realUrl) ? : return @amap
302+ val bypassedAds = bypassMirrored(realUrl)
303303 bypassedAds.amap ads@{ adsLink ->
304304 val fixedEmbed = fixEmbed(adsLink) ? : return @ads
305305 loadExtractor(fixedEmbed, " $mainUrl /" , subtitleCallback) { link ->
@@ -457,23 +457,40 @@ class NekopoiProvider : MainAPI() {
457457
458458 private fun NiceResponse.selectMirror (): String? {
459459 return this .document.selectFirst(" script:containsData(#passcheck)" )?.data()
460- ?.substringAfter(" \" GET\" , \" " )?.substringBefore(" \" " )
460+ ?.substringAfter(" \" GET\" , \" " , " " )
461+ ?.substringBefore(" \" " , " " )
462+ ?.takeIf { it.isNotBlank() }
461463 }
462464
463- private suspend fun bypassMirrored (url : String? ): List <String ?> {
464- val request = session.get(url ? : return emptyList())
465- delay(500 )
466- val mirrorUrl = request.selectMirror() ? : run {
467- val nextUrl = request.document.select(" div.col-sm.centered.extra-top a" ).attr(" href" )
468- session.get(nextUrl).selectMirror()
469- }
470- return session.get(fixUrl(mirrorUrl ? : return emptyList(), mirroredHost)).document.select(" table.hoverable tbody tr" )
471- .filter { mirror ->
472- ! mirrorIsBlackList(mirror.selectFirst(" img" )?.attr(" alt" ))
473- }.amap {
474- val fileLink = it.selectFirst(" a" )?.attr(" href" )
475- session.get(fixUrl(fileLink ? : return @amap null , mirroredHost)).document.selectFirst(" div.code_wrap code" )?.text()
465+ private suspend fun bypassMirrored (url : String? ): List <String > {
466+ if (url.isNullOrBlank()) return emptyList()
467+ try {
468+ val request = session.get(url)
469+ delay(500 )
470+
471+ val mirrorUrl = request.selectMirror() ? : run {
472+ val nextUrl = request.document.selectFirst(" div.col-sm.centered.extra-top a, a.get_btn" )?.attr(" href" )
473+ if (nextUrl.isNullOrBlank()) return emptyList()
474+ session.get(fixUrl(nextUrl, mirroredHost)).selectMirror()
476475 }
476+
477+ if (mirrorUrl.isNullOrBlank()) return emptyList()
478+
479+ return session.get(fixUrl(mirrorUrl, mirroredHost)).document.select(" table.hoverable tbody tr" )
480+ .filter { mirror ->
481+ val hostName = mirror.selectFirst(" img" )?.attr(" alt" ) ? : " "
482+ ! mirrorIsBlackList(hostName)
483+ }.amap { row ->
484+ val fileLink = row.selectFirst(" a" )?.attr(" href" ) ? : return @amap null
485+ val res = session.get(fixUrl(fileLink, mirroredHost))
486+
487+ res.document.selectFirst(" div.code_wrap code" )?.text()?.takeIf { it.startsWith(" http" ) }
488+ ? : res.document.selectFirst(" a.btn, a.btn-primary" )?.attr(" href" )?.takeIf { it.startsWith(" http" ) }
489+ }.filterNotNull()
490+ } catch (e: Exception ) {
491+ e.printStackTrace()
492+ return emptyList()
493+ }
477494 }
478495
479496 private fun mirrorIsBlackList (host : String? ): Boolean {
0 commit comments