mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
✨ Ability to provide GitHub Access Token to bypass GitHub Rate Limit.
This commit is contained in:
@@ -84,3 +84,4 @@ class RevancedConfig:
|
||||
"ALTERNATIVE_YOUTUBE_MUSIC_PATCHES", []
|
||||
)
|
||||
self.existing_downloaded_apks = env.list("EXISTING_DOWNLOADED_APKS", [])
|
||||
self.personal_access_token = env.str("PERSONAL_ACCESS_TOKEN", None)
|
||||
|
||||
+26
-10
@@ -14,7 +14,7 @@ from tqdm import tqdm
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.patches import Patches
|
||||
from src.utils import AppNotFound, update_changelog
|
||||
from src.utils import AppNotFound, handle_response, update_changelog
|
||||
|
||||
|
||||
class Downloader(object):
|
||||
@@ -32,8 +32,18 @@ class Downloader(object):
|
||||
logger.debug(f"Trying to download {file_name} from {url}")
|
||||
self._QUEUE_LENGTH += 1
|
||||
start = perf_counter()
|
||||
resp = self.config.session.get(url, stream=True)
|
||||
total = int(resp.headers.get("content-length", 0))
|
||||
headers = {}
|
||||
if self.config.personal_access_token:
|
||||
headers.update(
|
||||
{"Authorization": "token " + self.config.personal_access_token}
|
||||
)
|
||||
response = self.config.session.get(
|
||||
url,
|
||||
stream=True,
|
||||
headers=headers,
|
||||
)
|
||||
handle_response(response)
|
||||
total = int(response.headers.get("content-length", 0))
|
||||
bar = tqdm(
|
||||
desc=file_name,
|
||||
total=total,
|
||||
@@ -43,7 +53,7 @@ class Downloader(object):
|
||||
colour="green",
|
||||
)
|
||||
with self.config.temp_folder.joinpath(file_name).open("wb") as dl_file, bar:
|
||||
for chunk in resp.iter_content(self._CHUNK_SIZE):
|
||||
for chunk in response.iter_content(self._CHUNK_SIZE):
|
||||
size = dl_file.write(chunk)
|
||||
bar.update(size)
|
||||
self._QUEUE.put((perf_counter() - start, file_name))
|
||||
@@ -197,14 +207,20 @@ class Downloader(object):
|
||||
"""
|
||||
logger.debug(f"Trying to download {name} from github")
|
||||
repo_url = f"https://api.github.com/repos/{owner}/{name}/releases/latest"
|
||||
r = requests.get(
|
||||
repo_url, headers={"Content-Type": "application/vnd.github.v3+json"}
|
||||
)
|
||||
headers = {
|
||||
"Content-Type": "application/vnd.github.v3+json",
|
||||
}
|
||||
if self.config.personal_access_token:
|
||||
headers.update(
|
||||
{"Authorization": "token " + self.config.personal_access_token}
|
||||
)
|
||||
response = requests.get(repo_url, headers=headers)
|
||||
handle_response(response)
|
||||
if name == "revanced-patches":
|
||||
download_url = r.json()["assets"][1]["browser_download_url"]
|
||||
download_url = response.json()["assets"][1]["browser_download_url"]
|
||||
else:
|
||||
download_url = r.json()["assets"][0]["browser_download_url"]
|
||||
update_changelog(f"{owner}/{name}", r.json())
|
||||
download_url = response.json()["assets"][0]["browser_download_url"]
|
||||
update_changelog(f"{owner}/{name}", response.json())
|
||||
self._download(download_url, file_name=file_name)
|
||||
|
||||
def download_revanced(self) -> None:
|
||||
|
||||
+7
-5
@@ -6,7 +6,7 @@ from loguru import logger
|
||||
from requests import Session
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.utils import AppNotFound
|
||||
from src.utils import AppNotFound, handle_response
|
||||
|
||||
|
||||
class Patches(object):
|
||||
@@ -60,10 +60,11 @@ class Patches(object):
|
||||
session = Session()
|
||||
|
||||
logger.debug("fetching all patches")
|
||||
resp = session.get(
|
||||
response = session.get(
|
||||
"https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json"
|
||||
)
|
||||
patches = resp.json()
|
||||
handle_response(response)
|
||||
patches = response.json()
|
||||
|
||||
for app_name in (self.revanced_app_ids[x][1] for x in self.revanced_app_ids):
|
||||
setattr(self, app_name, [])
|
||||
@@ -83,8 +84,9 @@ class Patches(object):
|
||||
else:
|
||||
url = "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json"
|
||||
|
||||
resp_extended = session.get(url)
|
||||
extended_patches = resp_extended.json()
|
||||
response = session.get(url)
|
||||
handle_response(response)
|
||||
extended_patches = response.json()
|
||||
for app_name in (
|
||||
self.revanced_extended_app_ids[x][1] for x in self.revanced_extended_app_ids
|
||||
):
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""Utilities."""
|
||||
from typing import Dict
|
||||
|
||||
from loguru import logger
|
||||
from requests import Response
|
||||
|
||||
default_build = [
|
||||
"youtube",
|
||||
]
|
||||
@@ -55,3 +58,10 @@ class AppNotFound(ValueError):
|
||||
"""Not a valid Revanced App."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def handle_response(response: Response) -> None:
|
||||
"""Handle Get Request Response."""
|
||||
response_code = response.status_code
|
||||
if response_code != 200:
|
||||
logger.info(response.text)
|
||||
|
||||
Reference in New Issue
Block a user