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

refactor: Backport refactorations from [REDACTED] #2764

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 6 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,19 @@ src/<lang>/<mysourcename>/
13 directories, 9 files
```

`<lang>` should be an ISO 639-1 compliant language code (two letters or `all`). `<mysourcename>`
should be adapted from the site name, and can only contain lowercase ASCII letters and digits.
Your extension code must be placed in the package `eu.kanade.tachiyomi.animeextension.<lang>.<mysourcename>`.

#### AndroidManifest.xml
A minimal [Android manifest file](https://developer.android.com/guide/topics/manifest/manifest-intro) is needed for Android to recognize a extension when it's compiled into an APK file. You can also add intent filters inside this file (see [URL intent filter](#url-intent-filter) for more information).

#### build.gradle
Make sure that your new extension's `build.gradle` file follows the following structure:

```gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

ext {
extName = '<My source name>'
pkgNameSuffix = '<lang>.<mysourcename>'
extClass = '.<MySourceName>'
extVersionCode = 1
containsNsfw = true
Expand All @@ -234,8 +234,7 @@ apply from: "$rootDir/common.gradle"

| Field | Description |
| ----- | ----------- |
| `extName` | The name of the extension. |
| `pkgNameSuffix` | A unique suffix added to `eu.kanade.tachiyomi.animeextension`. The language and the site name should be enough. Remember your extension code implementation must be placed in this package. |
| `extName` | The name of the extension. Should be romanized if site name is not in English.|
| `extClass` | Points to the class that implements `AnimeSource`. You can use a relative path starting with a dot (the package name is the base path). This is used to find and instantiate the source(s). |
| `extVersionCode` | The extension version code. This must be a positive integer and incremented with any change to the code. |
| `libVersion` | (Optional, defaults to `14`) The version of the [extensions library](https://github.com/aniyomiorg/extensions-lib) used. |
Expand Down Expand Up @@ -408,7 +407,7 @@ open class UriPartFilter(displayName: String, private val vals: Array<Pair<Strin

### Misc notes

- Sometimes you may find no use for some inherited methods. If so just override them and throw exceptions: `throw UnsupportedOperationException("Not used.")`
- Sometimes you may find no use for some inherited methods. If so just override them and throw exceptions: `throw UnsupportedOperationException()`
- You probably will find `getUrlWithoutDomain` useful when parsing the target source URLs. Keep in mind there's a current issue with spaces in the URL though, so if you use it, replace all spaces with URL encoded characters (like `%20`).
- If possible try to stick to the general workflow from `AnimeHttpSource`/`AnimeParsedHttpSource`; breaking them may cause you more headache than necessary.
- By implementing `ConfigurableAnimeSource` you can add settings to your source, which is backed by [`SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences).
Expand Down
7 changes: 5 additions & 2 deletions common.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
apply plugin: 'org.jmailen.kotlinter'

android {
Expand All @@ -21,11 +24,11 @@ android {
defaultConfig {
minSdkVersion AndroidConfig.minSdk
targetSdkVersion AndroidConfig.targetSdk
applicationIdSuffix pkgNameSuffix
applicationIdSuffix project.parent.name + "." + project.name
versionCode extVersionCode
versionName project.ext.properties.getOrDefault("libVersion", "14") + ".$extVersionCode"
base {
archivesName = "aniyomi-$pkgNameSuffix-v$versionName"
archivesName = "aniyomi-$applicationIdSuffix-v$versionName"
}
def readmes = project.projectDir.listFiles({ File file ->
file.name.equals("README.md") ||
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ org.gradle.caching=true

# Enable AndroidX dependencies
android.useAndroidX=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp_version = "8.0.2"
agp_version = "8.2.1"
coroutines_version = "1.7.1"
kotlin_version = "1.8.22"
serialization_version = "1.5.1"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
11 changes: 5 additions & 6 deletions multisrc/overrides/datalifeengine/frenchanime/src/FrenchAnime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.lang.Exception

class FrenchAnime : DataLifeEngine(
"French Anime",
Expand Down Expand Up @@ -82,9 +81,9 @@ class FrenchAnime : DataLifeEngine(
return episodeList.reversed()
}

override fun episodeListSelector(): String = throw Exception("not used")
override fun episodeListSelector(): String = throw UnsupportedOperationException()

override fun episodeFromElement(element: Element): SEpisode = throw Exception("not used")
override fun episodeFromElement(element: Element): SEpisode = throw UnsupportedOperationException()

// ============================ Video Links =============================
override suspend fun getVideoList(episode: SEpisode): List<Video> {
Expand All @@ -109,9 +108,9 @@ class FrenchAnime : DataLifeEngine(
return list
}

override fun videoFromElement(element: Element): Video = throw Exception("Not Used")
override fun videoFromElement(element: Element): Video = throw UnsupportedOperationException()

override fun videoListSelector(): String = throw Exception("Not Used")
override fun videoListSelector(): String = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document): String = throw Exception("Not Used")
override fun videoUrlParse(document: Document): String = throw UnsupportedOperationException()
}
6 changes: 3 additions & 3 deletions multisrc/overrides/datalifeengine/wiflix/src/Wiflix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class Wiflix : DataLifeEngine(
return list
}

override fun videoFromElement(element: Element): Video = throw Exception("Not Used")
override fun videoFromElement(element: Element): Video = throw UnsupportedOperationException()

override fun videoListSelector(): String = throw Exception("Not Used")
override fun videoListSelector(): String = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document): String = throw Exception("Not Used")
override fun videoUrlParse(document: Document): String = throw UnsupportedOperationException()
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ abstract class AnimeStream(
return emptyList()
}

override fun videoFromElement(element: Element) = throw Exception("Not Used")
override fun videoFromElement(element: Element) = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document) = throw Exception("Not Used")
override fun videoUrlParse(document: Document) = throw UnsupportedOperationException()

// ============================== Settings ==============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ abstract class DataLifeEngine(

// =============================== Latest ===============================

override fun latestUpdatesRequest(page: Int): Request = throw Exception("Not Used")
override fun latestUpdatesRequest(page: Int): Request = throw UnsupportedOperationException()

override fun latestUpdatesSelector(): String = throw Exception("Not Used")
override fun latestUpdatesSelector(): String = throw UnsupportedOperationException()

override fun latestUpdatesNextPageSelector(): String = throw Exception("Not Used")
override fun latestUpdatesNextPageSelector(): String = throw UnsupportedOperationException()

override fun latestUpdatesFromElement(element: Element): SAnime = throw Exception("Not Used")
override fun latestUpdatesFromElement(element: Element): SAnime = throw UnsupportedOperationException()

// =============================== Search ===============================

Expand Down Expand Up @@ -139,7 +139,7 @@ abstract class DataLifeEngine(
}
}

override fun animeDetailsParse(document: Document): SAnime = throw Exception("Not used")
override fun animeDetailsParse(document: Document): SAnime = throw UnsupportedOperationException()

private fun animeDetailsParse(response: Response, baseAnime: SAnime): SAnime {
val document = response.asJsoup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.lang.Exception
import java.text.SimpleDateFormat
import java.util.Locale

Expand Down Expand Up @@ -124,7 +123,7 @@ abstract class DooPlay(
}
}

override fun episodeFromElement(element: Element): SEpisode = throw Exception("not used")
override fun episodeFromElement(element: Element): SEpisode = throw UnsupportedOperationException()

protected open fun episodeFromElement(element: Element, seasonName: String): SEpisode {
return SEpisode.create().apply {
Expand All @@ -145,13 +144,13 @@ abstract class DooPlay(
}

// ============================ Video Links =============================
override fun videoListParse(response: Response): List<Video> = throw Exception("not used")
override fun videoListParse(response: Response): List<Video> = throw UnsupportedOperationException()

override fun videoListSelector(): String = throw Exception("not used")
override fun videoListSelector(): String = throw UnsupportedOperationException()

override fun videoFromElement(element: Element): Video = throw Exception("not used")
override fun videoFromElement(element: Element): Video = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document): String = throw Exception("not used")
override fun videoUrlParse(document: Document): String = throw UnsupportedOperationException()

// =============================== Search ===============================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ abstract class DopeFlix(
}

// ============================== Episodes ==============================
override fun episodeListSelector() = throw Exception("not used")
override fun episodeListSelector() = throw UnsupportedOperationException()

override fun episodeListParse(response: Response): List<SEpisode> {
val document = response.use { it.asJsoup() }
Expand Down Expand Up @@ -154,7 +154,7 @@ abstract class DopeFlix(
}
}

override fun episodeFromElement(element: Element): SEpisode = throw Exception("not used")
override fun episodeFromElement(element: Element): SEpisode = throw UnsupportedOperationException()

private fun parseEpisodesFromSeries(element: Element): List<SEpisode> {
val seasonId = element.attr("data-id")
Expand Down Expand Up @@ -245,11 +245,11 @@ abstract class DopeFlix(
).reversed()
}

override fun videoListSelector() = throw Exception("not used")
override fun videoListSelector() = throw UnsupportedOperationException()

override fun videoFromElement(element: Element) = throw Exception("not used")
override fun videoFromElement(element: Element) = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document) = throw Exception("not used")
override fun videoUrlParse(document: Document) = throw UnsupportedOperationException()

// ============================== Settings ==============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ abstract class ZoroTheme(
return emptyList()
}

override fun videoListSelector() = throw Exception("not used")
override fun videoListSelector() = throw UnsupportedOperationException()

override fun videoFromElement(element: Element) = throw Exception("not used")
override fun videoFromElement(element: Element) = throw UnsupportedOperationException()

override fun videoUrlParse(document: Document) = throw Exception("not used")
override fun videoUrlParse(document: Document) = throw UnsupportedOperationException()

// ============================= Utilities ==============================
private fun Set<String>.contains(s: String, ignoreCase: Boolean): Boolean {
Expand Down
11 changes: 3 additions & 8 deletions multisrc/src/main/java/generator/ThemeSourceGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,18 @@ interface ThemeSourceGenerator {
gradle.writeText(
"""
|// THIS FILE IS AUTO-GENERATED; DO NOT EDIT
|plugins {
| alias(libs.plugins.android.application)
| alias(libs.plugins.kotlin.android)
| alias(libs.plugins.kotlin.serialization)
|}
|
|ext {
| extName = '${source.name}'
| pkgNameSuffix = '${pkgNameSuffix(source, ".")}'
| extClass = '.${source.className}'
| extFactory = '$themePkg'
| extVersionCode = ${baseVersionCode + source.overrideVersionCode + MULTISRC_LIBRARY_VERSION}
| ${if (source.isNsfw) "containsNsfw = true\n" else ""}
|}
|
|apply from: "${'$'}rootDir/common.gradle"
|
|$defaultAdditionalGradleText
|$additionalGradleOverrideText
|apply from: "${'$'}rootDir/common.gradle"
|
|android {
| defaultConfig {
Expand Down
7 changes: 0 additions & 7 deletions src/all/animeonsen/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
}

ext {
extName = 'AnimeOnsen'
pkgNameSuffix = 'all.animeonsen'
extClass = '.AnimeOnsen'
extVersionCode = 7
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import okhttp3.Response
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import kotlin.Exception

class AnimeOnsen : ConfigurableAnimeSource, AnimeHttpSource() {

Expand Down Expand Up @@ -70,8 +69,8 @@ class AnimeOnsen : ConfigurableAnimeSource, AnimeHttpSource() {
}

// =============================== Latest ===============================
override fun latestUpdatesRequest(page: Int) = throw Exception("not used")
override fun latestUpdatesParse(response: Response) = throw Exception("not used")
override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException()
override fun latestUpdatesParse(response: Response) = throw UnsupportedOperationException()

// =============================== Search ===============================
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList) =
Expand Down Expand Up @@ -133,7 +132,7 @@ class AnimeOnsen : ConfigurableAnimeSource, AnimeHttpSource() {

override fun videoListRequest(episode: SEpisode) = GET("$apiUrl/content/${episode.url}")

override fun videoUrlParse(response: Response) = throw Exception("not used")
override fun videoUrlParse(response: Response) = throw UnsupportedOperationException()

// ============================== Settings ==============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
Expand Down
Loading