mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
✨ Per app config
This commit is contained in:
@@ -30,7 +30,6 @@ class ApkMirror(Downloader):
|
||||
"p.notes:nth-child(3) > span:nth-child(1) > a:nth-child(1)"
|
||||
).attributes["href"]
|
||||
self._download(self.config.apk_mirror + href, f"{app}.apk")
|
||||
logger.debug("Finished Extracting link and downloading")
|
||||
|
||||
def get_download_page(self, parser: LexborHTMLParser, main_page: str) -> str:
|
||||
"""Function to get the download page in apk_mirror.
|
||||
@@ -67,7 +66,6 @@ class ApkMirror(Downloader):
|
||||
:param version: Version of the application to download
|
||||
:return: Version of downloaded apk
|
||||
"""
|
||||
logger.debug(f"Trying to download {app},specific version {version}")
|
||||
version = version.replace(".", "-")
|
||||
main_page = f"{self.config.apk_mirror_version_urls.get(app)}-{version}-release/"
|
||||
parser = LexborHTMLParser(
|
||||
@@ -75,7 +73,6 @@ class ApkMirror(Downloader):
|
||||
)
|
||||
download_page = self.get_download_page(parser, main_page)
|
||||
self.extract_download_link(download_page, app)
|
||||
logger.debug(f"Downloaded {app} apk from apkmirror_specific_version")
|
||||
|
||||
def latest_version(self, app: str, **kwargs: Any) -> None:
|
||||
"""Function to download whatever the latest version of app from
|
||||
@@ -105,4 +102,3 @@ class ApkMirror(Downloader):
|
||||
parser = LexborHTMLParser(self.config.session.get(main_page).text)
|
||||
download_page = self.get_download_page(parser, main_page)
|
||||
self.extract_download_link(download_page, app)
|
||||
logger.debug(f"Downloaded {app} apk from apkmirror_specific_version in rt")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Downloader Class."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
from queue import PriorityQueue
|
||||
from time import perf_counter
|
||||
from typing import Any, Tuple
|
||||
@@ -23,14 +24,20 @@ class Downloader(object):
|
||||
self.config = config
|
||||
self.patcher = patcher
|
||||
|
||||
def _download(self, url: str, file_name: str) -> None:
|
||||
if (
|
||||
os.path.exists(self.config.temp_folder.joinpath(file_name))
|
||||
or self.config.dry_run
|
||||
):
|
||||
@staticmethod
|
||||
def file_status_check(file_name: Path, dry_run: bool, url: str) -> bool:
|
||||
"""Check if file already exists."""
|
||||
if os.path.exists(file_name) or dry_run:
|
||||
logger.debug(
|
||||
f"Skipping download of {file_name}. File already exists or dry running."
|
||||
f"Skipping download of {file_name} from {url}. File already exists or dry running."
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
def _download(self, url: str, file_name: str) -> None:
|
||||
if self.file_status_check(
|
||||
self.config.temp_folder.joinpath(file_name), self.config.dry_run, url
|
||||
):
|
||||
return
|
||||
logger.info(f"Trying to download {file_name} from {url}")
|
||||
self._QUEUE_LENGTH += 1
|
||||
@@ -99,3 +106,7 @@ class Downloader(object):
|
||||
self.specific_version(app, version)
|
||||
else:
|
||||
self.latest_version(app, **kwargs)
|
||||
|
||||
def direct_download(self, dl: str, file_name: str) -> None:
|
||||
"""Download from DL."""
|
||||
self._download(dl, file_name)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"""Github Downloader."""
|
||||
from typing import Dict
|
||||
from typing import Dict, List
|
||||
|
||||
import requests
|
||||
from lastversion import latest
|
||||
from loguru import logger
|
||||
|
||||
from src.downloader.download import Downloader
|
||||
@@ -41,3 +42,11 @@ class Github(Downloader):
|
||||
download_url = response.json()["assets"][0]["browser_download_url"]
|
||||
update_changelog(f"{owner}/{repo_name}", response.json())
|
||||
self._download(download_url, file_name=app)
|
||||
|
||||
@staticmethod
|
||||
def patch_resource(repo_url: str, assets_filter: str) -> list[str]:
|
||||
"""Fetch patch resource from repo url."""
|
||||
latest_resource_version: List[str] = latest(
|
||||
repo_url, assets_filter=assets_filter, output_format="assets"
|
||||
)
|
||||
return latest_resource_version
|
||||
|
||||
@@ -1,63 +1,4 @@
|
||||
"""Utility class."""
|
||||
import os
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.patches import Patches
|
||||
from src.utils import PatcherDownloadFailed
|
||||
|
||||
implement_method = "Please implement the method"
|
||||
|
||||
|
||||
def download_revanced(config: RevancedConfig, patcher: Patches) -> None:
|
||||
"""Download Revanced and Extended Patches, Integration and CLI."""
|
||||
from src.downloader.factory import DownloaderFactory
|
||||
|
||||
if os.path.exists("changelog.md") and not config.dry_run:
|
||||
logger.debug("Deleting old changelog.md")
|
||||
os.remove("changelog.md")
|
||||
assets = [
|
||||
["revanced", "revanced-cli", config.normal_cli_jar],
|
||||
["revanced", "revanced-integrations", config.normal_integrations_apk],
|
||||
["revanced", "revanced-patches", config.normal_patches_jar],
|
||||
]
|
||||
if config.build_extended:
|
||||
assets += [
|
||||
["inotia00", "revanced-cli", config.cli_jar],
|
||||
["inotia00", "revanced-integrations", config.integrations_apk],
|
||||
["inotia00", "revanced-patches", config.patches_jar],
|
||||
]
|
||||
if (
|
||||
"youtube" in config.apps
|
||||
or "youtube_music" in config.apps
|
||||
or "microg" in config.apps
|
||||
):
|
||||
if config.build_extended and "microg" in config.apps:
|
||||
assets += [
|
||||
["inotia00", "mMicroG", "microg.apk"],
|
||||
]
|
||||
else:
|
||||
assets += [
|
||||
["inotia00", "mMicroG", "microg-output.apk"],
|
||||
]
|
||||
downloader = DownloaderFactory.create_downloader(
|
||||
app="patches", patcher=patcher, config=config
|
||||
)
|
||||
with ThreadPoolExecutor(7) as executor:
|
||||
futures = [
|
||||
executor.submit(
|
||||
downloader.download,
|
||||
version="latest",
|
||||
app=repo[2],
|
||||
**{"owner": repo[0], "name": repo[1]},
|
||||
)
|
||||
for repo in assets
|
||||
]
|
||||
for future in as_completed(futures):
|
||||
try:
|
||||
future.result()
|
||||
except Exception as e:
|
||||
raise PatcherDownloadFailed(f"An exception occurred: {e}")
|
||||
logger.info("Downloaded revanced microG ,cli, integrations and patches.")
|
||||
|
||||
Reference in New Issue
Block a user