trailer.to homepage

This commit is contained in:
LagradOst 2021-07-29 17:44:16 +02:00
parent 522e53eca6
commit 936ca06f7b
3 changed files with 51 additions and 3 deletions

View file

@ -29,6 +29,7 @@ object APIHolder {
private const val defProvider = 0 private const val defProvider = 0
val apis = arrayListOf( val apis = arrayListOf(
TrailersToProvider(),
ShiroProvider(), ShiroProvider(),
TenshiProvider(), TenshiProvider(),
WcoProvider(), WcoProvider(),
@ -36,7 +37,6 @@ object APIHolder {
DubbedAnimeProvider(), DubbedAnimeProvider(),
HDMProvider(), HDMProvider(),
//LookMovieProvider(), // RECAPTCHA (Please allow up to 5 seconds...) //LookMovieProvider(), // RECAPTCHA (Please allow up to 5 seconds...)
TrailersToProvider(),
) )
fun getApiFromName(apiName: String?): MainAPI { fun getApiFromName(apiName: String?): MainAPI {

View file

@ -15,8 +15,55 @@ class TrailersToProvider : MainAPI() {
override val hasQuickSearch: Boolean override val hasQuickSearch: Boolean
get() = true get() = true
override val hasMainPage: Boolean
get() = true
override fun getMainPage(): HomePageResponse? {
val response = khttp.get(mainUrl)
val document = Jsoup.parse(response.text)
val returnList = ArrayList<HomePageList>()
val docs = document.select("section.section > div.container")
for (doc in docs) {
val epList = doc.selectFirst("> div.owl-carousel") ?: continue
val title = doc.selectFirst("> div.text-center > h2").text()
val list = epList.select("> div.item > div.box-nina")
val isMovieType = title.contains("Movie")
val currentList = list.mapNotNull { head ->
val hrefItem = head.selectFirst("> div.box-nina-media > a")
val href = fixUrl(hrefItem.attr("href"))
val img = hrefItem.selectFirst("> img")
val posterUrl = img.attr("src")
val name = img.attr("alt")
return@mapNotNull if (isMovieType) MovieSearchResponse(
name,
href,
href,
this.name,
TvType.Movie,
posterUrl,
null
) else TvSeriesSearchResponse(
name,
href,
href,
this.name,
TvType.TvSeries,
posterUrl,
null, null
)
}
if (currentList.isNotEmpty()) {
returnList.add(HomePageList(title, currentList))
}
}
if(returnList.size <= 0) return null
return HomePageResponse(returnList)
//section.section > div.container > div.owl-carousel
}
override fun quickSearch(query: String): ArrayList<SearchResponse> { override fun quickSearch(query: String): ArrayList<SearchResponse> {
val url = "https://trailers.to/en/quick-search?q=$query" val url = "$mainUrl/en/quick-search?q=$query"
val response = khttp.get(url) val response = khttp.get(url)
val document = Jsoup.parse(response.text) val document = Jsoup.parse(response.text)
val items = document.select("div.group-post-minimal > a.post-minimal") val items = document.select("div.group-post-minimal > a.post-minimal")
@ -44,7 +91,7 @@ class TrailersToProvider : MainAPI() {
} }
override fun search(query: String): ArrayList<SearchResponse> { override fun search(query: String): ArrayList<SearchResponse> {
val url = "https://trailers.to/en/popular/movies-tvshows-collections?q=$query" val url = "$mainUrl/en/popular/movies-tvshows-collections?q=$query"
val response = khttp.get(url) val response = khttp.get(url)
val document = Jsoup.parse(response.text) val document = Jsoup.parse(response.text)
val items = document.select("div.col-lg-8 > article.list-item") val items = document.select("div.col-lg-8 > article.list-item")

View file

@ -31,6 +31,7 @@ class HomeViewModel : ViewModel() {
} else { } else {
autoloadRepo() autoloadRepo()
} }
_apiName.postValue(repo?.name)
_page.postValue(Resource.Loading()) _page.postValue(Resource.Loading())
_page.postValue(repo?.getMainPage()) _page.postValue(repo?.getMainPage())
} }