mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
Merge pull request #111 from nikhilbadyal/rate-limit-gh
✨ Ability to provide GitHub Access Token to bypass GitHub Rate Limit.
This commit is contained in:
@@ -36,6 +36,11 @@ on:
|
||||
type: boolean
|
||||
required: false
|
||||
default: true
|
||||
DEBUG_ENABLED:
|
||||
type: boolean
|
||||
description: 'Run the build with tmate debugging enabled.'
|
||||
required: false
|
||||
default: false
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.head_ref || github.run_id }}
|
||||
@@ -45,6 +50,7 @@ jobs:
|
||||
uses: ./.github/workflows/build-artifact.yml
|
||||
with:
|
||||
COMMIT_CHANGELOG: ${{ inputs.COMMIT_CHANGELOG }}
|
||||
DEBUG_ENABLED: ${{ inputs.DEBUG_ENABLED }}
|
||||
secrets:
|
||||
ENVS: ${{ secrets.ENVS }}
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ on:
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
DEBUG_ENABLED:
|
||||
type: boolean
|
||||
description: 'Run the build with tmate debugging enabled.'
|
||||
required: false
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
build-apk:
|
||||
@@ -37,9 +42,13 @@ jobs:
|
||||
run: |
|
||||
echo "${{ secrets.ENVS }}" >> .env
|
||||
|
||||
- name: Setup tmate session
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.DEBUG_ENABLED }}
|
||||
|
||||
- name: Build Revanced APKs
|
||||
run: |
|
||||
docker-compose up
|
||||
docker-compose up --build
|
||||
|
||||
- name: Upload Build APKS
|
||||
uses: nikhilbadyal/upload-artifact@count-check
|
||||
|
||||
@@ -20,3 +20,4 @@ jobs:
|
||||
ENVS: |
|
||||
CI_TEST=True
|
||||
ES_JAVA_OPTS: '-Xms4g -Xmx4g'
|
||||
PERSONAL_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -5,3 +5,4 @@ venv
|
||||
*/__pycache__*
|
||||
*.pyc
|
||||
/revanced-cache/
|
||||
changelog.md
|
||||
|
||||
@@ -260,7 +260,12 @@ By default, script build the version as recommended by Revanced team.
|
||||
`/apks` folder.
|
||||
|
||||
Name of the downloaded apk must match with the available app choices found [here.](#note)
|
||||
14. Sample Envs<br>
|
||||
14. If you run script again & again. You might hit GitHub API limit. In that case you can provide your Personal
|
||||
GitHub Access Token in `.env` file or in `ENVS` in `GitHub secrets` (Recommended) in the format -
|
||||
```dotenv
|
||||
PERSONAL_ACCESS_TOKEN=<PAT>
|
||||
```
|
||||
15. Sample Envs<br>
|
||||
<img src="https://i.imgur.com/ajSE5nA.png" width="600" style="left">
|
||||
|
||||
Thanks to [@aliharslan0](https://github.com/aliharslan0/pyrevanced) for his work.
|
||||
|
||||
@@ -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)
|
||||
|
||||
+28
-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,19 @@ 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 and "github" in url:
|
||||
logger.debug("Using 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 +54,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))
|
||||
@@ -176,7 +187,7 @@ class Downloader(object):
|
||||
match = re.search(r"\d", main_page)
|
||||
if not match:
|
||||
logger.error("Cannot find app main page")
|
||||
sys.exit(-1)
|
||||
raise AppNotFound()
|
||||
int_version = match.start()
|
||||
extra_release = main_page.rfind("release") - 1
|
||||
version: str = main_page[int_version:extra_release]
|
||||
@@ -197,14 +208,21 @@ 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:
|
||||
logger.debug("Using 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