mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
Merge pull request #255 from nikhilbadyal/issue-scrapper
✨ Added apkcombo scrapper
This commit is contained in:
+27
-12
@@ -8,10 +8,28 @@ from bs4 import BeautifulSoup
|
|||||||
from google_play_scraper import app as gplay_app
|
from google_play_scraper import app as gplay_app
|
||||||
from google_play_scraper.exceptions import GooglePlayScraperException
|
from google_play_scraper.exceptions import GooglePlayScraperException
|
||||||
|
|
||||||
|
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_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 = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||||
|
"AppleWebKit/537.36 (HTML, like Gecko)"
|
||||||
|
" Chrome/96.0.4664.93 Safari/537.36"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def apkcombo_scrapper(package_name: str) -> str:
|
||||||
|
"""Apkcombo scrapper."""
|
||||||
|
try:
|
||||||
|
apkcombo_url = f"https://apkcombo.com/genericApp/{package_name}"
|
||||||
|
r = requests.get(apkcombo_url, headers=headers, allow_redirects=True)
|
||||||
|
soup = BeautifulSoup(r.text, "html.parser")
|
||||||
|
url = soup.select_one("div.avatar > img")["data-src"]
|
||||||
|
return re.sub(r"=.*$", "", url)
|
||||||
|
except Exception:
|
||||||
|
return not_found_icon
|
||||||
|
|
||||||
|
|
||||||
def apkmirror_scrapper(package_name: str) -> str:
|
def apkmirror_scrapper(package_name: str) -> str:
|
||||||
@@ -30,11 +48,6 @@ def apkmirror_scrapper(package_name: str) -> str:
|
|||||||
).content
|
).content
|
||||||
)
|
)
|
||||||
if response["data"][0]["exists"]:
|
if response["data"][0]["exists"]:
|
||||||
headers = {
|
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko)"
|
|
||||||
" Chrome/96.0.4664.93 Safari/537.36"
|
|
||||||
}
|
|
||||||
search_url = f"{apk_mirror_base_url}/?s={package_name}"
|
search_url = f"{apk_mirror_base_url}/?s={package_name}"
|
||||||
r = requests.get(search_url, headers=headers)
|
r = requests.get(search_url, headers=headers)
|
||||||
soup = BeautifulSoup(r.text, "html.parser")
|
soup = BeautifulSoup(r.text, "html.parser")
|
||||||
@@ -51,7 +64,7 @@ def apkmirror_scrapper(package_name: str) -> str:
|
|||||||
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
|
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
|
||||||
)
|
)
|
||||||
return apk_mirror_url
|
return apk_mirror_url
|
||||||
return not_found_icon
|
raise APKMirrorScrapperFailure()
|
||||||
|
|
||||||
|
|
||||||
def gplay_icon_scrapper(package_name: str) -> str:
|
def gplay_icon_scrapper(package_name: str) -> str:
|
||||||
@@ -65,7 +78,10 @@ def gplay_icon_scrapper(package_name: str) -> str:
|
|||||||
return str(result["icon"])
|
return str(result["icon"])
|
||||||
raise GooglePlayScraperException()
|
raise GooglePlayScraperException()
|
||||||
except GooglePlayScraperException:
|
except GooglePlayScraperException:
|
||||||
|
try:
|
||||||
return apkmirror_scrapper(package_name)
|
return apkmirror_scrapper(package_name)
|
||||||
|
except APKMirrorScrapperFailure:
|
||||||
|
return apkcombo_scrapper(package_name)
|
||||||
except Exception:
|
except Exception:
|
||||||
return not_found_icon
|
return not_found_icon
|
||||||
|
|
||||||
@@ -75,16 +91,14 @@ def generate_markdown_table(data: List[List[str]]) -> str:
|
|||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
return "No data to generate table."
|
return "No data to generate table."
|
||||||
|
|
||||||
table = "| Package Name | App Icon | PlayStore link | APKMirror link| Supported?|\n"
|
table = "| Package Name | App Icon | PlayStore link | APKMirror link|APKCombo Link| Supported?|\n"
|
||||||
table += (
|
table += "|-------------|----------|----------------|---------------|------------------|----------|\n"
|
||||||
"|-------------|----------|----------------|---------------|------------|\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
if len(row) != 5:
|
if len(row) != 6:
|
||||||
raise ValueError("Each row must contain 4 columns of data.")
|
raise ValueError("Each row must contain 4 columns of data.")
|
||||||
|
|
||||||
table += f"| {row[0]} | {row[1]} | {row[2]} | {row[3]} |{row[4]} |\n"
|
table += f"| {row[0]} | {row[1]} | {row[2]} | {row[3]} |{row[4]} |{row[5]} |\n"
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
@@ -113,6 +127,7 @@ def main() -> None:
|
|||||||
f'<img src="{gplay_icon_scrapper(app)}" width=50 height=50>',
|
f'<img src="{gplay_icon_scrapper(app)}" width=50 height=50>',
|
||||||
f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})",
|
f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})",
|
||||||
f"[APKMirror Link](https://www.apkmirror.com/?s={app})",
|
f"[APKMirror Link](https://www.apkmirror.com/?s={app})",
|
||||||
|
f"[APKCombo Link](https://apkcombo.com/genericApp/{app})",
|
||||||
"<li>- [ ] </li>",
|
"<li>- [ ] </li>",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
class APKMirrorScrapperFailure(Exception):
|
||||||
|
"""Failed to scrap icon from apkmirror."""
|
||||||
|
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user