-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: refactor code & captcha validate
- Loading branch information
Showing
67 changed files
with
4,387 additions
and
3,622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
app/src/main/kotlin/com/muedsa/jcytv/exception/NeedValidateCaptchaException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.muedsa.jcytv.exception | ||
|
||
class NeedValidateCaptchaException : RuntimeException() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.muedsa.jcytv.model | ||
|
||
class JcyRankList( | ||
val title: String, | ||
val list: List<JcyRankVideoInfo> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.muedsa.jcytv.model | ||
|
||
class JcyVideoRow( | ||
val title: String, | ||
val list: List<JcySimpleVideoInfo> | ||
) |
4 changes: 0 additions & 4 deletions
4
app/src/main/kotlin/com/muedsa/jcytv/repository/AppRepository.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
app/src/main/kotlin/com/muedsa/jcytv/repository/JcyRepo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.muedsa.jcytv.repository | ||
|
||
import com.google.common.net.HttpHeaders | ||
import com.muedsa.jcytv.KEY_CAPTCHA_GUARD_OK | ||
import com.muedsa.jcytv.exception.NeedValidateCaptchaException | ||
import com.muedsa.jcytv.model.JcyRankList | ||
import com.muedsa.jcytv.model.JcySimpleVideoInfo | ||
import com.muedsa.jcytv.model.JcyVideoDetail | ||
import com.muedsa.jcytv.model.JcyVideoRow | ||
import com.muedsa.jcytv.util.JcyConst | ||
import com.muedsa.jcytv.util.JcyHtmlParserTool | ||
import com.muedsa.jcytv.util.JcyPlaySourceTool.CHROME_USER_AGENT | ||
import com.muedsa.jcytv.util.JcyRotateCaptchaTool | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.flow.map | ||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
import org.jsoup.nodes.Element | ||
import javax.inject.Inject | ||
|
||
class JcyRepo @Inject constructor(dataStoreRepo: DataStoreRepo) { | ||
|
||
private val guardOkFlow: Flow<String> = dataStoreRepo.dataStore.data | ||
.map { it[KEY_CAPTCHA_GUARD_OK] ?: "" } | ||
|
||
private suspend fun getGuardOk(): String = guardOkFlow.firstOrNull() ?: "" | ||
|
||
suspend fun fetchHomeVideoRows(): List<JcyVideoRow> { | ||
val doc: Document = Jsoup.connect(JcyConst.HOME_URL) | ||
.header(HttpHeaders.REFERER, JcyConst.HOME_URL) | ||
.header(HttpHeaders.USER_AGENT, JcyConst.CHROME_USER_AGENT) | ||
.cookie(JcyRotateCaptchaTool.COOKIE_GUARD_OK, getGuardOk()) | ||
.get() | ||
checkIfNeedValidateCaptcha(doc.head()) | ||
return JcyHtmlParserTool.parseHomVideoRows(doc.body()) | ||
} | ||
|
||
suspend fun fetchRankList(): List<JcyRankList> { | ||
val doc: Document = Jsoup.connect(JcyConst.RANK_URL) | ||
.header(HttpHeaders.REFERER, JcyConst.RANK_URL) | ||
.header(HttpHeaders.USER_AGENT, JcyConst.CHROME_USER_AGENT) | ||
.cookie(JcyRotateCaptchaTool.COOKIE_GUARD_OK, getGuardOk()) | ||
.get() | ||
checkIfNeedValidateCaptcha(doc.head()) | ||
return JcyHtmlParserTool.parseRankList(doc.body()) | ||
} | ||
|
||
suspend fun searchVideos(query: String): List<JcySimpleVideoInfo> { | ||
val doc: Document = Jsoup.connect("${JcyConst.SEARCH_URL}$query") | ||
.header(HttpHeaders.REFERER, JcyConst.RANK_URL) | ||
.header(HttpHeaders.USER_AGENT, JcyConst.CHROME_USER_AGENT) | ||
.cookie(JcyRotateCaptchaTool.COOKIE_GUARD_OK, getGuardOk()) | ||
.get() | ||
checkIfNeedValidateCaptcha(doc.head()) | ||
val vodListEl = doc.body().selectFirst(".vod-list")!! | ||
return JcyHtmlParserTool.parseVideoRow(vodListEl).list | ||
} | ||
|
||
suspend fun catalog(queryMap: Map<String, String>): List<JcySimpleVideoInfo> { | ||
val query = queryMap.toSortedMap().map { | ||
"/${it.key}/${it.value}" | ||
}.joinToString("") | ||
val doc: Document = Jsoup.connect(JcyConst.CATALOG_URL.replace("{query}", query)) | ||
.header(HttpHeaders.REFERER, JcyConst.RANK_URL) | ||
.header(HttpHeaders.USER_AGENT, JcyConst.CHROME_USER_AGENT) | ||
.cookie(JcyRotateCaptchaTool.COOKIE_GUARD_OK, getGuardOk()) | ||
.get() | ||
checkIfNeedValidateCaptcha(doc.head()) | ||
val vodListEl = doc.body().selectFirst(".vod-list")!! | ||
return JcyHtmlParserTool.parseVideoRow(vodListEl).list | ||
} | ||
|
||
suspend fun fetchVideoDetail(id: Long): JcyVideoDetail { | ||
val url = JcyConst.DETAIL_URL.replace("{id}", id.toString()) | ||
val doc: Document = Jsoup.connect(url) | ||
.header(HttpHeaders.REFERER, url) | ||
.header(HttpHeaders.USER_AGENT, CHROME_USER_AGENT) | ||
.cookie(JcyRotateCaptchaTool.COOKIE_GUARD_OK, getGuardOk()) | ||
.get() | ||
checkIfNeedValidateCaptcha(doc.head()) | ||
return JcyHtmlParserTool.parseVideoDetail(doc.body()) | ||
} | ||
|
||
private fun checkIfNeedValidateCaptcha(body: Element) { | ||
if (JcyRotateCaptchaTool.checkIfNeedValidateCaptcha(body)) | ||
throw NeedValidateCaptchaException() | ||
} | ||
} |
Oops, something went wrong.