-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathCustomAnimeDetailModel.kt
More file actions
178 lines (174 loc) · 9.08 KB
/
CustomAnimeDetailModel.kt
File metadata and controls
178 lines (174 loc) · 9.08 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.skyd.imomoe.model.impls.custom
import com.skyd.imomoe.bean.*
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.IAnimeDetailModel
import org.jsoup.select.Elements
class CustomAnimeDetailModel : IAnimeDetailModel {
override suspend fun getAnimeDetailData(
partUrl: String
): Triple<ImageBean, String, ArrayList<IAnimeDetailBean>> {
val animeDetailList: ArrayList<IAnimeDetailBean> = ArrayList()
val cover = ImageBean("", "", "", "")
var title = ""
val url = Api.MAIN_URL + partUrl
val document = JsoupUtil.getDocument(url)
//番剧头部信息
val area: Elements = document.getElementsByClass("area")
for (i in area.indices) {
val areaChildren = area[i].children()
for (j in areaChildren.indices) {
when (areaChildren[j].className()) {
"fire l" -> {
var alias = ""
var info = ""
var year = ""
var index = ""
var animeArea = ""
val animeType: MutableList<AnimeTypeBean> = ArrayList()
val tag: MutableList<AnimeTypeBean> = ArrayList()
val fireLChildren =
areaChildren[j].select("[class=fire l]")[0].children()
for (k in fireLChildren.indices) {
when (fireLChildren[k].className()) {
"thumb l" -> {
cover.url = CustomParseHtmlUtil.getCoverUrl(
fireLChildren[k].select("img").attr("src")
, url
)
cover.referer = url
}
"rate r" -> {
val rateR = fireLChildren[k]
title = rateR.select("h1").text()
val sinfo: Elements = rateR.select("[class=sinfo]")
val span: Elements = sinfo.select("span")
val p: Elements = sinfo.select("p")
if (p.size == 1) {
alias = p[0].text()
} else if (p.size == 2) {
alias = p[0].text()
info = p[1].text()
}
year = span[0].text()
animeArea = span[1].select("a").text()
index = span[3].select("a").text()
val typeElements: Elements = span[2].select("a")
for (l in typeElements.indices) {
animeType.add(
AnimeTypeBean(
"",
typeElements[l].attr("href"),
Api.MAIN_URL + typeElements[l].attr("href"),
typeElements[l].text()
)
)
}
val tagElements: Elements = span[4].select("a")
for (l in tagElements.indices) {
tag.add(
AnimeTypeBean(
"",
tagElements[l].attr("href"),
Api.MAIN_URL + tagElements[l].attr("href"),
tagElements[l].text()
)
)
}
}
"tabs", "tabs noshow" -> { //播放列表+header
val menu0 = fireLChildren[k].select("[class=menu0]")[0]
val main0 = fireLChildren[k].select("[class=main0]")[0]
val li = menu0.select("li")
var movurl = main0.select("[class=movurl]")
if (movurl.size == 0)
movurl = main0.select("[class=movurl movurl_pan]")
for (l: Int in li.indices) {
if (movurl[l].select("ul").select("li").size == 0) continue
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HEADER_1, "",
li[l].text(),
"",
null
)
)
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HORIZONTAL_RECYCLER_VIEW_1,
"",
"",
"",
CustomParseHtmlUtil.parseMovurls(movurl[l])
)
)
}
}
"botit" -> { //其它header
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HEADER_1, "",
CustomParseHtmlUtil.parseBotit(fireLChildren[k]),
"",
null
)
)
}
"dtit" -> { //其它header
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HEADER_1, "",
CustomParseHtmlUtil.parseDtit(fireLChildren[k]),
"",
null
)
)
}
"info" -> { //动漫介绍
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.ANIME_DESCRIBE_1, "",
"",
fireLChildren[k]
.select("[class=info]").text(),
null
)
)
}
"img" -> { //系列动漫推荐
animeDetailList.addAll(
CustomParseHtmlUtil.parseImg(fireLChildren[k], url)
)
}
}
}
val animeInfoBean = AnimeInfoBean(
"",
"",
title,
ImageBean("", "", cover.url, url),
alias,
animeArea,
year,
index,
animeType,
tag,
info
)
animeDetailList.add(
0,
AnimeDetailBean(
Const.ViewHolderTypeString.ANIME_INFO_1, "",
"",
"",
headerInfo = animeInfoBean
)
)
}
}
}
}
return Triple(cover, title, animeDetailList)
}
}