-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathCustomAnimeShowModel.kt
More file actions
132 lines (130 loc) · 5.56 KB
/
CustomAnimeShowModel.kt
File metadata and controls
132 lines (130 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.skyd.imomoe.model.impls.custom
import com.skyd.imomoe.bean.AnimeShowBean
import com.skyd.imomoe.bean.IAnimeShowBean
import com.skyd.imomoe.bean.PageNumberBean
import com.skyd.imomoe.config.Api
import com.skyd.imomoe.config.Const
import com.skyd.imomoe.model.util.JsoupUtil
import com.skyd.imomoe.model.interfaces.IAnimeShowModel
import org.jsoup.select.Elements
class CustomAnimeShowModel : IAnimeShowModel {
override suspend fun getAnimeShowData(
partUrl: String
): Pair<ArrayList<IAnimeShowBean>, PageNumberBean?> {
val url = Api.MAIN_URL + partUrl
var pageNumberBean: PageNumberBean? = null
val document = JsoupUtil.getDocument(url)
val animeShowList: ArrayList<IAnimeShowBean> = ArrayList()
//banner
val foucsBgElements: Elements = document.getElementsByClass("foucs bg")
for (i in foucsBgElements.indices) {
val foucsBgChildren: Elements = foucsBgElements[i].children()
for (j in foucsBgChildren.indices) {
when (foucsBgChildren[j].className()) {
"hero-wrap" -> {
animeShowList.add(
AnimeShowBean(
Const.ViewHolderTypeString.BANNER_1, "",
"", "", "", null, "",
CustomParseHtmlUtil.parseHeroWrap(
foucsBgChildren[j],
url
)
)
)
}
}
}
}
//area
var area: Elements = document.getElementsByClass("area")
if (partUrl == "/") //首页,有右边栏
area = document.getElementsByClass("area").select("[class=firs l]")
for (i in area.indices) {
val elements: Elements = area[i].children()
for (j in elements.indices) {
when (elements[j].className()) {
"dtit" -> {
val a = elements[j].select("h2").select("a")
if (a.size == 0) { //只有一个标题
animeShowList.add(
AnimeShowBean(
Const.ViewHolderTypeString.HEADER_1,
"",
"",
elements[j].select("h2").text(),
"",
null,
""
)
)
} else { //有右侧“更多”
animeShowList.add(
AnimeShowBean(
Const.ViewHolderTypeString.HEADER_1,
a.attr("href"),
Api.MAIN_URL + a.attr("href"),
a.text(),
elements[j].select("span").select("a").text(),
null,
""
)
)
}
}
"img", "imgs" -> {
animeShowList.addAll(
CustomParseHtmlUtil.parseImg(
elements[j],
url
)
)
}
"fire l" -> { //右侧前半tab内容
val firsLChildren = elements[j].children()
for (k in firsLChildren.indices) {
when (firsLChildren[k].className()) {
"lpic" -> {
animeShowList.addAll(
CustomParseHtmlUtil.parseLpic(
firsLChildren[k],
url
)
)
}
"pages" -> {
pageNumberBean =
CustomParseHtmlUtil.parseNextPages(
firsLChildren[k]
)
}
}
}
}
"dnews" -> { //右侧后半tab内容,cover4
animeShowList.addAll(
CustomParseHtmlUtil.parseDnews(
elements[j],
url
)
)
}
"topli" -> { //右侧后半tab内容,cover5
animeShowList.addAll(
CustomParseHtmlUtil.parseTopli(
elements[j]
)
)
}
"pages" -> {
pageNumberBean =
CustomParseHtmlUtil.parseNextPages(
elements[j]
)
}
}
}
}
return Pair(animeShowList, pageNumberBean)
}
}