Skip to content

Commit

Permalink
feat(src/all): New Source: MissAV (#2224)
Browse files Browse the repository at this point in the history
Co-authored-by: jmir1 <[email protected]>
  • Loading branch information
AwkwardPeak7 and jmir1 authored Sep 21, 2023
1 parent 0ce5997 commit 5a12d24
Show file tree
Hide file tree
Showing 10 changed files with 532 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/all/missav/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
19 changes: 19 additions & 0 deletions src/all/missav/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}

ext {
extName = 'MissAV'
pkgNameSuffix = 'all.missav'
extClass = '.MissAV'
extVersionCode = 1
containsNsfw = true
}

dependencies {
implementation(project(':lib-unpacker'))
implementation(project(':lib-playlist-utils'))
}

apply from: "$rootDir/common.gradle"
Binary file added src/all/missav/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/all/missav/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/all/missav/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/all/missav/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/all/missav/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/all/missav/res/web_hi_res_512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package eu.kanade.tachiyomi.animeextension.all.missav

import android.app.Application
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.lib.unpacker.Unpacker
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

class MissAV : AnimeHttpSource(), ConfigurableAnimeSource {

override val name = "MissAV"

override val lang = "all"

override val baseUrl = "https://missav.com"

override val supportsLatest = true

override val client = network.cloudflareClient

override fun headersBuilder() = super.headersBuilder()
.add("Referer", "$baseUrl/")

private val playlistExtractor by lazy {
PlaylistUtils(client, headers)
}

private val preferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

override fun popularAnimeRequest(page: Int) =
GET("$baseUrl/en/today-hot?page=$page", headers)

override fun popularAnimeParse(response: Response): AnimesPage {
val document = response.asJsoup()

val entries = document.select("div.thumbnail").map { element ->
SAnime.create().apply {
element.select("a.text-secondary").let {
setUrlWithoutDomain(it.attr("href"))
title = it.text()
}
thumbnail_url = element.selectFirst("img")?.attr("abs:data-src")
}
}

val hasNextPage = document.selectFirst("a[rel=next]") != null

return AnimesPage(entries, hasNextPage)
}

override fun latestUpdatesRequest(page: Int) =
GET("$baseUrl/en/new?page=$page", headers)

override fun latestUpdatesParse(response: Response) = popularAnimeParse(response)

override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val url = baseUrl.toHttpUrl().newBuilder().apply {
val genre = filters.firstInstanceOrNull<GenreList>()?.selected
if (query.isNotEmpty()) {
addEncodedPathSegments("en/search")
addPathSegment(query.trim())
} else if (genre != null) {
addEncodedPathSegments(genre)
} else {
addEncodedPathSegments("en/new")
}
filters.firstInstanceOrNull<SortFilter>()?.selected?.let {
addQueryParameter("sort", it)
}
addQueryParameter("page", page.toString())
}.build().toString()

return GET(url, headers)
}

override fun getFilterList() = getFilters()

override fun searchAnimeParse(response: Response) = popularAnimeParse(response)

override fun animeDetailsParse(response: Response): SAnime {
val document = response.asJsoup()

return SAnime.create().apply {
title = document.select("h1.text-base").text()
genre = document.select("div.text-secondary > a[href*=/genres/]").joinToString { it.text() }
description = document.select("div.mb-1").text()
author = document.select("div.text-secondary > a[href*=/makers/]").joinToString { it.text() }
artist = document.select("div.text-secondary > a[href*=/actresses/]").joinToString { it.text() }
status = SAnime.COMPLETED
thumbnail_url = document.select("video.player").attr("abs:data-poster")
}
}

override fun fetchEpisodeList(anime: SAnime): Observable<List<SEpisode>> {
return Observable.just(
listOf(
SEpisode.create().apply {
url = anime.url
name = "Episode"
},
),
)
}

override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()

val playlists = document.selectFirst("script:containsData(function(p,a,c,k,e,d))")?.html()
?.let(Unpacker::unpack)?.ifEmpty { null }
?: return emptyList()

val masterPlaylist = playlists.substringAfter("source=\"").substringBefore("\";")

return playlistExtractor.extractFromHls(masterPlaylist)
}

override fun List<Video>.sort(): List<Video> {
val quality = preferences.getString(PREF_QUALITY, PREF_QUALITY_DEFAULT)!!

return this.sortedWith(
compareBy { it.quality.contains(quality) },
).reversed()
}

override fun setupPreferenceScreen(screen: PreferenceScreen) {
ListPreference(screen.context).apply {
key = PREF_QUALITY
title = PREF_QUALITY_TITLE
entries = arrayOf("720p", "480p", "360p")
entryValues = arrayOf("720", "480", "360")
setDefaultValue(PREF_QUALITY_DEFAULT)
summary = "%s"
}.also(screen::addPreference)
}

override fun episodeListParse(response: Response): List<SEpisode> {
throw UnsupportedOperationException("Not Used")
}

private inline fun <reified T> List<*>.firstInstanceOrNull(): T? =
filterIsInstance<T>().firstOrNull()

companion object {
private const val PREF_QUALITY = "preferred_quality"
private const val PREF_QUALITY_TITLE = "Preferred quality"
private const val PREF_QUALITY_DEFAULT = "720"
}
}
Loading

0 comments on commit 5a12d24

Please sign in to comment.