mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-24 19:38:36 +09:00
💚 Fixed Branch prefix for bugs
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#GLobal envs
|
||||
PATCH_APPS=youtube,youtube_music,twiiter
|
||||
GLOBAL_CLI_DL=https://github.com/revanced/revanced-cli
|
||||
GLOBAL_PATCHES_DL=https://github.com/revanced/revanced-patches
|
||||
GLOBAL_PATCHES_JSON_DL=https://github.com/revanced/revanced-patches
|
||||
GLOBAL_INTEGRATIONS_DL=https://github.com/revanced/revanced-integrations
|
||||
EXISTING_DOWNLOADED_APKS=youtube,youtube_music
|
||||
PERSONAL_ACCESS_TOKEN=ghp_asample_token
|
||||
|
||||
#YouTune
|
||||
YOUTUBE_CLI_DL=https://github.com/revanced/revanced-cli
|
||||
YOUTUBE_PATCHES_DL=https://github.com/revanced/revanced-patches
|
||||
YOUTUBE_PATCHES_JSON_DL=https://github.com/revanced/revanced-patches
|
||||
YOUTUBE_INTEGRATIONS_DL=https://github.com/revanced/revanced-integrations
|
||||
YOUTUBE_KEYSTORE_FILE_NAME=youtube.keystore
|
||||
YOUTUBE_ARCHS_TO_BUILD=arm64-v8a,armeabi-v7a
|
||||
YOUTUBE_EXCLUDE_PATCH=custom-branding,hide-get-premium
|
||||
YOUTUBE_INCLUDE_PATCH=remove-screenshot-restriction
|
||||
YOUTUBE_VERSION=17.31.36
|
||||
|
||||
#YOUTUBE_MUSIC Music
|
||||
YOUTUBE_MUSIC_CLI_DL=https://github.com/revanced/revanced-cli/releases/tag/v2.22.1
|
||||
YOUTUBE_MUSIC_PATCHES_DL=https://github.com/revanced/revanced-patches
|
||||
YOUTUBE_MUSIC_PATCHES_JSON_DL=https://github.com/revanced/revanced-patches
|
||||
YOUTUBE_MUSIC_INTEGRATIONS_DL=https://github.com/revanced/revanced-integrations
|
||||
YOUTUBE_MUSIC_EXCLUDE_PATCH=yt-music-is-shit
|
||||
|
||||
#Twitter
|
||||
TWITTER_VERSION=latest
|
||||
@@ -6,6 +6,7 @@ from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.downloader.factory import DownloaderFactory
|
||||
from src.exceptions import PatchingFailed
|
||||
from src.parser import Parser
|
||||
from src.patches import Patches
|
||||
from src.utils import AppNotFound, PatchesJsonFailed, check_java, extra_downloads
|
||||
@@ -16,6 +17,7 @@ def main() -> None:
|
||||
from src.app import APP
|
||||
|
||||
env = Env()
|
||||
env.read_env()
|
||||
config = RevancedConfig(env)
|
||||
extra_downloads(config)
|
||||
check_java(config.dry_run)
|
||||
@@ -38,6 +40,8 @@ def main() -> None:
|
||||
logger.info(f"Invalid app requested to build {e}")
|
||||
except PatchesJsonFailed:
|
||||
logger.exception("Patches.json not found")
|
||||
except PatchingFailed as e:
|
||||
logger.exception(e)
|
||||
except Exception as e:
|
||||
logger.exception(f"Failed to build {app} because of {e}")
|
||||
|
||||
|
||||
+4
-3
@@ -8,7 +8,8 @@ from typing import Dict
|
||||
from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.utils import PatcherDownloadFailed, slugify
|
||||
from src.exceptions import PatchingFailed
|
||||
from src.utils import slugify
|
||||
|
||||
|
||||
class APP(object):
|
||||
@@ -64,7 +65,7 @@ class APP(object):
|
||||
if url.startswith("https://github"):
|
||||
from src.downloader.github import Github
|
||||
|
||||
url = Github.patch_resource(url, assets_filter)[0]
|
||||
url = Github.patch_resource(url, assets_filter, config)
|
||||
if not file_name:
|
||||
extension = pathlib.Path(url).suffix
|
||||
file_name = APP.generate_filename(url) + extension
|
||||
@@ -97,7 +98,7 @@ class APP(object):
|
||||
try:
|
||||
self.resource[resource_name] = future.result()
|
||||
except Exception as e:
|
||||
raise PatcherDownloadFailed(f"An exception occurred: {e}") from e
|
||||
raise PatchingFailed(e) from e
|
||||
|
||||
@staticmethod
|
||||
def generate_filename(url: str) -> str:
|
||||
|
||||
@@ -10,6 +10,7 @@ from tqdm import tqdm
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.downloader.utils import implement_method
|
||||
from src.exceptions import PatchingFailed
|
||||
from src.patches import Patches
|
||||
from src.utils import handle_response
|
||||
|
||||
@@ -35,6 +36,8 @@ class Downloader(object):
|
||||
return False
|
||||
|
||||
def _download(self, url: str, file_name: str) -> None:
|
||||
if not url:
|
||||
raise PatchingFailed("No download to download")
|
||||
if self.file_status_check(
|
||||
self.config.temp_folder.joinpath(file_name), self.config.dry_run, url
|
||||
):
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"""Github Downloader."""
|
||||
from typing import Dict, List
|
||||
import re
|
||||
from typing import Dict, Tuple
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
from lastversion import latest
|
||||
from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.downloader.download import Downloader
|
||||
from src.utils import handle_response, update_changelog
|
||||
|
||||
@@ -42,9 +44,60 @@ class Github(Downloader):
|
||||
self._download(download_url, file_name=app)
|
||||
|
||||
@staticmethod
|
||||
def patch_resource(repo_url: str, assets_filter: str) -> list[str]:
|
||||
def _extract_repo_owner_and_tag(url: str) -> Tuple[str, str, str]:
|
||||
"""Extract repo owner and url from github url."""
|
||||
parsed_url = urlparse(url)
|
||||
path_segments = parsed_url.path.strip("/").split("/")
|
||||
|
||||
github_repo_owner = path_segments[0]
|
||||
github_repo_name = path_segments[1]
|
||||
|
||||
release_tag = "latest"
|
||||
for i, segment in enumerate(path_segments):
|
||||
if segment == "tag":
|
||||
release_tag = "tags/" + path_segments[i + 1]
|
||||
break
|
||||
|
||||
return github_repo_owner, github_repo_name, release_tag
|
||||
|
||||
@staticmethod
|
||||
def _get_release_assets(
|
||||
github_repo_owner: str,
|
||||
github_repo_name: str,
|
||||
release_tag: str,
|
||||
asset_filter: str,
|
||||
config: RevancedConfig,
|
||||
) -> str:
|
||||
"""Get assets from given tag."""
|
||||
api_url = f"https://api.github.com/repos/{github_repo_owner}/{github_repo_name}/releases/{release_tag}"
|
||||
headers = {
|
||||
"Content-Type": "application/vnd.github.v3+json",
|
||||
}
|
||||
if config.personal_access_token:
|
||||
headers["Authorization"] = f"token {config.personal_access_token}"
|
||||
response = requests.get(api_url, headers=headers)
|
||||
handle_response(response)
|
||||
assets = response.json()["assets"]
|
||||
try:
|
||||
filter_pattern = re.compile(asset_filter)
|
||||
except re.error:
|
||||
logger.error("Invalid regex pattern provided.")
|
||||
raise Exception()
|
||||
for asset in assets:
|
||||
assets_url = asset["browser_download_url"]
|
||||
assets_name = asset["name"]
|
||||
match = filter_pattern.search(assets_url)
|
||||
if match:
|
||||
logger.debug(f"Found {assets_name} to be downloaded from {assets_url}")
|
||||
return match.group()
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def patch_resource(
|
||||
repo_url: str, assets_filter: str, config: RevancedConfig
|
||||
) -> str:
|
||||
"""Fetch patch resource from repo url."""
|
||||
latest_resource_version: List[str] = latest(
|
||||
repo_url, assets_filter=assets_filter, output_format="assets"
|
||||
repo_owner, repo_name, tag = Github._extract_repo_owner_and_tag(repo_url)
|
||||
return Github._get_release_assets(
|
||||
repo_owner, repo_name, tag, assets_filter, config
|
||||
)
|
||||
return latest_resource_version
|
||||
|
||||
@@ -2,3 +2,15 @@ class APKMirrorScrapperFailure(Exception):
|
||||
"""Failed to scrap icon from apkmirror."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ExtraAssetsFailure(Exception):
|
||||
"""Failed to scrap icon from apkmirror."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class PatchingFailed(Exception):
|
||||
"""Patching Failed."""
|
||||
|
||||
pass
|
||||
|
||||
+2
-3
@@ -1,5 +1,4 @@
|
||||
"""Revanced Parser."""
|
||||
import sys
|
||||
from subprocess import PIPE, Popen
|
||||
from time import perf_counter
|
||||
from typing import List
|
||||
@@ -8,6 +7,7 @@ from loguru import logger
|
||||
|
||||
from src.app import APP
|
||||
from src.config import RevancedConfig
|
||||
from src.exceptions import PatchingFailed
|
||||
from src.patches import Patches
|
||||
from src.utils import possible_archs
|
||||
|
||||
@@ -112,8 +112,7 @@ class Parser(object):
|
||||
process = Popen(["java", *args], stdout=PIPE)
|
||||
output = process.stdout
|
||||
if not output:
|
||||
logger.error("Failed to send request for patching.")
|
||||
sys.exit(-1)
|
||||
raise PatchingFailed("Failed to send request for patching.")
|
||||
for line in output:
|
||||
logger.debug(line.decode(), flush=True, end="")
|
||||
process.wait()
|
||||
|
||||
+5
-9
@@ -8,6 +8,7 @@ from loguru import logger
|
||||
from requests import Response
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.exceptions import PatchingFailed
|
||||
|
||||
default_build = [
|
||||
"youtube",
|
||||
@@ -43,12 +44,6 @@ class AppNotFound(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class PatcherDownloadFailed(Exception):
|
||||
"""Not a valid Revanced App."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class PatchesJsonFailed(ValueError):
|
||||
"""Patches failed."""
|
||||
|
||||
@@ -59,8 +54,9 @@ def handle_response(response: Response) -> None:
|
||||
"""Handle Get Request Response."""
|
||||
response_code = response.status_code
|
||||
if response_code != 200:
|
||||
logger.error(response.text)
|
||||
exit(1)
|
||||
raise PatchingFailed(
|
||||
f"Unable to downloaded assets from GitHub. Reason - {response.text}"
|
||||
)
|
||||
|
||||
|
||||
def slugify(string: str) -> str:
|
||||
@@ -98,7 +94,7 @@ def check_java(dry_run: bool) -> None:
|
||||
raise subprocess.CalledProcessError(-1, "java -version")
|
||||
logger.debug("Cool!! Java is available")
|
||||
except subprocess.CalledProcessError:
|
||||
logger.debug("Java>= 17 Must be installed")
|
||||
logger.error("Java>= 17 Must be installed")
|
||||
exit(-1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user