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:
+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:
|
||||
|
||||
Reference in New Issue
Block a user