commit 98ed7e88394cfe9e703353e20e7ff9912885b53f Author: almightyhak Date: Thu Jun 20 11:54:12 2024 +0700 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..336ff3c0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# Editor configuration, see https://editorconfig.org +root = true + +[*.kt] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +ktlint_experimental = enabled +ktlint_experimental_argument-list-wrapping = disabled # Doesn't play well with Android Studio +ktlint_experimental_comment-wrapping = disabled diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..176a458f --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..668f125f --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,32 @@ +**PLEASE READ THIS** + +I acknowledge that: + +- I have updated to the latest version of the app (stable is v0.15.2.2) +- I have updated all extensions +- If this is an issue with the app itself, that I should be opening an issue in https://github.com/aniyomiorg/aniyomi +- I have searched the existing issues for duplicates +- For source requests, I have checked the list of existing extensions including the multi-source spreadsheet: https://aniyomi.org/extensions/ + +**DELETE THIS SECTION IF YOU HAVE READ AND ACKNOWLEDGED IT** + +--- + +## Device information +* Aniyomi version: ? +* Android version: ? +* Device: ? + +## Source information +* Source name: ? +* Source extension version: ? + +## Steps to reproduce +1. First step +2. Second step + +## Issue/Request +? + +## Other details +Additional details and attachments. diff --git a/.github/ISSUE_TEMPLATE/01_report_issue.yml b/.github/ISSUE_TEMPLATE/01_report_issue.yml new file mode 100644 index 00000000..acbe78bd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/01_report_issue.yml @@ -0,0 +1,107 @@ +name: 🐞 Issue report +description: Report a source issue in Aniyomi +labels: [Bug] +body: + + - type: input + id: source + attributes: + label: Source information + description: | + You can find the extension name and version in **Browse → Extensions**. + placeholder: | + Example: "AnimePahe 14.19 (English)" + validations: + required: true + + - type: input + id: language + attributes: + label: Source language + placeholder: | + Example: "English" + validations: + required: true + + - type: textarea + id: reproduce-steps + attributes: + label: Steps to reproduce + description: Provide an example of the issue. Be as specific as possible. + placeholder: | + Example: + 1. First step (e.g. "Open Mahouka Koukou No Rettousei (first season)") + 2. Second step (e.g. "Try to watch episode 15") + 3. Issue here (e.g. "It shows a HTTP 403 error toast") + validations: + required: true + + - type: textarea + id: expected-behavior + attributes: + label: Expected behavior + placeholder: | + Example: + "This should happen..." + validations: + required: true + + - type: textarea + id: actual-behavior + attributes: + label: Actual behavior + placeholder: | + Example: + "This happened instead..." + validations: + required: true + + - type: input + id: aniyomi-version + attributes: + label: Aniyomi version + description: | + You can find your Aniyomi version in **More → About**. + placeholder: | + Example: "0.15.2.4" or "Preview r7473" + validations: + required: true + + - type: input + id: android-version + attributes: + label: Android version + description: | + You can find this somewhere in your Android settings. + placeholder: | + Example: "Android 11" + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + + - type: checkboxes + id: acknowledgements + attributes: + label: Acknowledgements + description: Your issue will be closed if you haven't done these steps. + options: + - label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open or closed issue. + required: true + - label: I have written a short but informative title. + required: true + - label: I have updated the app to version **[0.15.2.4](https://github.com/aniyomiorg/aniyomi/releases/latest)**. + required: true + - label: I have updated all installed extensions. + required: true + - label: I have tried the [troubleshooting guide](https://aniyomi.org/docs/guides/troubleshooting/). + required: true + - label: If this is an issue with the app itself, I should be opening an issue in the [app repository](https://github.com/aniyomiorg/aniyomi/issues/new/choose). + required: true + - label: I will fill out all of the requested information in this form. + required: true diff --git a/.github/ISSUE_TEMPLATE/02_request_source.yml b/.github/ISSUE_TEMPLATE/02_request_source.yml new file mode 100644 index 00000000..bc4cd131 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/02_request_source.yml @@ -0,0 +1,56 @@ +name: 🌐 Source request +description: Suggest a new source for Aniyomi +labels: [Source request] +body: + + - type: input + id: name + attributes: + label: Source name + placeholder: | + Example: "Not Real Source" + validations: + required: true + + - type: input + id: link + attributes: + label: Source link + placeholder: | + Example: "https://notrealsource.org" + validations: + required: true + + - type: input + id: language + attributes: + label: Source language + placeholder: | + Example: "English" + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + Example: "+18/NSFW = yes" + + - type: checkboxes + id: acknowledgements + attributes: + label: Acknowledgements + description: Your issue will be closed if you haven't done these steps. + options: + - label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open or closed issue. + required: true + - label: I have written a title with source name. + required: true + - label: I have checked that the extension does not already exist on the [website extensions list](https://aniyomi.org/extensions/) or the app. + required: true + - label: I have checked that the extension does not already exist by searching the [GitHub repository](https://github.com/aniyomiorg/aniyomi-extensions/) and verified it does not appear in the code base. + required: true + - label: I will fill out all of the requested information in this form. + required: true diff --git a/.github/ISSUE_TEMPLATE/03_report_url_change.yml b/.github/ISSUE_TEMPLATE/03_report_url_change.yml new file mode 100644 index 00000000..819e66e2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/03_report_url_change.yml @@ -0,0 +1,57 @@ +name: 🔗 URL change report +description: Report URL change of an existing source +labels: [Bug,Domain changed] +body: + + - type: input + id: source + attributes: + label: Source information + description: | + You can find the extension name and version in **Browse → Extensions**. + placeholder: | + Example: "NotRealSource 14.1" + validations: + required: true + + - type: input + id: language + attributes: + label: Source language + placeholder: | + Example: "English" + validations: + required: true + + - type: input + id: link + attributes: + label: Source new URL + placeholder: | + Example: "https://notrealsource.org" + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + + - type: checkboxes + id: acknowledgements + attributes: + label: Acknowledgements + description: Your issue will be closed if you haven't done these steps. + options: + - label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open or closed issue. + required: true + - label: I have written a short but informative title. + required: true + - label: I have updated all installed extensions. + required: true + - label: I have opened WebView and checked that the source URL is not updated yet. + required: true + - label: I will fill out all of the requested information in this form. + required: true diff --git a/.github/ISSUE_TEMPLATE/04_report_dead_source.yml b/.github/ISSUE_TEMPLATE/04_report_dead_source.yml new file mode 100644 index 00000000..59942ab1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/04_report_dead_source.yml @@ -0,0 +1,63 @@ +name: ❌ Dead source report +description: Source is down and website is closed +labels: [Source is down] +body: + + - type: markdown + attributes: + value: | + ### Notice + If you have a lot of dead sources to report, please go back and submit a single meta request. + + - type: input + id: source + attributes: + label: Source name + description: | + You can find the extension name in **Browse → Extensions**. + placeholder: | + Example: "NotRealSource" + validations: + required: true + + - type: input + id: language + attributes: + label: Source language + placeholder: | + Example: "English" + validations: + required: true + + - type: input + id: link + attributes: + label: Source link + placeholder: | + Example: "https://notrealsource.org" + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + + - type: checkboxes + id: acknowledgements + attributes: + label: Acknowledgements + description: Your issue will be closed if you haven't done these steps. + options: + - label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open or closed issue. + required: true + - label: I have written a title with source name. + required: true + - label: I have updated all installed extensions. + required: true + - label: I have opened WebView and checked that the source website is down. + required: true + - label: I will fill out all of the requested information in this form. + required: true diff --git a/.github/ISSUE_TEMPLATE/05_request_feature.yml b/.github/ISSUE_TEMPLATE/05_request_feature.yml new file mode 100644 index 00000000..e47281fb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/05_request_feature.yml @@ -0,0 +1,59 @@ +name: ⭐ Feature request +description: Suggest a feature to improve an existing source +labels: [Feature request] +body: + + - type: input + id: source + attributes: + label: Source name + description: | + You can find the extension name in **Browse → Extensions**. + placeholder: | + Example: "DopeBox" + validations: + required: true + + - type: input + id: language + attributes: + label: Source language + placeholder: | + Example: "English" + validations: + required: true + + - type: textarea + id: feature-description + attributes: + label: Describe your suggested feature + description: How can an existing extension be improved? + placeholder: | + Example: + "It should work like this..." + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + + - type: checkboxes + id: acknowledgements + attributes: + label: Acknowledgements + description: Your issue will be closed if you haven't done these steps. + options: + - label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open or closed issue. + required: true + - label: I have written a short but informative title. + required: true + - label: If this is an issue with the app itself, I should be opening an issue in the [app repository](https://github.com/aniyomiorg/aniyomi/issues/new/choose). + required: true + - label: I have updated the app to version **[0.15.2.4](https://github.com/aniyomiorg/aniyomi/releases/latest)**. + required: true + - label: I will fill out all of the requested information in this form. + required: true diff --git a/.github/ISSUE_TEMPLATE/06_request_meta.yml b/.github/ISSUE_TEMPLATE/06_request_meta.yml new file mode 100644 index 00000000..f6003b85 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/06_request_meta.yml @@ -0,0 +1,41 @@ +name: 🧠 Meta request +description: Suggest improvements to the project +labels: [Meta request] +body: + + - type: textarea + id: feature-description + attributes: + label: Describe why this should be added + description: How can the project be improved? + placeholder: | + Example: + "It should work like this..." + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + + - type: checkboxes + id: acknowledgements + attributes: + label: Acknowledgements + description: Your issue will be closed if you haven't done these steps. + options: + - label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open (or closed) issue. + required: true + - label: I have written a short but informative title. + required: true + - label: If this is an issue with the app itself, I should be opening an issue in the [app repository](https://github.com/aniyomiorg/aniyomi/issues/new/choose). + required: true + - label: I have updated the app to version **[0.15.2.4](https://github.com/aniyomiorg/aniyomi/releases/latest)**. + required: true + - label: I have updated all installed extensions. + required: true + - label: I will fill out all of the requested information in this form. + required: true diff --git a/.github/ISSUE_TEMPLATE/07_request_removal.yml b/.github/ISSUE_TEMPLATE/07_request_removal.yml new file mode 100644 index 00000000..7b3617bf --- /dev/null +++ b/.github/ISSUE_TEMPLATE/07_request_removal.yml @@ -0,0 +1,33 @@ +name: 🗑 Source removal request +description: Scanlators can request their site to be removed +labels: [Meta request] +body: + + - type: input + id: link + attributes: + label: Source link + placeholder: | + Example: "https://notrealscans.org" + validations: + required: true + + - type: textarea + id: other-details + attributes: + label: Other details + placeholder: | + Additional details and attachments. + + - type: checkboxes + id: requirements + attributes: + label: Requirements + description: Your request will be denied if you don't meet these requirements. + options: + - label: Proof of ownership/intent to remove sent to a Aniyomi Discord server mod via DM + required: true + - label: Site only hosts content scanlated by the group and not stolen from other scanlators or official releases (i.e., not an aggregator site) + required: true + - label: Site is not infested with user-hostile features (e.g., invasive or malicious ads) + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..9e1a6b4e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,14 @@ +blank_issues_enabled: false +contact_links: + - name: ⚠️ Application issue + url: https://github.com/aniyomiorg/aniyomi/issues/new/choose + about: Issues and requests about the app itself should be opened in the tachiyomi repository instead + - name: 📦 Aniyomi extensions + url: https://aniyomi.org/extensions + about: List of all available extensions with download links + - name: 🖥️ Aniyomi website + url: https://aniyomi.org/help/ + about: Guides, troubleshooting, and answers to common questions + - name: Aniyomi app GitHub repository + url: https://github.com/aniyomiorg/aniyomi + about: Issues about the app itself should be opened here instead. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..e0276c30 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,10 @@ +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 diff --git a/.github/readme-images/app-icon.png b/.github/readme-images/app-icon.png new file mode 100644 index 00000000..c77fb428 Binary files /dev/null and b/.github/readme-images/app-icon.png differ diff --git a/.github/scripts/bump-versions.py b/.github/scripts/bump-versions.py new file mode 100644 index 00000000..ec2d56a8 --- /dev/null +++ b/.github/scripts/bump-versions.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +from concurrent.futures import Future, ThreadPoolExecutor, as_completed +import itertools +from pathlib import Path +import re +import subprocess +import sys + +VERSION_STR = "VersionCode =" +VERSION_REGEX = re.compile(f"{VERSION_STR} (\\d+)") +BUMPED_FILES: list[Path] = [] + +BOT_EMAIL = "aniyomi-bot@aniyomi.org" +BOT_NAME = "aniyomi-bot[bot]" + +def has_match(query: str, file: Path) -> tuple[Path, bool]: + return (file, query in file.read_text()) + +def find_files_with_match(query: str, include_multisrc: bool = True) -> list[Path]: + files = Path("src").glob("*/*/build.gradle") + if include_multisrc: + files = itertools.chain(files, Path("lib-multisrc").glob("*/build.gradle.kts")) + + # Prevent bumping files twice. + files = filter(lambda file: file not in BUMPED_FILES, files) + + # Use multiple threads to find matches. + with ThreadPoolExecutor() as executor: + futures = [executor.submit(has_match, query, file) for file in files] + results = map(Future.result, as_completed(futures)) + return [path for path, result in results if result] + +def replace_version(match: re.Match) -> str: + version = int(match.group(1)) + print(f"{version} -> {version + 1}") + return f"{VERSION_STR} {version + 1}" + +def bump_version(file: Path): + BUMPED_FILES.append(file) + with file.open("r+") as f: + print(f"\n{file}: ", end="") + text = VERSION_REGEX.sub(replace_version, f.read()) + # Move the cursor to the start again, to prevent writing at the end + f.seek(0) + f.write(text) + +def bump_lib_multisrc(theme: str): + for file in find_files_with_match(f"themePkg = '{theme}'", include_multisrc=False): + bump_version(file) + +def commit_changes(): + paths = [str(path.resolve()) for path in BUMPED_FILES] + subprocess.check_call(["git", "config", "--local", "user.email", BOT_EMAIL]) + subprocess.check_call(["git", "config", "--local", "user.name", BOT_NAME]) + subprocess.check_call(["git", "add"] + paths) + subprocess.check_call(["git", "commit", "-S", "-m", "[skip ci] chore: Mass-bump on extensions"]) + subprocess.check_call(["git", "push"]) + +if __name__ == "__main__": + if len(sys.argv) > 1: + # Regex to match the lib name in the path, like "unpacker" or "dood-extractor". + lib_regex = re.compile(r"lib/([a-z0-9-]+)/") + # Find matches and remove None results. + matches = filter(None, map(lib_regex.search, sys.argv[1:])) + for match in matches: + project_path = ":lib:" + match.group(1) + for file in find_files_with_match(project_path): + if file.parent.parent.name == "lib-multisrc": + bump_lib_multisrc(file.parent.name) + else: + bump_version(file) + + if len(BUMPED_FILES) > 0: + commit_changes() diff --git a/.github/scripts/commit-repo.sh b/.github/scripts/commit-repo.sh new file mode 100644 index 00000000..240e7126 --- /dev/null +++ b/.github/scripts/commit-repo.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +rsync -a --delete --exclude .git --exclude .gitignore ../master/repo/ . +git config --global user.email "aniyomi-bot@aniyomi.org" +git config --global user.name "aniyomi-bot[bot]" +git status +if [ -n "$(git status --porcelain)" ]; then + git add . + git commit -S -m "Update extensions repo" + git push + + # Purge cached index on jsDelivr + curl https://purge.jsdelivr.net/gh/aniyomiorg/aniyomi-extensions@repo/index.min.json +else + echo "No changes to commit" +fi diff --git a/.github/scripts/create-repo.py b/.github/scripts/create-repo.py new file mode 100644 index 00000000..09c31c2c --- /dev/null +++ b/.github/scripts/create-repo.py @@ -0,0 +1,108 @@ +import json +import os +import re +import subprocess +from pathlib import Path +from zipfile import ZipFile + +PACKAGE_NAME_REGEX = re.compile(r"package: name='([^']+)'") +VERSION_CODE_REGEX = re.compile(r"versionCode='([^']+)'") +VERSION_NAME_REGEX = re.compile(r"versionName='([^']+)'") +IS_NSFW_REGEX = re.compile(r"'tachiyomi.animeextension.nsfw' value='([^']+)'") +APPLICATION_LABEL_REGEX = re.compile(r"^application-label:'([^']+)'", re.MULTILINE) +APPLICATION_ICON_320_REGEX = re.compile( + r"^application-icon-320:'([^']+)'", re.MULTILINE +) +LANGUAGE_REGEX = re.compile(r"aniyomi-([^\.]+)") + +*_, ANDROID_BUILD_TOOLS = (Path(os.environ["ANDROID_HOME"]) / "build-tools").iterdir() +REPO_DIR = Path("repo") +REPO_APK_DIR = REPO_DIR / "apk" +REPO_ICON_DIR = REPO_DIR / "icon" + +REPO_ICON_DIR.mkdir(parents=True, exist_ok=True) + +with open("output.json", encoding="utf-8") as f: + inspector_data = json.load(f) + +index_data = [] +index_min_data = [] + +for apk in REPO_APK_DIR.iterdir(): + badging = subprocess.check_output( + [ + ANDROID_BUILD_TOOLS / "aapt", + "dump", + "--include-meta-data", + "badging", + apk, + ] + ).decode() + + package_info = next(x for x in badging.splitlines() if x.startswith("package: ")) + package_name = PACKAGE_NAME_REGEX.search(package_info).group(1) + application_icon = APPLICATION_ICON_320_REGEX.search(badging).group(1) + + with ZipFile(apk) as z, z.open(application_icon) as i, ( + REPO_ICON_DIR / f"{package_name}.png" + ).open("wb") as f: + f.write(i.read()) + + language = LANGUAGE_REGEX.search(apk.name).group(1) + sources = inspector_data[package_name] + + if len(sources) == 1: + source_language = sources[0]["lang"] + + if ( + source_language != language + and source_language not in {"all", "other"} + and language not in {"all", "other"} + ): + language = source_language + + common_data = { + "name": APPLICATION_LABEL_REGEX.search(badging).group(1), + "pkg": package_name, + "apk": apk.name, + "lang": language, + "code": int(VERSION_CODE_REGEX.search(package_info).group(1)), + "version": VERSION_NAME_REGEX.search(package_info).group(1), + "nsfw": int(IS_NSFW_REGEX.search(badging).group(1)), + } + min_data = { + **common_data, + "sources": [], + } + + for source in sources: + min_data["sources"].append( + { + "name": source["name"], + "lang": source["lang"], + "id": source["id"], + "baseUrl": source["baseUrl"], + } + ) + + index_min_data.append(min_data) + index_data.append( + { + **common_data, + "hasReadme": 0, + "hasChangelog": 0, + "sources": sources, + } + ) + +index_data.sort(key=lambda x: x["pkg"]) +index_min_data.sort(key=lambda x: x["pkg"]) + +with (REPO_DIR / "index.json").open("w", encoding="utf-8") as f: + index_data_str = json.dumps(index_data, ensure_ascii=False, indent=2) + + print(index_data_str) + f.write(index_data_str) + +with (REPO_DIR / "index.min.json").open("w", encoding="utf-8") as f: + json.dump(index_min_data, f, ensure_ascii=False, separators=(",", ":")) diff --git a/.github/scripts/move-apks.py b/.github/scripts/move-apks.py new file mode 100644 index 00000000..b354a33a --- /dev/null +++ b/.github/scripts/move-apks.py @@ -0,0 +1,16 @@ +from pathlib import Path +import shutil + +REPO_APK_DIR = Path("repo/apk") + +try: + shutil.rmtree(REPO_APK_DIR) +except FileNotFoundError: + pass + +REPO_APK_DIR.mkdir(parents=True, exist_ok=True) + +for apk in (Path.home() / "apk-artifacts").glob("**/*.apk"): + apk_name = apk.name.replace("-release.apk", ".apk") + + shutil.move(apk, REPO_APK_DIR / apk_name) diff --git a/.github/scripts/sign-apks.sh b/.github/scripts/sign-apks.sh new file mode 100644 index 00000000..fa7a0ae7 --- /dev/null +++ b/.github/scripts/sign-apks.sh @@ -0,0 +1,52 @@ +#!/bin/bash +set -e + +TOOLS="$(ls -d ${ANDROID_HOME}/build-tools/* | tail -1)" + +shopt -s globstar nullglob extglob +APKS=( **/*".apk" ) + +# Fail if too little extensions seem to have been built +if [ "${#APKS[@]}" -le "50" ]; then + echo "Insufficient amount of APKs found. Please check the project configuration." + exit 1; +fi; + +# Take base64 encoded key input and put it into a file +STORE_PATH=$PWD/signingkey.jks +rm -f $STORE_PATH && touch $STORE_PATH +echo $1 | base64 -d > $STORE_PATH + +STORE_ALIAS=$2 +export KEY_STORE_PASSWORD=$3 +export KEY_PASSWORD=$4 + +DEST=$PWD/apk +rm -rf $DEST && mkdir -p $DEST + +MAX_PARALLEL=4 + +# Sign all of the APKs +for APK in ${APKS[@]}; do + ( + BASENAME=$(basename $APK) + APKNAME="${BASENAME%%+(-release*)}.apk" + APKDEST="$DEST/$APKNAME" + + ${TOOLS}/zipalign -c -v -p 4 $APK + + cp $APK $APKDEST + ${TOOLS}/apksigner sign --ks $STORE_PATH --ks-key-alias $STORE_ALIAS --ks-pass env:KEY_STORE_PASSWORD --key-pass env:KEY_PASSWORD $APKDEST + ) & + + # Allow to execute up to $MAX_PARALLEL jobs in parallel + if [[ $(jobs -r -p | wc -l) -ge $MAX_PARALLEL ]]; then + wait -n + fi +done + +wait + +rm $STORE_PATH +unset KEY_STORE_PASSWORD +unset KEY_PASSWORD diff --git a/.github/workflows/batch_close_issues.yml b/.github/workflows/batch_close_issues.yml new file mode 100644 index 00000000..2e5ac860 --- /dev/null +++ b/.github/workflows/batch_close_issues.yml @@ -0,0 +1,25 @@ +name: "Batch close stale issues" + +on: + # Monthly + schedule: + - cron: '0 0 1 * *' + # Manual trigger + workflow_dispatch: + inputs: + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + # Close everything older than ~6 months + days-before-issue-stale: 180 + days-before-issue-close: 0 + exempt-issue-labels: "do-not-autoclose,Meta request" + close-issue-message: "In an effort to have a more manageable issue backlog, we're closing older requests that weren't addressed since there's a low chance of it being addressed if it hasn't already. If your request is still relevant, please [open a new request](https://github.com/aniyomiorg/aniyomi-extensions/issues/new/choose)." + close-issue-reason: not_planned + ascending: true + operations-per-run: 250 diff --git a/.github/workflows/build_pull_request.yml b/.github/workflows/build_pull_request.yml new file mode 100644 index 00000000..3aaa544e --- /dev/null +++ b/.github/workflows/build_pull_request.yml @@ -0,0 +1,76 @@ +name: PR build check + +on: + pull_request: + paths: + - '**' + - '!**.md' + - '!.github/**' + - '.github/workflows/build_pull_request.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +env: + CI_CHUNK_SIZE: 65 + +jobs: + prepare: + name: Prepare job + runs-on: ubuntu-latest + outputs: + individualMatrix: ${{ steps.generate-matrices.outputs.individualMatrix }} + steps: + - name: Clone repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@a494d935f4b56874c4a5a87d19af7afcf3a163d0 # v2 + + - name: Get number of modules + run: | + set -x + projects=(src/*/*) + + echo "NUM_INDIVIDUAL_MODULES=${#projects[@]}" >> $GITHUB_ENV + + - id: generate-matrices + name: Create output matrices + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 + with: + script: | + const numIndividualModules = process.env.NUM_INDIVIDUAL_MODULES; + const chunkSize = process.env.CI_CHUNK_SIZE; + + const numIndividualChunks = Math.ceil(numIndividualModules / chunkSize); + + console.log(`Individual modules: ${numIndividualModules} (${numIndividualChunks} chunks of ${chunkSize})`); + + core.setOutput('individualMatrix', { 'chunk': [...Array(numIndividualChunks).keys()] }); + + build_individual: + name: Build individual modules + needs: prepare + runs-on: ubuntu-latest + strategy: + matrix: ${{ fromJSON(needs.prepare.outputs.individualMatrix) }} + steps: + - name: Checkout PR + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Set up JDK + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4 + with: + java-version: 17 + distribution: temurin + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3 + with: + cache-read-only: true + + - name: Build extensions (chunk ${{ matrix.chunk }}) + env: + CI_CHUNK_NUM: ${{ matrix.chunk }} + run: ./gradlew -p src assembleDebug diff --git a/.github/workflows/build_push.yml b/.github/workflows/build_push.yml new file mode 100644 index 00000000..59256092 --- /dev/null +++ b/.github/workflows/build_push.yml @@ -0,0 +1,178 @@ +name: CI + +on: + push: + branches: + - master + paths: + - '**' + - '!**.md' + - '!.github/**' + - '.github/scripts/**' + - '.github/workflows/build_push.yml' + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + +env: + CI_CHUNK_SIZE: 65 + +jobs: + prepare: + name: Prepare job + runs-on: ubuntu-latest + outputs: + individualMatrix: ${{ steps.generate-matrices.outputs.individualMatrix }} + steps: + - name: Clone repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + ref: master + token: ${{ secrets.ANIYOMIORG_BOT_PAT }} + + - name: Find lib changes + id: modified-libs + uses: tj-actions/changed-files@90a06d6ba9543371ab4df8eeca0be07ca6054959 #v42 + with: + files: lib/ + files_ignore: lib/**.md + files_separator: " " + safe_output: false + + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + + # This step is going to commit, but this will not trigger another workflow. + - name: Bump extensions that uses a modified lib + if: steps.modified-libs.outputs.any_changed == 'true' + run: | + ./.github/scripts/bump-versions.py ${{ steps.modified-libs.outputs.all_changed_files }} + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@a494d935f4b56874c4a5a87d19af7afcf3a163d0 # v2 + + - name: Get number of modules + run: | + set -x + projects=(src/*/*) + + echo "NUM_INDIVIDUAL_MODULES=${#projects[@]}" >> $GITHUB_ENV + + - id: generate-matrices + name: Create output matrices + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 + with: + script: | + const numIndividualModules = process.env.NUM_INDIVIDUAL_MODULES; + const chunkSize = process.env.CI_CHUNK_SIZE; + + const numIndividualChunks = Math.ceil(numIndividualModules / chunkSize); + + console.log(`Individual modules: ${numIndividualModules} (${numIndividualChunks} chunks of ${chunkSize})`); + + core.setOutput('individualMatrix', { 'chunk': [...Array(numIndividualChunks).keys()] }); + + build_individual: + name: Build individual modules + needs: prepare + runs-on: ubuntu-latest + strategy: + matrix: ${{ fromJSON(needs.prepare.outputs.individualMatrix) }} + steps: + - name: Checkout master branch + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + ref: master + + - name: Set up JDK + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4 + with: + java-version: 17 + distribution: temurin + + - name: Prepare signing key + run: | + echo ${{ secrets.SIGNING_KEY }} | base64 -d > signingkey.jks + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3 + + - name: Build extensions (chunk ${{ matrix.chunk }}) + env: + CI_CHUNK_NUM: ${{ matrix.chunk }} + ALIAS: ${{ secrets.ALIAS }} + KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + run: ./gradlew -p src assembleRelease + + - name: Upload APKs (chunk ${{ matrix.chunk }}) + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4 + if: "github.repository == 'aniyomiorg/aniyomi-extensions'" + with: + name: "individual-apks-${{ matrix.chunk }}" + path: "**/*.apk" + retention-days: 1 + + - name: Clean up CI files + run: rm signingkey.jks + + publish_repo: + name: Publish repo + needs: + - build_individual + if: "github.repository == 'aniyomiorg/aniyomi-extensions'" + runs-on: ubuntu-latest + steps: + - name: Download APK artifacts + uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4 + with: + path: ~/apk-artifacts + + - name: Set up JDK + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4 + with: + java-version: 17 + distribution: temurin + + - name: Checkout master branch + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + ref: master + path: master + + - name: Create repo artifacts + run: | + cd master + python ./.github/scripts/move-apks.py + INSPECTOR_LINK="$(curl -s "https://api.github.com/repos/aniyomiorg/aniyomi-extensions-inspector/releases/latest" | jq -r '.assets[0].browser_download_url')" + curl -L "$INSPECTOR_LINK" -o ./Inspector.jar + java -jar ./Inspector.jar "repo/apk" "output.json" "tmp" + python ./.github/scripts/create-repo.py + + - name: Checkout repo branch + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + repository: aniyomiorg/aniyomi-extensions + token: ${{ secrets.ANIYOMIORG_BOT_PAT }} + ref: repo + path: repo + + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + workdir: repo + + - name: Deploy repo + run: | + cd repo + ../master/.github/scripts/commit-repo.sh diff --git a/.github/workflows/issue_moderator.yml b/.github/workflows/issue_moderator.yml new file mode 100644 index 00000000..52695c98 --- /dev/null +++ b/.github/workflows/issue_moderator.yml @@ -0,0 +1,51 @@ +name: Issue moderator + +on: + issues: + types: [opened, edited, reopened] + issue_comment: + types: [created] + +jobs: + autoclose: + runs-on: ubuntu-latest + steps: + - name: Moderate issues + uses: aniyomiorg/issue-moderator-action@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + duplicate-label: Duplicate + + duplicate-check-enabled: true + duplicate-check-labels: | + ["Source request", "Domain changed"] + + existing-check-enabled: true + existing-check-labels: | + ["Source request", "Domain changed"] + + auto-close-rules: | + [ + { + "type": "body", + "regex": ".*DELETE THIS SECTION IF YOU HAVE READ AND ACKNOWLEDGED IT.*", + "message": "The acknowledgment section was not removed." + }, + { + "type": "body", + "regex": ".*\\* (Aniyomi version|Android version|Device): \\?.*", + "message": "Requested information in the template was not filled out." + }, + { + "type": "title", + "regex": ".*(Source name|Short description).*", + "message": "You did not fill out the description in the title." + }, + { + "type": "both", + "regex": ".*(?:fail(?:ed|ure|s)?|can\\s*(?:no|')?t|(?:not|un).*able|(?Steps + +1. Make sure to delete "repo" branch in your fork. You may also want to disable Actions in the repo settings. + + **Also make sure you are using the latest version of Git as many commands used here are pretty new.** + +2. Do a partial clone. + ```bash + git clone --filter=blob:none --sparse + cd aniyomi-extensions/ + ``` +3. Configure sparse checkout. + + There are two modes of pattern matching. The default is cone (🔺) mode. + Cone mode enables significantly faster pattern matching for big monorepos + and the sparse index feature to make Git commands more responsive. + In this mode, you can only filter by file path, which is less flexible + and might require more work when the project structure changes. + + You can skip this code block to use legacy mode if you want easier filters. + It won't be much slower as the repo doesn't have that many files. + + To enable cone mode together with sparse index, follow these steps: + + ```bash + git sparse-checkout set --cone --sparse-index + # add project folders + git sparse-checkout add .run buildSrc core gradle lib multisrc/src/main/java/generator + # add a single source + git sparse-checkout add src// + # add a multisrc theme + git sparse-checkout add multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/ + git sparse-checkout add multisrc/overrides/ + ``` + + To remove a source, open `.git/info/sparse-checkout` and delete the exact + lines you typed when adding it. Don't touch the other auto-generated lines + unless you fully understand how cone mode works, or you might break it. + + To use the legacy non-cone mode, follow these steps: + + ```bash + # enable sparse checkout + git sparse-checkout set --no-cone + # edit sparse checkout filter + vim .git/info/sparse-checkout + # alternatively, if you have VS Code installed + code .git/info/sparse-checkout + ``` + Here's an example: + ```bash + /* + !/src/* + !/multisrc/overrides/* + !/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/* + # allow a single source + /src// + # allow a multisrc theme + /multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/ + /multisrc/overrides/ + # or type the source name directly + + ``` + + Explanation: the rules are like `gitignore`. We first exclude all sources + while retaining project folders, then add the needed sources back manually. + +4. Configure remotes. + ```bash + # add upstream + git remote add upstream + # optionally disable push to upstream + git remote set-url --push upstream no_pushing + # ignore 'repo' branch of upstream + # option 1: use negative refspec + git config --add remote.upstream.fetch "^refs/heads/repo" + # option 2: fetch master only (ignore all other branches) + git config remote.upstream.fetch "+refs/heads/master:refs/remotes/upstream/master" + # update remotes + git remote update + # track master of upstream instead of fork + git branch master -u upstream/master + ``` +5. Useful configurations. (optional) + ```bash + # prune obsolete remote branches on fetch + git config remote.origin.prune true + # fast-forward only when pulling master branch + git config pull.ff only + # Add an alias to sync master branch without fetching useless blobs. + # If you run `git pull` to fast-forward in a blobless clone like this, + # all blobs (files) in the new commits are still fetched regardless of + # sparse rules, which makes the local repo accumulate unused files. + # Use `git sync-master` to avoid this. Be careful if you have changes + # on master branch, which is not a good practice. + git config alias.sync-master '!git switch master && git fetch upstream && git reset --keep FETCH_HEAD' + ``` +6. Later, if you change the sparse checkout filter, run `git sparse-checkout reapply`. + +Read more on +[Git's object model](https://github.blog/2020-12-17-commits-are-snapshots-not-diffs/), +[partial clone](https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/), +[sparse checkout](https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/), +[sparse index](https://github.blog/2021-11-10-make-your-monorepo-feel-small-with-gits-sparse-index/), +and [negative refspecs](https://github.blog/2020-10-19-git-2-29-released/#user-content-negative-refspecs). + + +## Getting help + +- Join [the Discord server](https://discord.gg/F32UjdJZrR) for online help and to ask questions while developing your extension. When doing so, please ask it in the `#dev` channel. + +- There are some features and tricks that are not explored in this document. Refer to existing extension code for examples. + +## Writing an extension + +The quickest way to get started is to copy an existing extension's folder structure and renaming it as needed. We also recommend reading through a few existing extensions' code before you start. + +### Setting up a new Gradle module + +Each extension should reside in `src//`. Use `all` as `` if your target source supports multiple languages or if it could support multiple sources. + +The `` used in the folder inside `src` should be the major `language` part. For example, if you will be creating a `pt-BR` source, use `` here as `pt` only. Inside the source class, use the full locale string instead. + +#### Extension file structure + +The simplest extension structure looks like this: + +```console +$ tree src/// +src/// +├── AndroidManifest.xml (optional) +├── build.gradle +├── build.gradle +├── res +│   ├── mipmap-hdpi +│   │   └── ic_launcher.png +│   ├── mipmap-mdpi +│   │   └── ic_launcher.png +│   ├── mipmap-xhdpi +│   │   └── ic_launcher.png +│   ├── mipmap-xxhdpi +│   │   └── ic_launcher.png +│   ├── mipmap-xxxhdpi +│   │   └── ic_launcher.png +│   └── web_hi_res_512.png +└── src + └── eu + └── kanade + └── tachiyomi + └── animeextension + └── + └── + └── .kt + +13 directories, 9 files +``` + +`` should be an ISO 639-1 compliant language code (two letters or `all`). `` +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..`. + +#### AndroidManifest.xml (optional) +You only need to create this file if you want to add deep linking to your extension. +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: + +```groovy +ext { + extName = '' + extClass = '.' + extVersionCode = 1 + isNsfw = true +} + +apply from: "$rootDir/common.gradle" +``` + +| Field | Description | +| ----- | ----------- | +| `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. | +| `isNsfw` | (Optional, defaults to `false`) Flag to indicate that a source contains NSFW content. | + +The extension's version name is generated automatically by concatenating `14` and `extVersionCode`. With the example used above, the version would be `14.1`. + +### Core dependencies + +#### Extension API + +Extensions rely on [extensions-lib](https://github.com/aniyomiorg/extensions-lib), which provides some interfaces and stubs from the [app](https://github.com/aniyomiorg/aniyomi) for compilation purposes. The actual implementations can be found [here](https://github.com/aniyomiorg/aniyomi/tree/master/app/src/main/java/eu/kanade/tachiyomi/animesource). Referencing the actual implementation will help with understanding extensions' call flow. + +#### CryptoAES library + +The [`cryptoaes`](https://github.com/aniyomiorg/aniyomi-extensions/tree/master/lib/cryptoaes) provides utilities for decrypting AES-encrypted data, like data encrypted with AES+EvpKDF (The key-derivation algorithm used by the [cryptojs](https://cryptojs.gitbook.io/docs/) library). It also includes some utilities to decrypt strings in the [jsfuck](https://jsfuck.com/) format. + +```groovy +dependencies { + implementation(project(":lib:cryptoaes")) +} +``` + +#### Unpacker library + +The [`unpacker`](https://github.com/aniyomiorg/aniyomi-extensions/tree/master/lib/unpacker) library provides a deobfuscator(unpacker) for javascript code obfuscated with the [jspacker](http://dean.edwards.name/packer/) algorithm. + +```groovy +dependencies { + implementation(project(":lib:unpacker")) +} +``` + +#### Synchrony library + +[`synchrony`](https://github.com/aniyomiorg/aniyomi-extensions/tree/master/lib/synchrony) is a library that bundles and runs the [synchrony](https://github.com/relative/synchrony) deobfuscator with your extension to help when deobfuscating obfuscated javascript. Useful to get data on highly obfuscated javascript code. + +```groovy +dependencies { + implementation(project(":lib:synchrony")) +} +``` + +#### Additional dependencies + +If you find yourself needing additional functionality, you can add more dependencies to your `build.gradle` file. +Many of [the dependencies](https://github.com/aniyomiorg/aniyomi/blob/master/app/build.gradle.kts) from the main Aniyomi app are exposed to extensions by default. + +> Note that several dependencies are already exposed to all extensions via Gradle version catalog. +> To view which are available view `libs.versions.toml` under the `gradle` folder + +Notice that we're using `compileOnly` instead of `implementation` if the app already contains it. You could use `implementation` instead for a new dependency, or you prefer not to rely on whatever the main app has at the expense of app size. + +Note that using `compileOnly` restricts you to versions that must be compatible with those used in [the latest stable version of Aniyomi](https://github.com/aniyomiorg/aniyomi/releases/latest). + +### Extension main class + +The class which is referenced and defined by `extClass` in `build.gradle`. This class should implement either `AnimeSourceFactory` or extend one of the `AnimeSource` implementations: `AnimeHttpSource` or `ParsedAnimeHttpSource`. + +| Class | Description | +| ----- | ----------- | +|`AnimeSourceFactory`| Used to expose multiple `AnimeSource`s. Use this in case of a source that supports multiple languages or mirrors of the same website. For similar websites use [theme sources](#multi-source-themes). | +| `AnimeHttpSource`| For online source, where requests are made using HTTP. | +| `ParsedAnimeHttpSource`| Similar to `AnimeHttpSource`, but has methods useful for scraping pages. | + +#### Main class key variables + +| Field | Description | +| ----- | ----------- | +| `name` | Name displayed in the "Sources" tab in Aniyomi. | +| `baseUrl` | Base URL of the source without any trailing slashes. | +| `lang` | An ISO 639-1 compliant language code (two letters in lower case in most cases, but can also include the country/dialect part by using a simple dash character). | +| `id` | Identifier of your source, automatically set in `AnimeHttpSource`. It should only be manually overriden if you need to copy an existing autogenerated ID. | + +### Extension call flow + +#### Popular Anime + +a.k.a. the Browse source entry point in the app (invoked by tapping on the source name). + +- The app calls `fetchPopularAnime` which should return a `AnimesPage` containing the first batch of found `SAnime` entries. + - This method supports pagination. When user scrolls the manga list and more results must be fetched, the app calls it again with increasing `page` values(starting with `page=1`). This continues while `AnimesPage.hasNextPage` is passed as `true` and `AnimesPage.mangas` is not empty. +- To show the list properly, the app needs `url`, `title` and `thumbnail_url`. You **must** set them here. The rest of the fields could be filled later.(refer to Anime Details below). + - You should set `thumbnail_url` if is available, if not, `fetchAnimeDetails` will be **immediately** called. (this will increase network calls heavily and should be avoided). + +#### Latest Anime + +a.k.a. the Latest source entry point in the app (invoked by tapping on the "Latest" button beside the source name). + +- Enabled if `supportsLatest` is `true` for a source +- Similar to popular anime, but should be fetching the latest entries from a source. + +#### Anime Search + +- When the user searches inside the app, `fetchSearchAnime` will be called and the rest of the flow is similar to what happens with `fetchPopularAnime`. + - If search functionality is not available, return `Observable.just(AnimesPage(emptyList(), false))` +- `getFilterList` will be called to get all filters and filter types. + +##### Filters + +The search flow have support to filters that can be added to a `AnimeFilterList` inside the `getFilterList` method. When the user changes the filter's state, they will be passed to the `searchAnimeRequest`, and they can be iterated to create the request (by getting the `filter.state` value, where the type varies depending on the `AnimeFilter` used). You can check the filter types available [here](https://github.com/aniyomiorg/aniyomi/blob/master/source-api/src/main/java/eu/kanade/tachiyomi/animesource/model/AnimeFilter.kt) and in the table below. + +| Filter | State type | Description | +| ------ | ---------- | ----------- | +| `AnimeFilter.Header` | None | A simple header. Useful for separating sections in the list or showing any note or warning to the user. | +| `AnimeFilter.Separator` | None | A line separator. Useful for visual distinction between sections. | +| `AnimeFilter.Select` | `Int` | A select control, similar to HTML's ``. | +| `AnimeFilter.CheckBox` | `Boolean` | A checkbox control, similar to HTML's ``. The state is `true` if it's checked. | +| `AnimeFilter.TriState` | `Int` | A enhanced checkbox control that supports an excluding state. The state can be compared with `STATE_IGNORE`, `STATE_INCLUDE` and `STATE_EXCLUDE` constants of the class. | +| `AnimeFilter.Group` | `List` | A group of filters (preferentially of the same type). The state will be a `List` with all the states. | +| `AnimeFilter.Sort` | `Selection` | A control for sorting, with support for the ordering. The state indicates which item index is selected and if the sorting is `ascending`. | + +All control filters can have a default state set. It's usually recommended if the source have filters to make the initial state match the popular anime list, so when the user open the filter sheet, the state is equal and represents the current anime showing. + +The `AnimeFilter` classes can also be extended, so you can create new custom filters like the `UriPartFilter`: + +```kotlin +open class UriPartFilter(displayName: String, private val vals: Array>) : + AnimeFilter.Select(displayName, vals.map { it.first }.toTypedArray()) { + fun toUriPart() = vals[state].second +} +``` + +#### Anime Details + +- When user taps on an anime, `fetchAnimeDetails` and `fetchEpisodeList` will be called and the results will be cached. + - A `SAnime` entry is identified by its `url`. +- `fetchAnimeDetails` is called to update an anime's details from when it was initialized earlier. + - `SAnime.initialized` tells the app if it should call `fetchAnimeDetails`. If you are overriding `fetchAnimeDetails`, make sure to pass it as `true`. + - `SAnime.genre` is a string containing list of all genres separated with `", "`. + - `SAnime.status` is an "enum" value. Refer to [the values in the `SAnime` companion object](https://github.com/aniyomiorg/extensions-lib/blob/main/library/src/main/java/eu/kanade/tachiyomi/animesource/model/SAnime.kt#L26-L32). + - During a backup, only `url` and `title` are stored. To restore the rest of the anime data, the app calls `fetchAnimeDetails`, so all fields should be (re)filled in if possible. + - If a `SAnime` is cached `fetchAnimeDetails` will be only called when the user does a manual update(Swipe-to-Refresh). +- `fetchEpisodeList` is called to display the episode list. + - **The list should be sorted descending by the source order**. + - If `Video.videoUrl`s are available immediately, you should pass them here. Otherwise, you should set `video.url` to a page that contains them and override `videoUrlParse` to fill those `videoUrl`s. + +#### Episode + +- After an episode list for the anime is fetched and the app is going to cache the data, `prepareNewEpisode` will be called. +- `SEpisode.date_upload` is the [UNIX Epoch time](https://en.wikipedia.org/wiki/Unix_time) **expressed in milliseconds**. + - If you don't pass `SEpisode.date_upload` and leave it zero, the app will use the default date instead, but it's recommended to always fill it if it's available. + - To get the time in milliseconds from a date string, you can use a `SimpleDateFormat` like in the example below. + + ```kotlin + private fun parseDate(dateStr: String): Long { + return runCatching { DATE_FORMATTER.parse(dateStr)?.time } + .getOrNull() ?: 0L + } + + companion object { + private val DATE_FORMATTER by lazy { + SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH) + } + } + ``` + + Make sure you make the `SimpleDateFormat` a class constant or variable so it doesn't get recreated for every episode. If you need to parse or format dates in anime description, create another instance since `SimpleDateFormat` is not thread-safe. + - If the parsing have any problem, make sure to return `0L` so the app will use the default date instead. + - The app will overwrite dates of existing old episodes **UNLESS** `0L` is returned. + - The default date has [changed](https://github.com/aniyomiorg/aniyomi/pull/7197) in Aniyomi preview ≥ r4442 or stable > 0.13.4. + - In older versions, the default date is always the fetch date. + - In newer versions, this is the same if every (new) episode has `0L` returned. + - However, if the source only provides the upload date of the latest episode, you can now set it to the latest episode and leave other episodes default. The app will automatically set it (instead of fetch date) to every new episode and leave old episodes' dates untouched. + +#### Episode Videos + +- When user opens an episode, `fetchVideoList` will be called and it will return a list of `Video`s that are used by the player. + +### Misc notes + +- 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). + +### Advanced Extension features + +#### URL intent filter + +Extensions can define URL intent filters by defining it inside a custom `AndroidManifest.xml` file. +For an example, refer to [the AniWatch module's `AndroidManifest.xml` file](https://github.com/aniyomiorg/aniyomi-extensions/blob/master/src/en/aniwatch/AndroidManifest.xml) and [its corresponding `AniWatchUrlActivity` handler](https://github.com/aniyomiorg/aniyomi-extensions/blob/master/src/en/aniwatch/src/eu/kanade/tachiyomi/animeextension/en/zoro/AniWatchUrlActivity.kt). + +To test if the URL intent filter is working as expected, you can try opening the website in a browser and navigating to the endpoint that was added as a filter or clicking a hyperlink. Alternatively, you can use the `adb` command below. + +```console +$ adb shell am start -d "" -a android.intent.action.VIEW +``` + +#### Renaming existing sources + +There is some cases where existing sources changes their name on the website. To correctly reflect these changes in the extension, you need to explicity set the `id` to the same old value, otherwise it will get changed by the new `name` value and users will be forced to migrate back to the source. + +To get the current `id` value before the name change, you can search the source name in the [repository JSON file](https://github.com/aniyomiorg/aniyomi-extensions/blob/repo/index.json) by looking into the `sources` attribute of the extension. When you have the `id` copied, you can override it in the source: + +```kotlin +override val id: Long = +``` + +Then the class name and the `name` attribute value can be changed. Also don't forget to update the extension name and class name in the individual Gradle file if it is not a multisrc extension. + +**Important:** the package name **needs** to be the same (even if it has the old name), otherwise users will not receive the extension update when it gets published in the repository. If you're changing the name of a multisrc source, you can manually set it in the generator class of the theme by using `pkgName = "oldpackagename"`. + +The `id` also needs to be explicity set to the old value if you're changing the `lang` attribute. + +## Multi-source themes +The `multisrc` module houses source code for generating extensions for cases where multiple source sites use the same site generator tool(usually a CMS) for bootstraping their website and this makes them similar enough to prompt code reuse through inheritance/composition; which from now on we will use the general **theme** term to refer to. + +This module contains the *default implementation* for each theme and definitions for each source that builds upon that default implementation and also it's overrides upon that default implementation, all of this becomes a set of source code which then is used to generate individual extensions from. + +### The directory structure +```console +$ tree multisrc +multisrc +├── build.gradle.kts +├── overrides +│   └── +│   ├── default +│   │   ├── additional.gradle +│   │   └── res +│   │   ├── mipmap-hdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-mdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-xhdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-xxhdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-xxxhdpi +│   │   │   └── ic_launcher.png +│   │   └── web_hi_res_512.png +│   └── +│   ├── additional.gradle +│   ├── AndroidManifest.xml +│   ├── res +│   │   ├── mipmap-hdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-mdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-xhdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-xxhdpi +│   │   │   └── ic_launcher.png +│   │   ├── mipmap-xxxhdpi +│   │   │   └── ic_launcher.png +│   │   └── web_hi_res_512.png +│   └── src +│   └── .kt +└── src + └── main + ├── AndroidManifest.xml + └── java + ├── eu + │   └── kanade + │   └── tachiyomi + │   └── multisrc + │   └── + │   ├── Generator.kt + │   └── .kt + └── generator + ├── GeneratorMain.kt + ├── IntelijConfigurationGeneratorMain.kt + └── ThemeSourceGenerator.kt +``` + +- `multisrc/src/main/java/eu/kanade/tachiyomi/multisrc//.kt` defines the the theme's default implementation. +- `multisrc/src/main/java/eu/kanade/tachiyomi/multisrc//Generator.kt` defines the the theme's generator class, this is similar to a `AnimeSourceFactory` class. +- `multisrc/overrides//default/res` is the theme's default icons, if a source doesn't have overrides for `res`, then default icons will be used. +- `multisrc/overrides//default/additional.gradle` defines additional gradle code, this will be copied at the end of all generated sources from this theme. +- `multisrc/overrides//` contains overrides for a source that is defined inside the `Generator.kt` class. +- `multisrc/overrides///src` contains source overrides. +- `multisrc/overrides///res` contains override for icons. +- `multisrc/overrides///additional.gradle` defines additional gradle code, this will be copied at the end of the generated gradle file below the theme's `additional.gradle`. +- `multisrc/overrides///AndroidManifest.xml` is copied as an override to the default `AndroidManifest.xml` generation if it exists. + +> **Note** +> +> Files ending with `Gen.kt` (i.e. `multisrc/src/main/java/eu/kanade/tachiyomi/multisrc//XxxGen.kt`) +> are considered helper files and won't be copied to generated sources. + +### Development workflow +There are three steps in running and testing a theme source: + +1. Generate the sources + - **Option 1: Only generate sources from one theme** + - **Method 1:** Find and run `Generator` run configuration form the `Run/Debug Configuration` menu. + - **Method 2:** Directly run `.Generator.main` by pressing the play button in front of the method shown inside Android Studio's Code Editor to generate sources from the said theme. + - **Option 2: Generate sources from all themes** + - **Method 1:** Run `./gradlew multisrc:generateExtensions` from a terminal window to generate all sources. + - **Method 2:** Directly run `Generator.GeneratorMain.main` by pressing the play button in front of the method shown inside Android Studio's Code Editor to generate all sources. +2. Sync gradle to import the new generated sources inside `generated-src` + - **Method 1:** Android Studio might prompt to sync the gradle. Click on `Sync Now`. + - **Method 2:** Manually re-sync by opening `File` -> `Sync Project with Gradle Files` or by pressing `Alt+f` then `g`. +3. Build and test the generated Extention like normal `src` sources. + - It's recommended to make changes here to skip going through step 1 and 2 multiple times, and when you are done, copying the changes back to `multisrc`. + +### Scaffolding overrides +You can use this python script to generate scaffolds for source overrides. Put it inside `multisrc/overrides//` as `scaffold.py`. +```python +import os, sys +from pathlib import Path + +theme = Path(os.getcwd()).parts[-1] + +print(f"Detected theme: {theme}") + +if len(sys.argv) < 3: + print("Must be called with a class name and lang, for Example 'python scaffold.py LeviatanScans en'") + exit(-1) + +source = sys.argv[1] +package = source.lower() +lang = sys.argv[2] + +print(f"working on {source} with lang {lang}") + +os.makedirs(f"{package}/src") +os.makedirs(f"{package}/res") + +with open(f"{package}/src/{source}.kt", "w") as f: + f.write(f"package eu.kanade.tachiyomi.animeextension.{lang}.{package}\n\n") +``` + +### Additional Notes +- Generated sources extension version code is calculated as `baseVersionCode + overrideVersionCode + multisrcLibraryVersion`. + - Currently `multisrcLibraryVersion` is `0` + - When a new source is added, it doesn't need to set `overrideVersionCode` as it's default is `0`. + - For each time a source changes in a way that should the version increase, `overrideVersionCode` should be increased by one. + - When a theme's default implementation changes, `baseVersionCode` should be increased, the initial value should be `1`. + - For example, for a new theme with a new source, extention version code will be `0 + 0 + 1 = 1`. +- `IntelijConfigurationGeneratorMainKt` should be run on creating or removing a multisrc theme. + - On removing a theme, you can manually remove the corresponding configuration in the `.run` folder instead. + - Be careful if you're using sparse checkout. If other configurations are accidentally removed, `git add` the file you want and `git restore` the others. Another choice is to allow `/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/*` before running the generator. + +## Running + +To make local development more convenient, you can use the following run configuration to launch Aniyomi directly at the Browse panel: + +![](https://i.imgur.com/STy0UFY.png) + +If you're running a Preview or debug build of Aniyomi: + +``` +-W -S -n xyz.jmir.tachiyomi.mi.debug/eu.kanade.tachiyomi.ui.main.MainActivity -a eu.kanade.tachiyomi.SHOW_CATALOGUES +``` + +And for a release build of Aniyomi: + +``` +-W -S -n xyz.jmir.tachiyomi.mi/eu.kanade.tachiyomi.ui.main.MainActivity -a eu.kanade.tachiyomi.SHOW_CATALOGUES +``` + +If you're deploying to Android 11 or higher, enable the "Always install with package manager" option in the run configurations. + +## Debugging + +### Android Debugger + +You can leverage the Android Debugger to step through your extension while debugging. + +You *cannot* simply use Android Studio's `Debug 'module.name'` -> this will most likely result in an error while launching. + +Instead, once you've built and installed your extension on the target device, use `Attach Debugger to Android Process` to start debugging Aniyomi. + +![](https://i.imgur.com/muhXyfu.png) + + +### Logs + +You can also elect to simply rely on logs printed from your extension, which +show up in the [`Logcat`](https://developer.android.com/studio/debug/am-logcat) panel of Android Studio. + +### Inspecting network calls +One of the easiest way to inspect network issues (such as HTTP errors 404, 429, no chapter found etc.) is to use the [`Logcat`](https://developer.android.com/studio/debug/am-logcat) panel of Android Studio and filtering by the `OkHttpClient` tag. + +To be able to check the calls done by OkHttp, you need to enable verbose logging in the app, that is not enabled by default and is only included in the Preview versions of Aniyomi. To enable it, go to More -> Settings -> Advanced -> Verbose logging. After enabling it, don't forget to restart the app. + +Inspecting the Logcat allows you to get a good look at the call flow and it's more than enough in most cases where issues occurs. However, alternatively, you can also use an external tool like `mitm-proxy`. For that, refer to the next section. + +### Using external network inspecting tools +If you want to take a deeper look into the network flow, such as taking a look into the request and response bodies, you can use an external tool like `mitm-proxy`. + +#### Setup your proxy server +We are going to use [mitm-proxy](https://mitmproxy.org/) but you can replace it with any other Web Debugger (i.e. Charles, Burp Suite, Fiddler etc). To install and execute, follow the commands bellow. + +```console +Install the tool. +$ sudo pip3 install mitmproxy +Execute the web interface and the proxy. +$ mitmweb +``` + +Alternatively, you can also use the Docker image: + +``` +$ docker run --rm -it -p 8080:8080 \ + -p 127.0.0.1:8081:8081 \ + --web-host 0.0.0.0 \ + mitmproxy/mitmproxy mitmweb +``` + +After installing and running, open your browser and navigate to http://127.0.0.1:8081. + +#### OkHttp proxy setup +Since most of the manga sources are going to use HTTPS, we need to disable SSL verification in order to use the web debugger. For that, add this code to inside your source class: + +```kotlin +package eu.kanade.tachiyomi.animeextension.en.animesource + +import android.annotation.SuppressLint +import eu.kanade.tachiyomi.multisrc.animetheme.AnimeTheme +import okhttp3.OkHttpClient +import java.net.InetSocketAddress +import java.net.Proxy +import java.security.SecureRandom +import java.security.cert.X509Certificate +import javax.net.ssl.SSLContext +import javax.net.ssl.TrustManager +import javax.net.ssl.X509TrustManager + +class AnimeSource : AnimeTheme( + "AnimeSource", + "https://example.com", + "en" +) { + private fun OkHttpClient.Builder.ignoreAllSSLErrors(): OkHttpClient.Builder { + val naiveTrustManager = @SuppressLint("CustomX509TrustManager") + object : X509TrustManager { + override fun getAcceptedIssuers(): Array = emptyArray() + override fun checkClientTrusted(certs: Array, authType: String) = Unit + override fun checkServerTrusted(certs: Array, authType: String) = Unit + } + + val insecureSocketFactory = SSLContext.getInstance("TLSv1.2").apply { + val trustAllCerts = arrayOf(naiveTrustManager) + init(null, trustAllCerts, SecureRandom()) + }.socketFactory + + sslSocketFactory(insecureSocketFactory, naiveTrustManager) + hostnameVerifier { _, _ -> true } + return this + } + + override val client: OkHttpClient = network.client.newBuilder() + .ignoreAllSSLErrors() + .proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress("10.0.2.2", 8080))) + .build() +} +``` + +Note: `10.0.2.2` is usually the address of your loopback interface in the android emulator. If Aniyomi tells you that it's unable to connect to 10.0.2.2:8080 you will likely need to change it (the same if you are using hardware device). + +If all went well, you should see all requests and responses made by the source in the web interface of `mitmweb`. + +## Building + +APKs can be created in Android Studio via `Build > Build Bundle(s) / APK(s) > Build APK(s)` or `Build > Generate Signed Bundle / APK`. + +## Submitting the changes + +When you feel confident about your changes, submit a new Pull Request so your code can be reviewed and merged if it's approved. We encourage following a [GitHub Standard Fork & Pull Request Workflow](https://gist.github.com/Chaser324/ce0505fbed06b947d962) and following the good practices of the workflow, such as not commiting directly to `master`: always create a new branch for your changes. + +If you are more comfortable about using Git GUI-based tools, you can refer to [this guide](https://learntodroid.com/how-to-use-git-and-github-in-android-studio/) about the Git integration inside Android Studio, specifically the "How to Contribute to an to Existing Git Repository in Android Studio" section of the guide. + +Please **do test your changes by compiling it through Android Studio** before submitting it. Also make sure to follow the PR checklist available in the PR body field when creating a new PR. As a reference, you can find it below. + +### Pull Request checklist + +- Update `extVersionCode` value in `build.gradle` for individual extensions +- Update `overrideVersionCode` or `baseVersionCode` as needed for all multisrc extensions +- Reference all related issues in the PR body (e.g. "Closes #xyz") +- Add the `isNsfw = true` flag in `build.gradle` when appropriate +- Explicitly kept the `id` if a source's name or language were changed +- Test the modifications by compiling and running the extension through Android Studio diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8f71f43f --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/README.md b/README.md new file mode 100644 index 00000000..dff9521d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# aniyomi-extensions + extension source diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..98a6d7a5 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,21 @@ +buildscript { + repositories { + mavenCentral() + google() + maven(url = "https://plugins.gradle.org/m2/") + } + dependencies { + classpath(libs.gradle.agp) + classpath(libs.gradle.kotlin) + classpath(libs.gradle.kotlin.serialization) + classpath(libs.gradle.kotlinter) + } +} + +allprojects { + tasks.withType().configureEach { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..21d0f6cc --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation(libs.gradle.agp) + implementation(libs.gradle.kotlin) + implementation(libs.gradle.kotlin.serialization) + implementation(libs.gradle.kotlinter) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 00000000..b7e30c8e --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,9 @@ +apply(from = "../repositories.gradle.kts") + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/AndroidConfig.kt b/buildSrc/src/main/kotlin/AndroidConfig.kt new file mode 100644 index 00000000..5e3f111b --- /dev/null +++ b/buildSrc/src/main/kotlin/AndroidConfig.kt @@ -0,0 +1,8 @@ +object AndroidConfig { + const val compileSdk = 32 + const val minSdk = 21 + const val targetSdk = 32 + const val namespace = "eu.kanade.tachiyomi.animeextension" + const val coreNamespace = "eu.kanade.tachiyomi.lib.core" + const val multisrcNamespace = "eu.kanade.tachiyomi.lib.themesources" +} diff --git a/buildSrc/src/main/kotlin/Extensions.kt b/buildSrc/src/main/kotlin/Extensions.kt new file mode 100644 index 00000000..12eff37a --- /dev/null +++ b/buildSrc/src/main/kotlin/Extensions.kt @@ -0,0 +1,6 @@ +import org.gradle.api.plugins.ExtensionAware +import org.gradle.kotlin.dsl.extra + +var ExtensionAware.baseVersionCode: Int + get() = extra.get("baseVersionCode") as Int + set(value) = extra.set("baseVersionCode", value) diff --git a/buildSrc/src/main/kotlin/lib-android.gradle.kts b/buildSrc/src/main/kotlin/lib-android.gradle.kts new file mode 100644 index 00000000..2d9eebc6 --- /dev/null +++ b/buildSrc/src/main/kotlin/lib-android.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("com.android.library") + kotlin("android") + id("kotlinx-serialization") +} + +android { + compileSdk = AndroidConfig.compileSdk + + defaultConfig { + minSdk = AndroidConfig.minSdk + } + + namespace = "eu.kanade.tachiyomi.lib.${name.replace("-", "")}" +} + +versionCatalogs + .named("libs") + .findBundle("common") + .ifPresent { common -> + dependencies { + compileOnly(common) + } + } diff --git a/buildSrc/src/main/kotlin/lib-kotlin.gradle.kts b/buildSrc/src/main/kotlin/lib-kotlin.gradle.kts new file mode 100644 index 00000000..f800de6e --- /dev/null +++ b/buildSrc/src/main/kotlin/lib-kotlin.gradle.kts @@ -0,0 +1,13 @@ +plugins { + `java-library` + kotlin("jvm") +} + +versionCatalogs + .named("libs") + .findLibrary("kotlin-stdlib") + .ifPresent { stdlib -> + dependencies { + compileOnly(stdlib) + } + } diff --git a/buildSrc/src/main/kotlin/lib-multisrc.gradle.kts b/buildSrc/src/main/kotlin/lib-multisrc.gradle.kts new file mode 100644 index 00000000..57e86f95 --- /dev/null +++ b/buildSrc/src/main/kotlin/lib-multisrc.gradle.kts @@ -0,0 +1,55 @@ +plugins { + id("com.android.library") + kotlin("android") + id("kotlinx-serialization") + id("org.jmailen.kotlinter") +} + +android { + compileSdk = AndroidConfig.compileSdk + + defaultConfig { + minSdk = AndroidConfig.minSdk + } + + namespace = "eu.kanade.tachiyomi.multisrc.${project.name}" + + sourceSets { + named("main") { + manifest.srcFile("AndroidManifest.xml") + java.setSrcDirs(listOf("src")) + res.setSrcDirs(listOf("res")) + assets.setSrcDirs(listOf("assets")) + } + } + + buildFeatures { + resValues = false + shaders = false + } + + kotlinOptions { + freeCompilerArgs += "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" + } +} + +versionCatalogs + .named("libs") + .findBundle("common") + .ifPresent { common -> + dependencies { + compileOnly(common) + } + } + +tasks { + preBuild { + dependsOn(lintKotlin) + } + + if (System.getenv("CI") != "true") { + lintKotlin { + dependsOn(formatKotlin) + } + } +} diff --git a/common.gradle b/common.gradle new file mode 100644 index 00000000..fa09e223 --- /dev/null +++ b/common.gradle @@ -0,0 +1,133 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlinx-serialization' +apply plugin: 'org.jmailen.kotlinter' + +assert !ext.has("pkgNameSuffix") +assert !ext.has("libVersion") + +assert extName.chars().max().asInt < 0x180 : "Extension name should be romanized" + +Project theme = ext.has("themePkg") ? project(":lib-multisrc:$themePkg") : null +if (theme != null) evaluationDependsOn(theme.path) + +android { + compileSdkVersion AndroidConfig.compileSdk + namespace AndroidConfig.namespace + + sourceSets { + main { + manifest.srcFile "AndroidManifest.xml" + java.srcDirs = ['src'] + res.srcDirs = ['res'] + } + release { + manifest.srcFile "AndroidManifest.xml" + } + debug { + manifest.srcFile "AndroidManifest.xml" + } + } + + defaultConfig { + minSdkVersion AndroidConfig.minSdk + targetSdkVersion AndroidConfig.targetSdk + applicationIdSuffix project.parent.name + "." + project.name + versionCode theme == null ? extVersionCode : theme.baseVersionCode + overrideVersionCode + versionName "14.$versionCode" + base { + archivesName = "aniyomi-$applicationIdSuffix-v$versionName" + } + assert extClass.startsWith(".") + manifestPlaceholders = [ + appName : "Aniyomi: $extName", + extClass: extClass, + nsfw : project.ext.find("isNsfw") ? 1 : 0, + ] + String baseUrl = project.ext.find("baseUrl") ?: "" + if (theme != null && !baseUrl.isEmpty()) { + def split = baseUrl.split("://") + assert split.length == 2 + def path = split[1].split("/") + manifestPlaceholders += [ + SOURCEHOST : path[0], + SOURCESCHEME: split[0], + ] + } + + } + + signingConfigs { + release { + storeFile rootProject.file("signingkey.jks") + storePassword System.getenv("KEY_STORE_PASSWORD") + keyAlias System.getenv("ALIAS") + keyPassword System.getenv("KEY_PASSWORD") + } + } + + buildTypes { + release { + signingConfig signingConfigs.release + minifyEnabled false + } + } + + dependenciesInfo { + includeInApk = false + } + + buildFeatures { + // Disable unused AGP features + aidl false + renderScript false + resValues false + shaders false + buildConfig true + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + freeCompilerArgs += "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" + } +} + +dependencies { + if (theme != null) implementation(theme) // Overrides core launcher icons + implementation(project(":core")) + compileOnly(libs.bundles.common) +} + +configurations.all { + resolutionStrategy.eachDependency { DependencyResolveDetails details -> + if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name == 'kotlin-stdlib-jdk8' && details.requested.version == '1.7.0') { + details.useVersion(libs.versions.kotlin.version.get()) + details.because 'Fix problems with dev.datlag JsUnpacker' + } + } +} + +tasks.register("writeManifestFile") { + doLast { + def manifest = android.sourceSets.getByName("main").manifest + if (!manifest.srcFile.exists()) { + File tempFile = layout.buildDirectory.get().file("tempAndroidManifest.xml").getAsFile() + if (!tempFile.exists()) { + tempFile.withWriter { + it.write('\n\n') + } + } + manifest.srcFile(tempFile.path) + } + } +} + +preBuild.dependsOn(writeManifestFile, lintKotlin) +if (System.getenv("CI") != "true") { + lintKotlin.dependsOn(formatKotlin) +} diff --git a/core/AndroidManifest.xml b/core/AndroidManifest.xml new file mode 100644 index 00000000..6972ec62 --- /dev/null +++ b/core/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 00000000..dcd5b361 --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + id("com.android.library") +} + +android { + compileSdk = AndroidConfig.compileSdk + namespace = AndroidConfig.coreNamespace + + defaultConfig { + minSdk = AndroidConfig.minSdk + } + + sourceSets { + named("main") { + manifest.srcFile("AndroidManifest.xml") + res.setSrcDirs(listOf("res")) + } + } + + libraryVariants.all { + generateBuildConfigProvider?.configure { + enabled = false + } + } +} diff --git a/core/res/mipmap-hdpi/ic_launcher.png b/core/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..3e78412b Binary files /dev/null and b/core/res/mipmap-hdpi/ic_launcher.png differ diff --git a/core/res/mipmap-mdpi/ic_launcher.png b/core/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..88037fe1 Binary files /dev/null and b/core/res/mipmap-mdpi/ic_launcher.png differ diff --git a/core/res/mipmap-xhdpi/ic_launcher.png b/core/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..554324ed Binary files /dev/null and b/core/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/core/res/mipmap-xxhdpi/ic_launcher.png b/core/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..99590ff9 Binary files /dev/null and b/core/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/core/res/mipmap-xxxhdpi/ic_launcher.png b/core/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..9ddcbc02 Binary files /dev/null and b/core/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..022f4950 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,25 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx5120m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +org.gradle.parallel=true +org.gradle.workers.max=5 + +org.gradle.caching=true + +# Enable AndroidX dependencies +android.useAndroidX=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..e51cd920 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,29 @@ +[versions] +agp_version = "8.2.1" +coroutines_version = "1.7.1" +kotlin_version = "1.8.22" +serialization_version = "1.5.1" + +[libraries] +gradle-agp = { module = "com.android.tools.build:gradle", version.ref = "agp_version" } +gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin_version" } +gradle-kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin_version" } +gradle-kotlinter = { module = "org.jmailen.gradle:kotlinter-gradle", version = "3.15.0" } + +aniyomi-lib = { module = "com.github.aniyomiorg:extensions-lib", version = "14" } + +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin_version" } +kotlin-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "serialization_version" } +kotlin-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization_version" } + +coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines_version" } +coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines_version" } + +injekt-core = { module = "com.github.inorichi.injekt:injekt-core", version = "65b0440" } +rxjava = { module = "io.reactivex:rxjava", version = "1.3.8" } +jsoup = { module = "org.jsoup:jsoup", version = "1.16.1" } +okhttp = { module = "com.squareup.okhttp3:okhttp", version = "5.0.0-alpha.11" } +quickjs = { module = "app.cash.quickjs:quickjs-android", version = "0.9.2" } + +[bundles] +common = ["kotlin-stdlib", "injekt-core", "rxjava", "kotlin-protobuf", "kotlin-json", "jsoup", "okhttp", "aniyomi-lib", "quickjs", "coroutines-core", "coroutines-android"] diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..d64cd491 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..1af9e093 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 00000000..1aa94a42 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# 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 + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + 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=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=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +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, 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" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..93e3f59f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/ktlintCodeStyle.xml b/ktlintCodeStyle.xml new file mode 100644 index 00000000..e1422c7c --- /dev/null +++ b/ktlintCodeStyle.xml @@ -0,0 +1,136 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+ + +
\ No newline at end of file diff --git a/lib-multisrc/animestream/AndroidManifest.xml b/lib-multisrc/animestream/AndroidManifest.xml new file mode 100644 index 00000000..15e586eb --- /dev/null +++ b/lib-multisrc/animestream/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/lib-multisrc/animestream/build.gradle.kts b/lib-multisrc/animestream/build.gradle.kts new file mode 100644 index 00000000..5e2a19a1 --- /dev/null +++ b/lib-multisrc/animestream/build.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("lib-multisrc") +} + +baseVersionCode = 2 \ No newline at end of file diff --git a/lib-multisrc/animestream/src/eu/kanade/tachiyomi/multisrc/animestream/AnimeStream.kt b/lib-multisrc/animestream/src/eu/kanade/tachiyomi/multisrc/animestream/AnimeStream.kt new file mode 100644 index 00000000..fbd2a189 --- /dev/null +++ b/lib-multisrc/animestream/src/eu/kanade/tachiyomi/multisrc/animestream/AnimeStream.kt @@ -0,0 +1,431 @@ +package eu.kanade.tachiyomi.multisrc.animestream + +import android.app.Application +import android.util.Base64 +import android.util.Log +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource +import eu.kanade.tachiyomi.animesource.model.AnimeFilter +import eu.kanade.tachiyomi.animesource.model.AnimeFilterList +import eu.kanade.tachiyomi.animesource.model.AnimesPage +import eu.kanade.tachiyomi.animesource.model.SAnime +import eu.kanade.tachiyomi.animesource.model.SEpisode +import eu.kanade.tachiyomi.animesource.model.Video +import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.GenresFilter +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.OrderFilter +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.SeasonFilter +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.StatusFilter +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.StudioFilter +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.SubFilter +import eu.kanade.tachiyomi.multisrc.animestream.AnimeStreamFilters.TypeFilter +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.awaitSuccess +import eu.kanade.tachiyomi.util.asJsoup +import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.Request +import okhttp3.Response +import org.jsoup.Jsoup +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get +import java.text.SimpleDateFormat +import java.util.Locale + +abstract class AnimeStream( + override val lang: String, + override val name: String, + override val baseUrl: String, +) : ConfigurableAnimeSource, ParsedAnimeHttpSource() { + + override val supportsLatest = true + + protected open val preferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + + companion object { + const val PREFIX_SEARCH = "path:" + } + + protected open val prefQualityDefault = "720p" + protected open val prefQualityKey = "preferred_quality" + protected open val prefQualityTitle = when (lang) { + "pt-BR" -> "Qualidade preferida" + else -> "Preferred quality" + } + protected open val prefQualityValues = arrayOf("1080p", "720p", "480p", "360p") + protected open val prefQualityEntries = prefQualityValues + + protected open val videoSortPrefKey = prefQualityKey + protected open val videoSortPrefDefault = prefQualityDefault + + protected open val dateFormatter by lazy { + val locale = when (lang) { + "pt-BR" -> Locale("pt", "BR") + else -> Locale.ENGLISH + } + SimpleDateFormat("MMMM d, yyyy", locale) + } + + protected open val animeListUrl = "$baseUrl/anime" + + // ============================== Popular =============================== + override suspend fun getPopularAnime(page: Int): AnimesPage { + fetchFilterList() + return super.getPopularAnime(page) + } + + override fun popularAnimeRequest(page: Int) = GET("$animeListUrl/?page=$page&order=popular") + + override fun popularAnimeSelector() = searchAnimeSelector() + + override fun popularAnimeFromElement(element: Element) = searchAnimeFromElement(element) + + override fun popularAnimeNextPageSelector(): String? = searchAnimeNextPageSelector() + + // =============================== Latest =============================== + override suspend fun getLatestUpdates(page: Int): AnimesPage { + fetchFilterList() + return super.getLatestUpdates(page) + } + + override fun latestUpdatesRequest(page: Int) = GET("$animeListUrl/?page=$page&order=update") + + override fun latestUpdatesSelector() = searchAnimeSelector() + + override fun latestUpdatesFromElement(element: Element) = searchAnimeFromElement(element) + + override fun latestUpdatesNextPageSelector(): String? = searchAnimeNextPageSelector() + + // =============================== Search =============================== + override suspend fun getSearchAnime(page: Int, query: String, filters: AnimeFilterList): AnimesPage { + return if (query.startsWith(PREFIX_SEARCH)) { // URL intent handler + val path = query.removePrefix(PREFIX_SEARCH) + client.newCall(GET("$baseUrl/$path")) + .awaitSuccess() + .use(::searchAnimeByPathParse) + } else { + super.getSearchAnime(page, query, filters) + } + } + + protected open fun searchAnimeByPathParse(response: Response): AnimesPage { + val details = animeDetailsParse(response.asJsoup()) + return AnimesPage(listOf(details), false) + } + + override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request { + val params = AnimeStreamFilters.getSearchParameters(filters) + return if (query.isNotEmpty()) { + GET("$baseUrl/page/$page/?s=$query") + } else { + val multiString = buildString { + if (params.genres.isNotEmpty()) append(params.genres + "&") + if (params.seasons.isNotEmpty()) append(params.seasons + "&") + if (params.studios.isNotEmpty()) append(params.studios + "&") + } + + GET("$animeListUrl/?page=$page&$multiString&status=${params.status}&type=${params.type}&sub=${params.sub}&order=${params.order}") + } + } + + override fun searchAnimeSelector() = "div.listupd article a.tip" + + override fun searchAnimeFromElement(element: Element): SAnime { + return SAnime.create().apply { + setUrlWithoutDomain(element.attr("abs:href")) + title = element.selectFirst("div.tt, div.ttl")!!.ownText() + thumbnail_url = element.selectFirst("img")?.getImageUrl() + } + } + + override fun searchAnimeNextPageSelector(): String? = "div.pagination a.next, div.hpage > a.r" + + // ============================== Filters =============================== + + /** + * Disable it if you don't want the filters to be automatically fetched. + */ + protected open val fetchFilters = true + + protected open val filtersSelector = "span.sec1 > div.filter > ul" + + private fun fetchFilterList() { + if (fetchFilters && !AnimeStreamFilters.filterInitialized()) { + AnimeStreamFilters.filterElements = runBlocking { + withContext(Dispatchers.IO) { + client.newCall(GET(animeListUrl)).execute() + .asJsoup() + .select(filtersSelector) + } + } + } + } + + protected open val filtersHeader = when (lang) { + "pt-BR" -> "NOTA: Filtros serão ignorados se usar a pesquisa por nome!" + else -> "NOTE: Filters are going to be ignored if using search text!" + } + + protected open val filtersMissingWarning: String = when (lang) { + "pt-BR" -> "Aperte 'Redefinir' para tentar mostrar os filtros" + else -> "Press 'Reset' to attempt to show the filters" + } + + protected open val genresFilterText = when (lang) { + "pt-BR" -> "Gêneros" + else -> "Genres" + } + + protected open val seasonsFilterText = when (lang) { + "pt-BR" -> "Temporadas" + else -> "Seasons" + } + + protected open val studioFilterText = when (lang) { + "pt-BR" -> "Estúdios" + else -> "Studios" + } + + protected open val statusFilterText = "Status" + + protected open val typeFilterText = when (lang) { + "pt-BR" -> "Tipo" + else -> "Type" + } + + protected open val subFilterText = when (lang) { + "pt-BR" -> "Legenda" + else -> "Subtitle" + } + + protected open val orderFilterText = when (lang) { + "pt-BR" -> "Ordem" + else -> "Order" + } + + override fun getFilterList(): AnimeFilterList { + return if (fetchFilters && AnimeStreamFilters.filterInitialized()) { + AnimeFilterList( + GenresFilter(genresFilterText), + SeasonFilter(seasonsFilterText), + StudioFilter(studioFilterText), + AnimeFilter.Separator(), + StatusFilter(statusFilterText), + TypeFilter(typeFilterText), + SubFilter(subFilterText), + OrderFilter(orderFilterText), + ) + } else if (fetchFilters) { + AnimeFilterList(AnimeFilter.Header(filtersMissingWarning)) + } else { + AnimeFilterList() + } + } + + // =========================== Anime Details ============================ + protected open val animeDetailsSelector = "div.info-content, div.right ul.data" + protected open val animeAltNameSelector = ".alter" + protected open val animeTitleSelector = "h1.entry-title" + protected open val animeThumbnailSelector = "div.thumb > img, div.limage > img" + protected open val animeGenresSelector = "div.genxed > a, li:contains(Genre:) a" + protected open val animeDescriptionSelector = ".entry-content[itemprop=description], .desc" + protected open val animeAdditionalInfoSelector = "div.spe > span, li:has(b)" + + protected open val animeStatusText = "Status" + protected open val animeAuthorText = "Fansub" + protected open val animeArtistText = when (lang) { + "pt-BR" -> "Estudio" + else -> "Studio" + } + + protected open val animeAltNamePrefix = when (lang) { + "pt-BR" -> "Nome(s) alternativo(s): " + else -> "Alternative name(s): " + } + + protected open fun getAnimeDescription(document: Document) = + document.selectFirst(animeDescriptionSelector)?.text() + + override fun animeDetailsParse(document: Document): SAnime { + return SAnime.create().apply { + setUrlWithoutDomain(document.location()) + title = document.selectFirst(animeTitleSelector)!!.text() + thumbnail_url = document.selectFirst(animeThumbnailSelector)?.getImageUrl() + + val infos = document.selectFirst(animeDetailsSelector)!! + genre = infos.select(animeGenresSelector).eachText().joinToString() + + status = parseStatus(infos.getInfo(animeStatusText)) + artist = infos.getInfo(animeArtistText) + author = infos.getInfo(animeAuthorText) + + description = buildString { + getAnimeDescription(document)?.also { + append("$it\n\n") + } + + document.selectFirst(animeAltNameSelector)?.text() + ?.takeIf(String::isNotBlank) + ?.also { append("$animeAltNamePrefix$it\n") } + + infos.select(animeAdditionalInfoSelector).eachText().forEach { + append("$it\n") + } + } + } + } + + // ============================== Episodes ============================== + override fun episodeListParse(response: Response): List { + val doc = response.asJsoup() + return doc.select(episodeListSelector()).map(::episodeFromElement) + } + + override fun episodeListSelector() = "div.eplister > ul > li > a" + + protected open val episodePrefix = when (lang) { + "pt-BR" -> "Episódio" + else -> "Episode" + } + + @Suppress("unused_parameter") + protected open fun getEpisodeName(element: Element, epNum: String) = "$episodePrefix $epNum" + + override fun episodeFromElement(element: Element): SEpisode { + return SEpisode.create().apply { + setUrlWithoutDomain(element.attr("href")) + element.selectFirst(".epl-num")!!.text().let { + name = getEpisodeName(element, it) + episode_number = it.substringBefore(" ").toFloatOrNull() ?: 0F + } + element.selectFirst(".epl-sub")?.text()?.let { scanlator = it } + date_upload = element.selectFirst(".epl-date")?.text().toDate() + } + } + + // ============================ Video Links ============================= + override fun videoListSelector() = "select.mirror > option[data-index], ul.mirror a[data-em]" + + override fun videoListParse(response: Response): List