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
+6 -3
View File
@@ -54,7 +54,9 @@ class APP(object):
return ", ".join([f"{key}: {value}" for key, value in attrs.items()])
@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."""
from src.downloader.download import Downloader
@@ -63,8 +65,9 @@ class APP(object):
from src.downloader.github import Github
url = Github.patch_resource(url, assets_filter)[0]
extension = pathlib.Path(url).suffix
file_name = APP.generate_filename(url) + extension
if not file_name:
extension = pathlib.Path(url).suffix
file_name = APP.generate_filename(url) + extension
Downloader(None, config).direct_download(url, file_name) # type: ignore
return file_name
+3 -2
View File
@@ -5,8 +5,6 @@ from typing import List
from environs import Env
from requests import Session
from src.utils import default_build
default_cli = "https://github.com/revanced/revanced-cli/releases/latest"
default_patches = "https://github.com/revanced/revanced-patches/releases/latest"
default_patches_json = default_patches
@@ -19,6 +17,8 @@ class RevancedConfig(object):
"""Revanced Configurations."""
def __init__(self, env: Env) -> None:
from src.utils import default_build
self.env = env
self.temp_folder = Path("apks")
self.session = Session()
@@ -89,3 +89,4 @@ class RevancedConfig(object):
"GLOBAL_KEYSTORE_FILE_NAME", "revanced.keystore"
)
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."""
import os
import re
import subprocess
from typing import Dict
@@ -6,6 +7,8 @@ from typing import Dict
from loguru import logger
from requests import Response
from src.config import RevancedConfig
default_build = [
"youtube",
"youtube_music",
@@ -97,3 +100,23 @@ def check_java(dry_run: bool) -> None:
except subprocess.CalledProcessError:
logger.debug("Java>= 17 Must be installed")
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."
)