Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite MangaTube extension #7241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Rewrite MangaTube extension #7241

wants to merge 1 commit into from

Conversation

Ayley
Copy link

@Ayley Ayley commented Jan 18, 2025

This commit includes a complete rewrite of the MangaTube extension, improving functionality and compatibility by leveraging the backend API and adopting models for a cleaner architecture.

Checklist:

  • Updated extVersionCode value in build.gradle for individual extensions
  • Updated overrideVersionCode or baseVersionCode as needed for all multisrc extensions
  • Referenced all related issues in the PR body (e.g. "Closes #xyz")
  • Added the isNsfw = true flag in build.gradle when appropriate
  • Have not changed source names
  • Have explicitly kept the id if a source's name or language were changed
  • Have tested the modifications by compiling and running the extension through Android Studio
  • Have removed web_hi_res_512.png when adding a new extension

Issues Closed
Closes #4240
Closes #4112

Notes for Reviewers
This rewrite uses the backend API of MangaTube instad of crawling the data, this should be faster
Users must open the webview for IP verification if their IP is not pre-approved by MangaTube.

This is my first pull request, and I'm open to feedback. Please let me know if any changes or improvements are needed!

This commit includes a complete rewrite of the MangaTube extension, improving functionality and compatibility by leveraging the backend API and adopting models for a cleaner architecture.
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val url = "$baseUrl/api/manga/search?page=$page&query=$query"

Log.d("MangaTube", "Search for: $query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove logs


private val json: Json by injectLazy()
return GET(url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return GET(url)
return GET(url, headers)

pass headers to set appropriate useragent and other headers to requests

.map { response ->
parseMangaFromJson(response, page < 96)
if(!res.success){
throw Exception("Something went wrong!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be more specific?

mangas[manga.title] = manga
SManga.create().apply {
title = manga.title
url = "$baseUrl${manga.url}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set relative urls or slug/id

Comment on lines +122 to +123
genre = manga.genre.map { genre -> Genre.fromId(genre)!! }
.joinToString(", ") { genre -> genre.displayName }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
genre = manga.genre.map { genre -> Genre.fromId(genre)!! }
.joinToString(", ") { genre -> genre.displayName }
genre = manga.genre.joinToString { genre -> Genre.fromId(genre)!!.displayName }

}

override fun latestUpdatesSelector() = "div#series-updates div.series-update:not([style\$=none])"
override fun latestUpdatesParse(response: Response): MangasPage {
val body = MangaTubeHelper.checkResponse(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider calling this method in an interceptor since you are checking response every time

}

override fun latestUpdatesNextPageSelector() = "button#load-more-updates"
override fun mangaDetailsRequest(manga: SManga): Request {
val url = "$baseUrl/api/manga/${mangas[manga.title]!!.id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save the id in the actual SManga url when returning, the hashmap above will not be initialized on app restart

this.contains("abgeschlossen", ignoreCase = true) -> SManga.COMPLETED
else -> SManga.UNKNOWN
override fun chapterListRequest(manga: SManga): Request {
val url = "$baseUrl/api/manga/${mangas[manga.title]!!.slug}/chapters"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

url = "$baseUrl${chapter.readerURL}"
name = chapter.name.ifBlank { "Chapter ${chapter.number}" }
date_upload =
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(chapter.publishedAt)!!.time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize `SimpleDateFormat in the class to avoide initializing it every time, and wrap the parsing in try catch to avoide breaking in case of bad dates

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider creating one dto file with all the dtos in the package root (not in dto subpackage).

also use regular classes instead of data class unless needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manga Tube Https 404
2 participants