Replace search (#1574)
This commit is contained in:
parent
b236fc2a84
commit
7c56efd211
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'Google Drive'
|
||||
pkgNameSuffix = 'all.googledrive'
|
||||
extClass = '.GoogleDrive'
|
||||
extVersionCode = 3
|
||||
extVersionCode = 4
|
||||
libVersion = '13'
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,17 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
filters: AnimeFilterList,
|
||||
): Observable<AnimesPage> {
|
||||
val req = searchAnimeRequest(page, query, filters)
|
||||
return Observable.just(parsePage(req, page, query))
|
||||
|
||||
val filterList = if (filters.isEmpty()) getFilterList() else filters
|
||||
val urlFilter = filterList.find { it is URLFilter } as URLFilter
|
||||
|
||||
if (query.isNotEmpty()) throw Exception("Search is disabled. Use search in webview and add it as a single folder in filters.")
|
||||
|
||||
return if (urlFilter.state.isEmpty()) {
|
||||
Observable.just(parsePage(req, page))
|
||||
} else {
|
||||
Observable.just(addSinglePage(urlFilter.state))
|
||||
}
|
||||
}
|
||||
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
||||
@ -141,8 +151,10 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
// ============================== FILTERS ===============================
|
||||
|
||||
override fun getFilterList(): AnimeFilterList = AnimeFilterList(
|
||||
AnimeFilter.Header("Text search will only search inside selected server"),
|
||||
ServerFilter(getDomains()),
|
||||
AnimeFilter.Separator(),
|
||||
AnimeFilter.Header("Add single folder"),
|
||||
URLFilter(),
|
||||
)
|
||||
|
||||
private class ServerFilter(domains: Array<Pair<String, String>>) : UriPartFilter(
|
||||
@ -165,6 +177,8 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
fun toUriPart() = vals[state].second
|
||||
}
|
||||
|
||||
private class URLFilter : AnimeFilter.Text("Url")
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
|
||||
override fun animeDetailsRequest(anime: SAnime): Request {
|
||||
@ -395,7 +409,23 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
|
||||
private fun parsePage(request: Request, page: Int, matches: String? = null): AnimesPage {
|
||||
private fun addSinglePage(folderUrl: String): AnimesPage {
|
||||
val match = driveFolderRegex.matchEntire(folderUrl) ?: throw Exception("Invalid drive url")
|
||||
val recurDepth = match.groups["depth"]?.value ?: ""
|
||||
|
||||
val anime = SAnime.create()
|
||||
anime.title = match.groups["name"]?.value?.substringAfter("[")?.substringBeforeLast("]") ?: "Folder"
|
||||
anime.setUrlWithoutDomain(
|
||||
LinkData(
|
||||
"https://drive.google.com/drive/folders/${match.groups["id"]!!.value}$recurDepth",
|
||||
"multi",
|
||||
).toJsonString(),
|
||||
)
|
||||
anime.thumbnail_url = ""
|
||||
return AnimesPage(listOf(anime), false)
|
||||
}
|
||||
|
||||
private fun parsePage(request: Request, page: Int): AnimesPage {
|
||||
val animeList = mutableListOf<SAnime>()
|
||||
|
||||
val recurDepth = request.url.encodedFragment?.let { "#$it" } ?: ""
|
||||
@ -460,10 +490,6 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
)
|
||||
if (parsed.items == null) throw Exception("Failed to load items, please log in through webview")
|
||||
parsed.items.forEachIndexed { index, it ->
|
||||
if (matches != null) {
|
||||
if (!it.title.contains(matches, true)) return@forEachIndexed
|
||||
}
|
||||
|
||||
if (it.mimeType.startsWith("video")) {
|
||||
val anime = SAnime.create()
|
||||
anime.title = if (preferences.getBoolean("trim_anime_info", false)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user