diff --git a/main.py b/main.py index fe7c9c6..241534a 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +"""Entry point.""" import sys from environs import Env @@ -10,6 +11,7 @@ from src.patches import Patches def main() -> None: + """Entry point.""" env = Env() config = RevancedConfig(env) diff --git a/src/config.py b/src/config.py index a7514d1..cb18fec 100644 --- a/src/config.py +++ b/src/config.py @@ -1,3 +1,4 @@ +"""Revanced Configurations.""" from pathlib import Path from typing import List @@ -8,6 +9,8 @@ from src.utils import supported_apps class RevancedConfig: + """Revanced Configurations.""" + def __init__(self, env: Env) -> None: self.env = env self.temp_folder = Path("apks") diff --git a/src/downloader.py b/src/downloader.py index fb11132..710fed6 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -1,3 +1,4 @@ +"""Downloader Class.""" import re import sys from concurrent.futures import ThreadPoolExecutor @@ -14,6 +15,8 @@ from src.config import RevancedConfig class Downloader(object): + """Files downloader.""" + def __init__(self, config: RevancedConfig): self._CHUNK_SIZE = 2**21 * 5 self._QUEUE: PriorityQueue[Tuple[float, str]] = PriorityQueue() @@ -43,6 +46,11 @@ class Downloader(object): logger.debug(f"Downloaded {file_name}") def extract_download_link(self, page: str, app: str) -> None: + """Function to extract the download link from apkmirror html page. + + :param page: Url of the page + :param app: Name of the app + """ logger.debug(f"Extracting download link from\n{page}") parser = LexborHTMLParser(self.config.session.get(page).text) @@ -58,6 +66,12 @@ class Downloader(object): 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. + + :param parser: Parser + :param main_page: Main Download Page in APK mirror(Index) + :return: + """ apm = parser.css(".apkm-badge") sub_url = "" for is_apm in apm: @@ -84,6 +98,12 @@ class Downloader(object): return app_version def apkmirror_specific_version(self, app: str, version: str) -> str: + """Function to download the specified version of app from apkmirror. + + :param app: Name of the application + :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/" @@ -94,6 +114,12 @@ class Downloader(object): return version def apkmirror_latest_version(self, app: str) -> str: + """Function to download whatever the latest version of app from + apkmirror. + + :param app: Name of the application + :return: Version of downloaded apk + """ logger.debug(f"Trying to download {app}'s latest version from apkmirror") page = self.config.apk_mirror_urls.get(app) if not page: @@ -119,6 +145,12 @@ class Downloader(object): return version def repository(self, owner: str, name: str, file_name: str) -> None: + """Function to download files from GitHub repositories. + + :param owner: github user/organization + :param name: name of the repository + :param file_name: name of the file after downloading + """ logger.debug(f"Trying to download {name} from github") repo_url = f"https://api.github.com/repos/{owner}/{name}/releases/latest" r = requests.get( @@ -131,6 +163,7 @@ class Downloader(object): self._download(download_url, file_name=file_name) def download_revanced(self) -> None: + """Download Revanced and Extended Patches, Integration and CLI.""" assets = [ ["revanced", "revanced-cli", self.config.normal_cli_jar], ["revanced", "revanced-integrations", self.config.normal_integrations_apk], @@ -148,15 +181,32 @@ class Downloader(object): logger.info("Downloaded revanced microG ,cli, integrations and patches.") def upto_down_downloader(self, app: str) -> str: + """Function to download from UptoDown. + + :param app: Name of the application + :return: Version of downloaded APK + """ return self.__upto_down_downloader(app) def download_from_apkmirror(self, version: str, app: str) -> str: + """Function to download from apkmirror. + + :param version: version to download + :param app: App to download + :return: Version of downloaded APK + """ if version and version != "latest": return self.apkmirror_specific_version(app, version) else: return self.apkmirror_latest_version(app) def download_apk_to_patch(self, version: str, app: str) -> str: + """Public function to download apk to patch. + + :param version: version to download + :param app: App to download + :return: Version of apk + """ if app in self.config.upto_down: return self.upto_down_downloader(app) else: diff --git a/src/parser.py b/src/parser.py index e3222f0..d9a483c 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,3 +1,4 @@ +"""Revanced Parser.""" import sys from subprocess import PIPE, Popen from time import perf_counter @@ -10,6 +11,8 @@ from src.patches import Patches class Parser(object): + """Revanced Parser.""" + def __init__(self, patcher: Patches, config: RevancedConfig) -> None: self._PATCHES: List[str] = [] self._EXCLUDED: List[str] = [] @@ -17,16 +20,34 @@ class Parser(object): self.config = config def include(self, name: str) -> None: + """Include a given patch. + + :param name: Name of the patch + """ self._PATCHES.extend(["-i", name]) def exclude(self, name: str) -> None: + """Exclude a given patch. + + :param name: Name of the patch to exclude + """ self._PATCHES.extend(["-e", name]) self._EXCLUDED.append(name) def get_excluded_patches(self) -> List[str]: + """ + Getter to get all excluded patches + :return: List of excluded patches + """ return self._EXCLUDED def patch_app(self, app: str, version: str, is_experimental: bool = False) -> None: + """Revanced APP Patcher. + + :param app: Name of the app + :param version: Version of the application + :param is_experimental: Whether to enable experimental support + """ logger.debug(f"Sending request to revanced cli for building {app} revanced") cli = self.config.normal_cli_jar patches = self.config.normal_patches_jar diff --git a/src/patches.py b/src/patches.py index e100d3f..1591fd5 100644 --- a/src/patches.py +++ b/src/patches.py @@ -1,3 +1,4 @@ +"""Revanced Patches.""" import subprocess import sys from typing import Any, Dict, List, Tuple @@ -9,7 +10,11 @@ from src.config import RevancedConfig class Patches(object): - def check_java(self) -> None: + """Revanced Patches.""" + + @staticmethod + def check_java() -> None: + """Check if Java17 is installed.""" logger.debug("Checking if java is available") jd = subprocess.check_output( ["java", "-version"], stderr=subprocess.STDOUT @@ -23,7 +28,9 @@ class Patches(object): exit(-1) logger.debug("Cool!! Java is available") + # noinspection DuplicatedCode def fetch_patches(self) -> None: + """Function to fetch all patches.""" session = Session() logger.debug("fetching all patches") @@ -93,6 +100,11 @@ class Patches(object): self.fetch_patches() def get(self, app: str) -> Tuple[List[Dict[str, str]], str]: + """Get all patches for the given app. + + :param app: Name of the application + :return: Patches + """ logger.debug("Getting patches for %s" % app) app_names = { "reddit": "_reddit", @@ -118,6 +130,12 @@ class Patches(object): def include_and_exclude_patches( self, app: str, arg_parser: Any, app_patches: List[Dict[str, str]] ) -> None: + """Include and exclude patches for a given app. + + :param app: Name of the app + :param arg_parser: Parser Obj + :param app_patches: All the patches of a given app + """ logger.debug(f"Excluding patches for app {app}") if self.config.build_extended and app in self.config.extended_apps: excluded_patches = self.config.env.list( @@ -136,6 +154,11 @@ class Patches(object): logger.debug(f"No excluded patches for {app}") def get_app_configs(self, app: str) -> Tuple[List[Dict[str, str]], str, bool]: + """Get Configurations for a given app. + + :param app: Name of the application + :return: All Patches , Its version and whether it is experimental + """ experiment = False total_patches, recommended_version = self.get(app=app) env_version = self.config.env.str(f"{app}_VERSION".upper(), None) diff --git a/src/utils.py b/src/utils.py index 1a18c0f..2509585 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,3 +1,4 @@ +"""Utilities.""" supported_apps = [ "youtube", "youtube_music",