Added google drive downloader (#359)

This commit is contained in:
Nikhil Badyal
2023-08-31 11:46:23 +05:30
committed by GitHub
parent e2983d5b39
commit 6c0da4e45b
7 changed files with 48 additions and 4 deletions
+3
View File
@@ -225,6 +225,9 @@ You can use any of the following methods to build.
5. APKMonk - Supports downloading any available version 5. APKMonk - Supports downloading any available version
1. Link Format - https://www.apkmonk.com/app/<package-name>/ 1. Link Format - https://www.apkmonk.com/app/<package-name>/
2. Example Link - https://www.apkmonk.com/app/<package-name>/ 2. Example Link - https://www.apkmonk.com/app/<package-name>/
6. Google Drive - Supports downloading from Google Drive lint
1. Link Format - https://drive.google.com/uc?<id>
2. Example Link - https://drive.google.com/uc?id=1ad44UTghbDty8o36Nrp3ZMyUzkPckIqY
<br>Please verify the source of original APKs yourself with links provided. I'm not responsible for any damage <br>Please verify the source of original APKs yourself with links provided. I'm not responsible for any damage
caused.If you know any better/safe source to download clean. Open a discussion. caused.If you know any better/safe source to download clean. Open a discussion.
+2 -1
View File
@@ -52,7 +52,8 @@ ignore = [
"PTH122", #os-path-splitext "PTH122", #os-path-splitext
"TRY301", #raise-within-try "TRY301", #raise-within-try
"PERF203", #try-except-in-loop "PERF203", #try-except-in-loop
"UP004" #useless-object-inheritance "UP004", #useless-object-inheritance
"PLR0911" #too many returns
] ]
fix = true fix = true
show-fixes = true show-fixes = true
+1
View File
@@ -1,5 +1,6 @@
beautifulsoup4==4.12.2 beautifulsoup4==4.12.2
environs==9.5.0 environs==9.5.0
gdown @ git+https://github.com/nikhilbadyal/gdown
google-play-scraper==1.2.4 google-play-scraper==1.2.4
lastversion==3.0.1 lastversion==3.0.1
loguru==0.7.0 loguru==0.7.0
+2 -2
View File
@@ -16,10 +16,10 @@ class RevancedConfig(object):
def __init__(self: Self, env: Env) -> None: def __init__(self: Self, env: Env) -> None:
self.env = env self.env = env
self.temp_folder = Path("apks") self.temp_folder_name = "apks"
self.temp_folder = Path(self.temp_folder_name)
self.session = Session() self.session = Session()
self.ci_test = env.bool("CI_TEST", False) self.ci_test = env.bool("CI_TEST", False)
self.rip_libs_apps: List[str] = [] self.rip_libs_apps: List[str] = []
self.existing_downloaded_apks = env.list("EXISTING_DOWNLOADED_APKS", []) self.existing_downloaded_apks = env.list("EXISTING_DOWNLOADED_APKS", [])
self.personal_access_token = env.str("PERSONAL_ACCESS_TOKEN", None) self.personal_access_token = env.str("PERSONAL_ACCESS_TOKEN", None)
+5 -1
View File
@@ -6,11 +6,13 @@ from src.downloader.apkpure import ApkPure
from src.downloader.apksos import ApkSos from src.downloader.apksos import ApkSos
from src.downloader.download import Downloader from src.downloader.download import Downloader
from src.downloader.github import Github from src.downloader.github import Github
from src.downloader.google_drive import GoogleDrive
from src.downloader.sources import ( from src.downloader.sources import (
APK_MIRROR_BASE_URL, APK_MIRROR_BASE_URL,
APK_MONK_BASE_URL, APK_MONK_BASE_URL,
APK_PURE_BASE_URL, APK_PURE_BASE_URL,
APKS_SOS_BASE_URL, APKS_SOS_BASE_URL,
DRIVE_DOWNLOAD_BASE_URL,
GITHUB_BASE_URL, GITHUB_BASE_URL,
) )
from src.downloader.uptodown import UptoDown from src.downloader.uptodown import UptoDown
@@ -41,5 +43,7 @@ class DownloaderFactory(object):
return ApkMirror(config) return ApkMirror(config)
if apk_source.startswith(APK_MONK_BASE_URL): if apk_source.startswith(APK_MONK_BASE_URL):
return ApkMonk(config) return ApkMonk(config)
if apk_source.startswith(DRIVE_DOWNLOAD_BASE_URL):
return GoogleDrive(config)
msg = "No download factory found." msg = "No download factory found."
raise DownloadError(msg) raise DownloadError(msg, url=apk_source)
+31
View File
@@ -0,0 +1,31 @@
"""Google Drive downloader Class."""
from typing import Any, Self, Tuple
import gdown
from src.app import APP
from src.downloader.download import Downloader
class GoogleDrive(Downloader):
"""Google Driver downloader."""
def specific_version(self: Self, app: APP, version: str) -> Tuple[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
"""
return self.latest_version(app)
def latest_version(self: Self, app: APP, **kwargs: Any) -> Tuple[str, str]:
"""Function to download whatever the latest version of app from Google Driver.
:param app: Name of the application
:return: Version of downloaded apk
"""
url = app.download_source
file_name = f"{self.config.temp_folder_name}/{app.app_name}.apk"
_, download_url = gdown.download(url, quiet=False, use_cookies=False, output=file_name)
return file_name, download_url
+4
View File
@@ -1,4 +1,5 @@
"""APK Sources used.""" """APK Sources used."""
APK_MIRROR_BASE_URL = "https://www.apkmirror.com" APK_MIRROR_BASE_URL = "https://www.apkmirror.com"
APK_MIRROR_BASE_APK_URL = f"{APK_MIRROR_BASE_URL}/apk" APK_MIRROR_BASE_APK_URL = f"{APK_MIRROR_BASE_URL}/apk"
APK_MIRROR_PACKAGE_URL = f"{APK_MIRROR_BASE_URL}/?s=" + "{}" APK_MIRROR_PACKAGE_URL = f"{APK_MIRROR_BASE_URL}/?s=" + "{}"
@@ -20,6 +21,9 @@ revanced_api = "https://api.revanced.app/v2/patches/latest"
APK_MONK_BASE_URL = "https://www.apkmonk.com" APK_MONK_BASE_URL = "https://www.apkmonk.com"
APK_MONK_APK_URL = APK_MONK_BASE_URL + "/app/{}/" APK_MONK_APK_URL = APK_MONK_BASE_URL + "/app/{}/"
APK_MONK_ICON_URL = "https://cdn.apkmonk.com/logos/{}" APK_MONK_ICON_URL = "https://cdn.apkmonk.com/logos/{}"
DRIVE_BASE_URL = "https://drive.google.com"
DRIVE_DOWNLOAD_BASE_URL = f"{DRIVE_BASE_URL}/uc?id="
DRIVE_DOWNLOAD_URL = DRIVE_DOWNLOAD_BASE_URL + "{}"
apk_sources = { apk_sources = {
"backdrops": f"{APK_MIRROR_BASE_APK_URL}/backdrops/backdrops-wallpapers/", "backdrops": f"{APK_MIRROR_BASE_APK_URL}/backdrops/backdrops-wallpapers/",
"bacon": f"{APK_MIRROR_BASE_APK_URL}/onelouder-apps/baconreader-for-reddit/", "bacon": f"{APK_MIRROR_BASE_APK_URL}/onelouder-apps/baconreader-for-reddit/",