Ability to upload extra files

This commit is contained in:
Nikhil Badyal
2023-08-08 20:51:42 +05:30
parent d161d9243c
commit 86f449f519
5 changed files with 51 additions and 13 deletions
+17 -7
View File
@@ -136,6 +136,7 @@ You can use any of the following methods to build.
| [TELEGRAM_BOT_TOKEN](#telegram-support) | APKs Sender for Telegram upload | None | | [TELEGRAM_BOT_TOKEN](#telegram-support) | APKs Sender for Telegram upload | None |
| [TELEGRAM_API_ID](#telegram-support) | Used for telegram Authentication | None | | [TELEGRAM_API_ID](#telegram-support) | Used for telegram Authentication | None |
| [TELEGRAM_API_HASH](#telegram-support) | Used for telegram Authentication | None | | [TELEGRAM_API_HASH](#telegram-support) | Used for telegram Authentication | None |
| [EXTRA_FILES](#extra-files) | Extra files apk to upload in GitHub upload. | None |
`*` - Can be overridden for individual app. `*` - Can be overridden for individual app.
### App Level Config ### App Level Config
@@ -282,7 +283,16 @@ You can use any of the following methods to build.
*Note* - *Note* -
1. Possible values are: `armeabi-v7a`,`x86`,`x86_64`,`arm64-v8a` 1. Possible values are: `armeabi-v7a`,`x86`,`x86_64`,`arm64-v8a`
2. Make sure the patching resource(CLI) support this feature. 2. Make sure the patching resource(CLI) support this feature.
10. <a id="custom-exclude-patching"></a>If you want to exclude any patch. Set comma separated patch in `.env` file 10. <a id="extra-files"></a>If you want to include any extra file to the Github upload. Set comma arguments
in `.env` file or in `ENVS` in `GitHub secrets` (Recommended) in the format
```ini
EXTRA_FILES=<url>@<appName>.apk
```
Example:
```dotenv
EXTRA_FILES=https://github.com/inotia00/mMicroG/releases/latest@mmicrog.apk
```
11. <a id="custom-exclude-patching"></a>If you want to exclude any patch. Set comma separated patch in `.env` file
or in `ENVS` in `GitHub secrets` (Recommended) in the format or in `ENVS` in `GitHub secrets` (Recommended) in the format
```ini ```ini
<APP_NAME>_EXCLUDE_PATCH=<PATCH_TO_EXCLUDE-1,PATCH_TO_EXCLUDE-2> <APP_NAME>_EXCLUDE_PATCH=<PATCH_TO_EXCLUDE-1,PATCH_TO_EXCLUDE-2>
@@ -296,7 +306,7 @@ You can use any of the following methods to build.
1. **All** the patches for an app are **included** by default.<br> 1. **All** the patches for an app are **included** by default.<br>
2. Revanced patches are provided as space separated, make sure you type those **-** separated here. 2. Revanced patches are provided as space separated, make sure you type those **-** separated here.
It means a patch named _**Hey There**_ must be entered as **_hey-there_** in the above example. It means a patch named _**Hey There**_ must be entered as **_hey-there_** in the above example.
11. <a id="custom-include-patching"></a>If you want to include any universal patch. Set comma separated patch in `.env` 12. <a id="custom-include-patching"></a>If you want to include any universal patch. Set comma separated patch in `.env`
file or in `ENVS` in `GitHub secrets` (Recommended) in the format file or in `ENVS` in `GitHub secrets` (Recommended) in the format
```ini ```ini
<APP_NAME>_INCLUDE_PATCH=<PATCH_TO_EXCLUDE-1,PATCH_TO_EXCLUDE-2> <APP_NAME>_INCLUDE_PATCH=<PATCH_TO_EXCLUDE-1,PATCH_TO_EXCLUDE-2>
@@ -308,7 +318,7 @@ You can use any of the following methods to build.
Note - Note -
1. Revanced patches are provided as space separated, make sure you type those **-** separated here. 1. Revanced patches are provided as space separated, make sure you type those **-** separated here.
It means a patch named _**Hey There**_ must be entered as **_hey-there_** in the above example. It means a patch named _**Hey There**_ must be entered as **_hey-there_** in the above example.
12. <a id="app-version"></a>If you want to build a specific version or latest version. Add `version` in `.env` file 13. <a id="app-version"></a>If you want to build a specific version or latest version. Add `version` in `.env` file
or in `ENVS` in `GitHub secrets` (Recommended) in the format or in `ENVS` in `GitHub secrets` (Recommended) in the format
```ini ```ini
<APP_NAME>_VERSION=<VERSION> <APP_NAME>_VERSION=<VERSION>
@@ -319,7 +329,7 @@ You can use any of the following methods to build.
YOUTUBE_MUSIC_VERSION=X.X.X YOUTUBE_MUSIC_VERSION=X.X.X
TWITTER_VERSION=latest TWITTER_VERSION=latest
``` ```
13. <a id="telegram-support"></a>For Telegram Upload. 14. <a id="telegram-support"></a>For Telegram Upload.
1. Set up a telegram channel, send a message to it and forward the message to 1. Set up a telegram channel, send a message to it and forward the message to
this telegram [bot](https://t.me/username_to_id_bot) this telegram [bot](https://t.me/username_to_id_bot)
2. Copy `id` and save it to `TELEGRAM_CHAT_ID`<br> 2. Copy `id` and save it to `TELEGRAM_CHAT_ID`<br>
@@ -333,12 +343,12 @@ You can use any of the following methods to build.
<img src="https://i.imgur.com/7n5k1mp.png" width="300" style="left"><br> <img src="https://i.imgur.com/7n5k1mp.png" width="300" style="left"><br>
6. After Everything done successfully a part of the actions secrets of the repository may look like<br> 6. After Everything done successfully a part of the actions secrets of the repository may look like<br>
<img src="https://i.imgur.com/Cjifz1M.png" width="400"> <img src="https://i.imgur.com/Cjifz1M.png" width="400">
14. Configuration defined in `ENVS` in `GitHub secrets` will override the configuration in `.env` file. You can use this 15. Configuration defined in `ENVS` in `GitHub secrets` will override the configuration in `.env` file. You can use this
fact to define your normal configurations in `.env` file and sometimes if you want to build something different just fact to define your normal configurations in `.env` file and sometimes if you want to build something different just
once. Add it in `GitHub secrets`.<br> once. Add it in `GitHub secrets`.<br>
15. Sample Envs<br> 16. Sample Envs<br>
<img src="https://i.imgur.com/FxOtiGs.png" width="600" style="left"> <img src="https://i.imgur.com/FxOtiGs.png" width="600" style="left">
16. Make sure your Action has write access. If not click 17. Make sure your Action has write access. If not click
[here](https://github.com/nikhilbadyal/docker-py-revanced/settings/actions). [here](https://github.com/nikhilbadyal/docker-py-revanced/settings/actions).
In the bottom give read and write access to Actions. In the bottom give read and write access to Actions.
<img src="https://i.imgur.com/STSv2D3.png" width="400"> <img src="https://i.imgur.com/STSv2D3.png" width="400">
+2 -1
View File
@@ -8,7 +8,7 @@ from src.config import RevancedConfig
from src.downloader.factory import DownloaderFactory from src.downloader.factory import DownloaderFactory
from src.parser import Parser from src.parser import Parser
from src.patches import Patches from src.patches import Patches
from src.utils import AppNotFound, PatchesJsonFailed, check_java from src.utils import AppNotFound, PatchesJsonFailed, check_java, extra_downloads
def main() -> None: def main() -> None:
@@ -17,6 +17,7 @@ def main() -> None:
env = Env() env = Env()
config = RevancedConfig(env) config = RevancedConfig(env)
extra_downloads(config)
check_java(config.dry_run) check_java(config.dry_run)
logger.info(f"Will Patch only {config.apps}") logger.info(f"Will Patch only {config.apps}")
+4 -1
View File
@@ -54,7 +54,9 @@ class APP(object):
return ", ".join([f"{key}: {value}" for key, value in attrs.items()]) return ", ".join([f"{key}: {value}" for key, value in attrs.items()])
@staticmethod @staticmethod
def download(url: str, config: RevancedConfig, assets_filter: str) -> str: def download(
url: str, config: RevancedConfig, assets_filter: str, file_name: str = ""
) -> str:
"""Downloader.""" """Downloader."""
from src.downloader.download import Downloader from src.downloader.download import Downloader
@@ -63,6 +65,7 @@ class APP(object):
from src.downloader.github import Github from src.downloader.github import Github
url = Github.patch_resource(url, assets_filter)[0] url = Github.patch_resource(url, assets_filter)[0]
if not file_name:
extension = pathlib.Path(url).suffix extension = pathlib.Path(url).suffix
file_name = APP.generate_filename(url) + extension file_name = APP.generate_filename(url) + extension
Downloader(None, config).direct_download(url, file_name) # type: ignore Downloader(None, config).direct_download(url, file_name) # type: ignore
+3 -2
View File
@@ -5,8 +5,6 @@ from typing import List
from environs import Env from environs import Env
from requests import Session from requests import Session
from src.utils import default_build
default_cli = "https://github.com/revanced/revanced-cli/releases/latest" default_cli = "https://github.com/revanced/revanced-cli/releases/latest"
default_patches = "https://github.com/revanced/revanced-patches/releases/latest" default_patches = "https://github.com/revanced/revanced-patches/releases/latest"
default_patches_json = default_patches default_patches_json = default_patches
@@ -19,6 +17,8 @@ class RevancedConfig(object):
"""Revanced Configurations.""" """Revanced Configurations."""
def __init__(self, env: Env) -> None: def __init__(self, env: Env) -> None:
from src.utils import default_build
self.env = env self.env = env
self.temp_folder = Path("apks") self.temp_folder = Path("apks")
self.session = Session() self.session = Session()
@@ -89,3 +89,4 @@ class RevancedConfig(object):
"GLOBAL_KEYSTORE_FILE_NAME", "revanced.keystore" "GLOBAL_KEYSTORE_FILE_NAME", "revanced.keystore"
) )
self.global_archs_to_build = env.list("GLOBAL_ARCHS_TO_BUILD", []) self.global_archs_to_build = env.list("GLOBAL_ARCHS_TO_BUILD", [])
self.extra_download_files: List[str] = env.list("EXTRA_FILES", [])
+23
View File
@@ -1,4 +1,5 @@
"""Utilities.""" """Utilities."""
import os
import re import re
import subprocess import subprocess
from typing import Dict from typing import Dict
@@ -6,6 +7,8 @@ from typing import Dict
from loguru import logger from loguru import logger
from requests import Response from requests import Response
from src.config import RevancedConfig
default_build = [ default_build = [
"youtube", "youtube",
"youtube_music", "youtube_music",
@@ -97,3 +100,23 @@ def check_java(dry_run: bool) -> None:
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
logger.debug("Java>= 17 Must be installed") logger.debug("Java>= 17 Must be installed")
exit(-1) exit(-1)
def extra_downloads(config: RevancedConfig) -> None:
"""Download extra files."""
from src.app import APP
try:
for extra in config.extra_download_files:
url, file_name = extra.split("@")
file_name_without_extension, file_extension = os.path.splitext(file_name)
if file_extension.lower() == ".apk":
new_file_name = file_name_without_extension + "-output" + file_extension
else:
raise ValueError("Only .apk extensions are allowed.")
APP.download(url, config, assets_filter="", file_name=new_file_name)
except ValueError:
logger.info(
"Unable to download extra file. Provide input in url@name.apk format."
)