mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
🎨 Output app dl (#301)
This commit is contained in:
@@ -34,7 +34,9 @@ def main() -> None:
|
|||||||
downloader = DownloaderFactory.create_downloader(
|
downloader = DownloaderFactory.create_downloader(
|
||||||
app=app.app_name, patcher=patcher, config=config
|
app=app.app_name, patcher=patcher, config=config
|
||||||
)
|
)
|
||||||
app.download_file_name = downloader.download(app.app_version, app.app_name)
|
app.download_file_name, app.download_dl = downloader.download(
|
||||||
|
app.app_version, app.app_name
|
||||||
|
)
|
||||||
logger.info(app)
|
logger.info(app)
|
||||||
parser.patch_app(app)
|
parser.patch_app(app)
|
||||||
except AppNotFound as e:
|
except AppNotFound as e:
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class APP(object):
|
|||||||
f"{app_name}_ARCHS_TO_BUILD".upper(), config.global_archs_to_build
|
f"{app_name}_ARCHS_TO_BUILD".upper(), config.global_archs_to_build
|
||||||
)
|
)
|
||||||
self.download_file_name = None
|
self.download_file_name = None
|
||||||
|
self.download_dl = None
|
||||||
self.download_patch_resources(config)
|
self.download_patch_resources(config)
|
||||||
|
|
||||||
def get_output_file_name(self) -> str:
|
def get_output_file_name(self) -> str:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""Downloader Class."""
|
"""Downloader Class."""
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup, Tag
|
from bs4 import BeautifulSoup, Tag
|
||||||
@@ -14,7 +14,7 @@ from src.utils import bs4_parser, contains_any_word, request_header
|
|||||||
class ApkMirror(Downloader):
|
class ApkMirror(Downloader):
|
||||||
"""Files downloader."""
|
"""Files downloader."""
|
||||||
|
|
||||||
def _extract_force_download_link(self, link: str, app: str) -> str:
|
def _extract_force_download_link(self, link: str, app: str) -> Tuple[str, str]:
|
||||||
"""Extract force download link."""
|
"""Extract force download link."""
|
||||||
notes_divs = self._extracted_search_div(link, "tab-pane")
|
notes_divs = self._extracted_search_div(link, "tab-pane")
|
||||||
apk_type = self._extracted_search_div(link, "apkm-badge").get_text()
|
apk_type = self._extracted_search_div(link, "apkm-badge").get_text()
|
||||||
@@ -26,12 +26,12 @@ class ApkMirror(Downloader):
|
|||||||
):
|
):
|
||||||
file_name = f"{app}.{extension}"
|
file_name = f"{app}.{extension}"
|
||||||
self._download(APK_MIRROR_BASE_URL + possible_link["href"], file_name)
|
self._download(APK_MIRROR_BASE_URL + possible_link["href"], file_name)
|
||||||
return file_name
|
return file_name, APK_MIRROR_BASE_URL + possible_link["href"]
|
||||||
raise APKMirrorAPKDownloadFailure(
|
raise APKMirrorAPKDownloadFailure(
|
||||||
f"Unable to extract force download for {app}", url=link
|
f"Unable to extract force download for {app}", url=link
|
||||||
)
|
)
|
||||||
|
|
||||||
def extract_download_link(self, page: str, app: str) -> str:
|
def extract_download_link(self, page: str, app: str) -> Tuple[str, str]:
|
||||||
"""Function to extract the download link from apkmirror html page.
|
"""Function to extract the download link from apkmirror html page.
|
||||||
|
|
||||||
:param page: Url of the page
|
:param page: Url of the page
|
||||||
@@ -93,7 +93,9 @@ class ApkMirror(Downloader):
|
|||||||
soup = BeautifulSoup(r.text, bs4_parser)
|
soup = BeautifulSoup(r.text, bs4_parser)
|
||||||
return soup.find(class_=search_class)
|
return soup.find(class_=search_class)
|
||||||
|
|
||||||
def specific_version(self, app: str, version: str, main_page: str = "") -> str:
|
def specific_version(
|
||||||
|
self, app: str, version: str, main_page: str = ""
|
||||||
|
) -> Tuple[str, str]:
|
||||||
"""Function to download the specified version of app from apkmirror.
|
"""Function to download the specified version of app from apkmirror.
|
||||||
|
|
||||||
:param app: Name of the application
|
:param app: Name of the application
|
||||||
@@ -109,7 +111,7 @@ class ApkMirror(Downloader):
|
|||||||
download_page = self.get_download_page(main_page)
|
download_page = self.get_download_page(main_page)
|
||||||
return self.extract_download_link(download_page, app)
|
return self.extract_download_link(download_page, app)
|
||||||
|
|
||||||
def latest_version(self, app: str, **kwargs: Any) -> str:
|
def latest_version(self, app: str, **kwargs: Any) -> Tuple[str, str]:
|
||||||
"""Function to download whatever the latest version of app from
|
"""Function to download whatever the latest version of app from
|
||||||
apkmirror.
|
apkmirror.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""APK Pure Downloader Class."""
|
"""APK Pure Downloader Class."""
|
||||||
from typing import Any
|
from typing import Any, Tuple
|
||||||
|
|
||||||
from src.downloader.download import Downloader
|
from src.downloader.download import Downloader
|
||||||
from src.downloader.sources import apk_sources
|
from src.downloader.sources import apk_sources
|
||||||
@@ -9,7 +9,7 @@ from src.patches import Patches
|
|||||||
class ApkPure(Downloader):
|
class ApkPure(Downloader):
|
||||||
"""Files downloader."""
|
"""Files downloader."""
|
||||||
|
|
||||||
def latest_version(self, app: str, **kwargs: Any) -> str:
|
def latest_version(self, app: str, **kwargs: Any) -> Tuple[str, str]:
|
||||||
"""Function to download whatever the latest version of app from
|
"""Function to download whatever the latest version of app from
|
||||||
apkmirror.
|
apkmirror.
|
||||||
|
|
||||||
@@ -20,4 +20,4 @@ class ApkPure(Downloader):
|
|||||||
download_url = apk_sources[app].format(package_name)
|
download_url = apk_sources[app].format(package_name)
|
||||||
file_name = f"{app}.apk"
|
file_name = f"{app}.apk"
|
||||||
self._download(download_url, file_name)
|
self._download(download_url, file_name)
|
||||||
return file_name
|
return file_name, download_url
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""APK SOS Downloader Class."""
|
"""APK SOS Downloader Class."""
|
||||||
from typing import Any
|
from typing import Any, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@@ -13,7 +13,7 @@ from src.utils import bs4_parser, request_header
|
|||||||
class ApkSos(Downloader):
|
class ApkSos(Downloader):
|
||||||
"""Files downloader."""
|
"""Files downloader."""
|
||||||
|
|
||||||
def extract_download_link(self, page: str, app: str) -> str:
|
def extract_download_link(self, page: str, app: str) -> Tuple[str, str]:
|
||||||
"""Function to extract the download link from apkmirror html page.
|
"""Function to extract the download link from apkmirror html page.
|
||||||
|
|
||||||
:param page: Url of the page
|
:param page: Url of the page
|
||||||
@@ -27,10 +27,10 @@ class ApkSos(Downloader):
|
|||||||
if possible_link.get("href"):
|
if possible_link.get("href"):
|
||||||
file_name = f"{app}.apk"
|
file_name = f"{app}.apk"
|
||||||
self._download(possible_link["href"], file_name)
|
self._download(possible_link["href"], file_name)
|
||||||
return file_name
|
return file_name, possible_link["href"]
|
||||||
raise APKSosAPKDownloadFailure(f"Unable to download {app}", url=page)
|
raise APKSosAPKDownloadFailure(f"Unable to download {app}", url=page)
|
||||||
|
|
||||||
def latest_version(self, app: str, **kwargs: Any) -> str:
|
def latest_version(self, app: str, **kwargs: Any) -> Tuple[str, str]:
|
||||||
"""Function to download whatever the latest version of app from
|
"""Function to download whatever the latest version of app from
|
||||||
apkmirror.
|
apkmirror.
|
||||||
|
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ class Downloader(object):
|
|||||||
self._QUEUE.put((perf_counter() - start, file_name))
|
self._QUEUE.put((perf_counter() - start, file_name))
|
||||||
logger.debug(f"Downloaded {file_name}")
|
logger.debug(f"Downloaded {file_name}")
|
||||||
|
|
||||||
def extract_download_link(self, page: str, app: str) -> str:
|
def extract_download_link(self, page: str, app: str) -> Tuple[str, str]:
|
||||||
"""Extract download link from web page."""
|
"""Extract download link from web page."""
|
||||||
raise NotImplementedError(implement_method)
|
raise NotImplementedError(implement_method)
|
||||||
|
|
||||||
def specific_version(self, app: str, version: str) -> str:
|
def specific_version(self, app: str, version: str) -> Tuple[str, str]:
|
||||||
"""Function to download the specified version of app from apkmirror.
|
"""Function to download the specified version of app from apkmirror.
|
||||||
|
|
||||||
:param app: Name of the application
|
:param app: Name of the application
|
||||||
@@ -85,7 +85,7 @@ class Downloader(object):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError(implement_method)
|
raise NotImplementedError(implement_method)
|
||||||
|
|
||||||
def latest_version(self, app: str, **kwargs: Any) -> str:
|
def latest_version(self, app: str, **kwargs: Any) -> Tuple[str, str]:
|
||||||
"""Function to download the latest version of app.
|
"""Function to download the latest version of app.
|
||||||
|
|
||||||
:param app: Name of the application
|
:param app: Name of the application
|
||||||
@@ -123,22 +123,22 @@ class Downloader(object):
|
|||||||
base_name, _ = os.path.splitext(filename)
|
base_name, _ = os.path.splitext(filename)
|
||||||
return base_name + new_extension
|
return base_name + new_extension
|
||||||
|
|
||||||
def download(self, version: str, app: str, **kwargs: Any) -> str:
|
def download(self, version: str, app: str, **kwargs: Any) -> Tuple[str, str]:
|
||||||
"""Public function to download apk to patch.
|
"""Public function to download apk to patch.
|
||||||
|
|
||||||
:param version: version to download
|
:param version: version to download
|
||||||
:param app: App to download
|
:param app: App to download
|
||||||
"""
|
"""
|
||||||
if self.config.dry_run:
|
if self.config.dry_run:
|
||||||
return ""
|
return "", ""
|
||||||
if app in self.config.existing_downloaded_apks:
|
if app in self.config.existing_downloaded_apks:
|
||||||
logger.debug(f"Will not download {app} -v{version} from the internet.")
|
logger.debug(f"Will not download {app} -v{version} from the internet.")
|
||||||
return app
|
return app, f"local://{app}"
|
||||||
if version and version != "latest":
|
if version and version != "latest":
|
||||||
file_name = self.specific_version(app, version)
|
file_name, app_dl = self.specific_version(app, version)
|
||||||
else:
|
else:
|
||||||
file_name = self.latest_version(app, **kwargs)
|
file_name, app_dl = self.latest_version(app, **kwargs)
|
||||||
return self.convert_to_apk(file_name)
|
return self.convert_to_apk(file_name), app_dl
|
||||||
|
|
||||||
def direct_download(self, dl: str, file_name: str) -> None:
|
def direct_download(self, dl: str, file_name: str) -> None:
|
||||||
"""Download from DL."""
|
"""Download from DL."""
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from src.utils import handle_request_response, update_changelog
|
|||||||
class Github(Downloader):
|
class Github(Downloader):
|
||||||
"""Files downloader."""
|
"""Files downloader."""
|
||||||
|
|
||||||
def latest_version(self, app: str, **kwargs: Dict[str, str]) -> str:
|
def latest_version(self, app: str, **kwargs: Dict[str, str]) -> Tuple[str, str]:
|
||||||
"""Function to download files from GitHub repositories.
|
"""Function to download files from GitHub repositories.
|
||||||
|
|
||||||
:param app: App to download
|
:param app: App to download
|
||||||
@@ -25,7 +25,7 @@ class Github(Downloader):
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
f"Skipping download of {app}. File already exists or dry running."
|
f"Skipping download of {app}. File already exists or dry running."
|
||||||
)
|
)
|
||||||
return app
|
return app, f"local://{app}"
|
||||||
owner = str(kwargs["owner"])
|
owner = str(kwargs["owner"])
|
||||||
repo_name = str(kwargs["name"])
|
repo_name = str(kwargs["name"])
|
||||||
repo_url = f"https://api.github.com/repos/{owner}/{repo_name}/releases/latest"
|
repo_url = f"https://api.github.com/repos/{owner}/{repo_name}/releases/latest"
|
||||||
@@ -43,7 +43,7 @@ class Github(Downloader):
|
|||||||
download_url = response.json()["assets"][0]["browser_download_url"]
|
download_url = response.json()["assets"][0]["browser_download_url"]
|
||||||
update_changelog(f"{owner}/{repo_name}", response.json())
|
update_changelog(f"{owner}/{repo_name}", response.json())
|
||||||
self._download(download_url, file_name=app)
|
self._download(download_url, file_name=app)
|
||||||
return app
|
return app, download_url
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_repo_owner_and_tag(url: str) -> Tuple[str, str, str]:
|
def _extract_repo_owner_and_tag(url: str) -> Tuple[str, str, str]:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""Upto Down Downloader."""
|
"""Upto Down Downloader."""
|
||||||
from typing import Any
|
from typing import Any, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@@ -14,7 +14,7 @@ from src.utils import bs4_parser, request_header
|
|||||||
class UptoDown(Downloader):
|
class UptoDown(Downloader):
|
||||||
"""Files downloader."""
|
"""Files downloader."""
|
||||||
|
|
||||||
def extract_download_link(self, page: str, app: str) -> str:
|
def extract_download_link(self, page: str, app: str) -> Tuple[str, str]:
|
||||||
r = requests.get(page, headers=request_header, allow_redirects=True, timeout=60)
|
r = requests.get(page, headers=request_header, allow_redirects=True, timeout=60)
|
||||||
soup = BeautifulSoup(r.text, bs4_parser)
|
soup = BeautifulSoup(r.text, bs4_parser)
|
||||||
soup = soup.find(id="detail-download-button")
|
soup = soup.find(id="detail-download-button")
|
||||||
@@ -25,9 +25,9 @@ class UptoDown(Downloader):
|
|||||||
)
|
)
|
||||||
file_name = f"{app}.apk"
|
file_name = f"{app}.apk"
|
||||||
self._download(download_url, file_name)
|
self._download(download_url, file_name)
|
||||||
return file_name
|
return file_name, download_url
|
||||||
|
|
||||||
def specific_version(self, app: str, version: str) -> str:
|
def specific_version(self, app: str, version: str) -> Tuple[str, str]:
|
||||||
"""Function to download the specified version of app from apkmirror.
|
"""Function to download the specified version of app from apkmirror.
|
||||||
|
|
||||||
:param app: Name of the application
|
:param app: Name of the application
|
||||||
@@ -51,6 +51,6 @@ class UptoDown(Downloader):
|
|||||||
)
|
)
|
||||||
return self.extract_download_link(download_url, app)
|
return self.extract_download_link(download_url, app)
|
||||||
|
|
||||||
def latest_version(self, app: str, **kwargs: Any) -> str:
|
def latest_version(self, app: str, **kwargs: Any) -> Tuple[str, str]:
|
||||||
page = f"{apk_sources[app]}/download"
|
page = f"{apk_sources[app]}/download"
|
||||||
return self.extract_download_link(page, app)
|
return self.extract_download_link(page, app)
|
||||||
|
|||||||
Reference in New Issue
Block a user