mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
@@ -1,7 +1,8 @@
|
|||||||
## Things to work on
|
## Things to work on
|
||||||
|
|
||||||
| | |
|
| | |
|
||||||
|:--------------------------------------------|---------------:|
|
|:------------------------------------------------------|---------------:|
|
||||||
| Parallelize app object creation. | <li> [ ] </li> |
|
| Parallelize app object creation. | <li> [ ] </li> |
|
||||||
| Parallelize app patching. | <li> [ ] </li> |
|
| Parallelize app patching. | <li> [ ] </li> |
|
||||||
| Ability to provide local patching resources | <li> [X] </li> |
|
| Ability to provide local patching resources | <li> [X] </li> |
|
||||||
|
| Ability to provide changelog repo in update_changelog | <li> [ ] </li> |
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from google_play_scraper.exceptions import GooglePlayScraperException
|
|||||||
|
|
||||||
from src.exceptions import APKMirrorScrapperFailure
|
from src.exceptions import APKMirrorScrapperFailure
|
||||||
from src.patches import Patches
|
from src.patches import Patches
|
||||||
from src.utils import handle_response
|
from src.utils import handle_github_response
|
||||||
|
|
||||||
not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png"
|
not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png"
|
||||||
headers = {
|
headers = {
|
||||||
@@ -105,7 +105,7 @@ def generate_markdown_table(data: List[List[str]]) -> str:
|
|||||||
def main() -> None:
|
def main() -> None:
|
||||||
repo_url = "https://api.revanced.app/v2/patches/latest"
|
repo_url = "https://api.revanced.app/v2/patches/latest"
|
||||||
response = requests.get(repo_url)
|
response = requests.get(repo_url)
|
||||||
handle_response(response)
|
handle_github_response(response)
|
||||||
|
|
||||||
parsed_data = response.json()
|
parsed_data = response.json()
|
||||||
compatible_packages = parsed_data["patches"]
|
compatible_packages = parsed_data["patches"]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from src.config import RevancedConfig
|
|||||||
from src.downloader.utils import implement_method
|
from src.downloader.utils import implement_method
|
||||||
from src.exceptions import PatchingFailed
|
from src.exceptions import PatchingFailed
|
||||||
from src.patches import Patches
|
from src.patches import Patches
|
||||||
from src.utils import handle_response
|
from src.utils import handle_github_response
|
||||||
|
|
||||||
|
|
||||||
class Downloader(object):
|
class Downloader(object):
|
||||||
@@ -54,7 +54,7 @@ class Downloader(object):
|
|||||||
stream=True,
|
stream=True,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
handle_response(response)
|
handle_github_response(response)
|
||||||
total = int(response.headers.get("content-length", 0))
|
total = int(response.headers.get("content-length", 0))
|
||||||
bar = tqdm(
|
bar = tqdm(
|
||||||
desc=file_name,
|
desc=file_name,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from loguru import logger
|
|||||||
|
|
||||||
from src.config import RevancedConfig
|
from src.config import RevancedConfig
|
||||||
from src.downloader.download import Downloader
|
from src.downloader.download import Downloader
|
||||||
from src.utils import handle_response, update_changelog
|
from src.utils import handle_github_response, update_changelog
|
||||||
|
|
||||||
|
|
||||||
class Github(Downloader):
|
class Github(Downloader):
|
||||||
@@ -35,7 +35,7 @@ class Github(Downloader):
|
|||||||
logger.debug("Using personal access token")
|
logger.debug("Using personal access token")
|
||||||
headers["Authorization"] = f"token {self.config.personal_access_token}"
|
headers["Authorization"] = f"token {self.config.personal_access_token}"
|
||||||
response = requests.get(repo_url, headers=headers)
|
response = requests.get(repo_url, headers=headers)
|
||||||
handle_response(response)
|
handle_github_response(response)
|
||||||
if repo_name == "revanced-patches":
|
if repo_name == "revanced-patches":
|
||||||
download_url = response.json()["assets"][1]["browser_download_url"]
|
download_url = response.json()["assets"][1]["browser_download_url"]
|
||||||
else:
|
else:
|
||||||
@@ -78,7 +78,7 @@ class Github(Downloader):
|
|||||||
if config.personal_access_token:
|
if config.personal_access_token:
|
||||||
headers["Authorization"] = f"token {config.personal_access_token}"
|
headers["Authorization"] = f"token {config.personal_access_token}"
|
||||||
response = requests.get(api_url, headers=headers)
|
response = requests.get(api_url, headers=headers)
|
||||||
handle_response(response)
|
handle_github_response(response)
|
||||||
assets = response.json()["assets"]
|
assets = response.json()["assets"]
|
||||||
try:
|
try:
|
||||||
filter_pattern = re.compile(asset_filter)
|
filter_pattern = re.compile(asset_filter)
|
||||||
|
|||||||
+15
-7
@@ -15,6 +15,14 @@ from src.utils import possible_archs
|
|||||||
class Parser(object):
|
class Parser(object):
|
||||||
"""Revanced Parser."""
|
"""Revanced Parser."""
|
||||||
|
|
||||||
|
CLI_JAR = "-jar"
|
||||||
|
APK_ARG = "-a"
|
||||||
|
PATCHES_ARG = "-b"
|
||||||
|
INTEGRATIONS_ARG = "-m"
|
||||||
|
OUTPUT_ARG = "-o"
|
||||||
|
KEYSTORE_ARG = "--keystore"
|
||||||
|
OPTIONS_ARG = "--options"
|
||||||
|
|
||||||
def __init__(self, patcher: Patches, config: RevancedConfig) -> None:
|
def __init__(self, patcher: Patches, config: RevancedConfig) -> None:
|
||||||
self._PATCHES: List[str] = []
|
self._PATCHES: List[str] = []
|
||||||
self._EXCLUDED: List[str] = []
|
self._EXCLUDED: List[str] = []
|
||||||
@@ -78,19 +86,19 @@ class Parser(object):
|
|||||||
:param app: Name of the app
|
:param app: Name of the app
|
||||||
"""
|
"""
|
||||||
args = [
|
args = [
|
||||||
"-jar",
|
self.CLI_JAR,
|
||||||
app.resource["cli"],
|
app.resource["cli"],
|
||||||
"-a",
|
self.APK_ARG,
|
||||||
f"{app.app_name}.apk",
|
f"{app.app_name}.apk",
|
||||||
"-b",
|
self.PATCHES_ARG,
|
||||||
app.resource["patches"],
|
app.resource["patches"],
|
||||||
"-m",
|
self.INTEGRATIONS_ARG,
|
||||||
app.resource["integrations"],
|
app.resource["integrations"],
|
||||||
"-o",
|
self.OUTPUT_ARG,
|
||||||
app.get_output_file_name(),
|
app.get_output_file_name(),
|
||||||
"--keystore",
|
self.KEYSTORE_ARG,
|
||||||
app.keystore_name,
|
app.keystore_name,
|
||||||
"--options",
|
self.OPTIONS_ARG,
|
||||||
"options.json",
|
"options.json",
|
||||||
]
|
]
|
||||||
if app.experiment:
|
if app.experiment:
|
||||||
|
|||||||
+16
-12
@@ -1,6 +1,5 @@
|
|||||||
"""Revanced Patches."""
|
"""Revanced Patches."""
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@@ -64,18 +63,10 @@ class Patches(object):
|
|||||||
"""Return supported apps."""
|
"""Return supported apps."""
|
||||||
return Patches._revanced_app_ids
|
return Patches._revanced_app_ids
|
||||||
|
|
||||||
def scrap_patches(self, file_name: str) -> Any:
|
|
||||||
"""Scrap Patches."""
|
|
||||||
if os.path.exists(file_name):
|
|
||||||
with open(file_name) as f:
|
|
||||||
patches = json.load(f)
|
|
||||||
return patches
|
|
||||||
raise PatchesJsonFailed()
|
|
||||||
|
|
||||||
# noinspection DuplicatedCode
|
|
||||||
def fetch_patches(self, config: RevancedConfig, app: APP) -> None:
|
def fetch_patches(self, config: RevancedConfig, app: APP) -> None:
|
||||||
"""Function to fetch all patches."""
|
"""Function to fetch all patches."""
|
||||||
patches = self.scrap_patches(
|
patch_loader = PatchLoader()
|
||||||
|
patches = patch_loader.load_patches(
|
||||||
f'{config.temp_folder}/{app.resource["patches_json"]}'
|
f'{config.temp_folder}/{app.resource["patches_json"]}'
|
||||||
)
|
)
|
||||||
for app_name in (self.revanced_app_ids[x][1] for x in self.revanced_app_ids):
|
for app_name in (self.revanced_app_ids[x][1] for x in self.revanced_app_ids):
|
||||||
@@ -121,7 +112,6 @@ class Patches(object):
|
|||||||
pass
|
pass
|
||||||
return patches, version
|
return patches, version
|
||||||
|
|
||||||
# noinspection IncorrectFormatting
|
|
||||||
def include_exclude_patch(
|
def include_exclude_patch(
|
||||||
self, app: APP, parser: Any, patches: List[Dict[str, str]]
|
self, app: APP, parser: Any, patches: List[Dict[str, str]]
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -164,3 +154,17 @@ class Patches(object):
|
|||||||
recommended_version = app.app_version
|
recommended_version = app.app_version
|
||||||
app.set_recommended_version(recommended_version, experiment)
|
app.set_recommended_version(recommended_version, experiment)
|
||||||
return total_patches
|
return total_patches
|
||||||
|
|
||||||
|
|
||||||
|
class PatchLoader:
|
||||||
|
"""Patch Loader."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load_patches(file_name: str) -> Any:
|
||||||
|
"""Load patches from a file."""
|
||||||
|
try:
|
||||||
|
with open(file_name) as f:
|
||||||
|
patches = json.load(f)
|
||||||
|
return patches
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise PatchesJsonFailed()
|
||||||
|
|||||||
+20
-17
@@ -27,18 +27,20 @@ def update_changelog(name: str, response: Dict[str, str]) -> None:
|
|||||||
publish_time = f"**Published at** -<br> {response['published_at']}"
|
publish_time = f"**Published at** -<br> {response['published_at']}"
|
||||||
footer = f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
|
footer = f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
|
||||||
collapse_end = "</details>"
|
collapse_end = "</details>"
|
||||||
change_log = (
|
change_log = "".join(
|
||||||
collapse_start
|
[
|
||||||
+ release_version
|
collapse_start,
|
||||||
+ change_log
|
release_version,
|
||||||
+ publish_time
|
change_log,
|
||||||
+ footer
|
publish_time,
|
||||||
+ collapse_end
|
footer,
|
||||||
|
collapse_end,
|
||||||
|
]
|
||||||
)
|
)
|
||||||
file1.write(change_log)
|
file1.write(change_log)
|
||||||
|
|
||||||
|
|
||||||
def handle_response(response: Response) -> None:
|
def handle_github_response(response: Response) -> None:
|
||||||
"""Handle Get Request Response."""
|
"""Handle Get Request Response."""
|
||||||
response_code = response.status_code
|
response_code = response.status_code
|
||||||
if response_code != 200:
|
if response_code != 200:
|
||||||
@@ -50,21 +52,21 @@ def handle_response(response: Response) -> None:
|
|||||||
def slugify(string: str) -> str:
|
def slugify(string: str) -> str:
|
||||||
"""Converts a string to a slug format."""
|
"""Converts a string to a slug format."""
|
||||||
# Convert to lowercase
|
# Convert to lowercase
|
||||||
string = string.lower()
|
modified_string = string.lower()
|
||||||
|
|
||||||
# Remove special characters
|
# Remove special characters
|
||||||
string = re.sub(r"[^\w\s-]", "", string)
|
modified_string = re.sub(r"[^\w\s-]", "", modified_string)
|
||||||
|
|
||||||
# Replace spaces with dashes
|
# Replace spaces with dashes
|
||||||
string = re.sub(r"\s+", "-", string)
|
modified_string = re.sub(r"\s+", "-", modified_string)
|
||||||
|
|
||||||
# Remove consecutive dashes
|
# Remove consecutive dashes
|
||||||
string = re.sub(r"-+", "-", string)
|
modified_string = re.sub(r"-+", "-", modified_string)
|
||||||
|
|
||||||
# Remove leading and trailing dashes
|
# Remove leading and trailing dashes
|
||||||
string = string.strip("-")
|
modified_string = modified_string.strip("-")
|
||||||
|
|
||||||
return string
|
return modified_string
|
||||||
|
|
||||||
|
|
||||||
def check_java(dry_run: bool) -> None:
|
def check_java(dry_run: bool) -> None:
|
||||||
@@ -95,10 +97,11 @@ def extra_downloads(config: RevancedConfig) -> None:
|
|||||||
url, file_name = extra.split("@")
|
url, file_name = extra.split("@")
|
||||||
file_name_without_extension, file_extension = os.path.splitext(file_name)
|
file_name_without_extension, file_extension = os.path.splitext(file_name)
|
||||||
|
|
||||||
if file_extension.lower() == ".apk":
|
if file_extension.lower() != ".apk":
|
||||||
|
logger.info(f"Only .apk extensions are allowed {file_name}.")
|
||||||
|
continue
|
||||||
|
|
||||||
new_file_name = f"{file_name_without_extension}-output{file_extension}"
|
new_file_name = f"{file_name_without_extension}-output{file_extension}"
|
||||||
else:
|
|
||||||
raise ValueError("Only .apk extensions are allowed.")
|
|
||||||
APP.download(url, config, assets_filter=".*apk", file_name=new_file_name)
|
APP.download(url, config, assets_filter=".*apk", file_name=new_file_name)
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
Reference in New Issue
Block a user