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
|
type: boolean
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
|
DEBUG_ENABLED:
|
||||||
|
type: boolean
|
||||||
|
description: 'Run the build with tmate debugging enabled.'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.head_ref || github.run_id }}
|
group: ${{ github.head_ref || github.run_id }}
|
||||||
@@ -45,6 +50,7 @@ jobs:
|
|||||||
uses: ./.github/workflows/build-artifact.yml
|
uses: ./.github/workflows/build-artifact.yml
|
||||||
with:
|
with:
|
||||||
COMMIT_CHANGELOG: ${{ inputs.COMMIT_CHANGELOG }}
|
COMMIT_CHANGELOG: ${{ inputs.COMMIT_CHANGELOG }}
|
||||||
|
DEBUG_ENABLED: ${{ inputs.DEBUG_ENABLED }}
|
||||||
secrets:
|
secrets:
|
||||||
ENVS: ${{ secrets.ENVS }}
|
ENVS: ${{ secrets.ENVS }}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ on:
|
|||||||
type: boolean
|
type: boolean
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
|
DEBUG_ENABLED:
|
||||||
|
type: boolean
|
||||||
|
description: 'Run the build with tmate debugging enabled.'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-apk:
|
build-apk:
|
||||||
@@ -37,9 +42,13 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "${{ secrets.ENVS }}" >> .env
|
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
|
- name: Build Revanced APKs
|
||||||
run: |
|
run: |
|
||||||
docker-compose up
|
docker-compose up --build
|
||||||
|
|
||||||
- name: Upload Build APKS
|
- name: Upload Build APKS
|
||||||
uses: nikhilbadyal/upload-artifact@count-check
|
uses: nikhilbadyal/upload-artifact@count-check
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ jobs:
|
|||||||
ENVS: |
|
ENVS: |
|
||||||
CI_TEST=True
|
CI_TEST=True
|
||||||
ES_JAVA_OPTS: '-Xms4g -Xmx4g'
|
ES_JAVA_OPTS: '-Xms4g -Xmx4g'
|
||||||
|
PERSONAL_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ venv
|
|||||||
*/__pycache__*
|
*/__pycache__*
|
||||||
*.pyc
|
*.pyc
|
||||||
/revanced-cache/
|
/revanced-cache/
|
||||||
|
changelog.md
|
||||||
|
|||||||
@@ -260,7 +260,12 @@ By default, script build the version as recommended by Revanced team.
|
|||||||
`/apks` folder.
|
`/apks` folder.
|
||||||
|
|
||||||
Name of the downloaded apk must match with the available app choices found [here.](#note)
|
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">
|
<img src="https://i.imgur.com/ajSE5nA.png" width="600" style="left">
|
||||||
|
|
||||||
Thanks to [@aliharslan0](https://github.com/aliharslan0/pyrevanced) for his work.
|
Thanks to [@aliharslan0](https://github.com/aliharslan0/pyrevanced) for his work.
|
||||||
|
|||||||
@@ -84,3 +84,4 @@ class RevancedConfig:
|
|||||||
"ALTERNATIVE_YOUTUBE_MUSIC_PATCHES", []
|
"ALTERNATIVE_YOUTUBE_MUSIC_PATCHES", []
|
||||||
)
|
)
|
||||||
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)
|
||||||
|
|||||||
+29
-11
@@ -14,7 +14,7 @@ from tqdm import tqdm
|
|||||||
|
|
||||||
from src.config import RevancedConfig
|
from src.config import RevancedConfig
|
||||||
from src.patches import Patches
|
from src.patches import Patches
|
||||||
from src.utils import AppNotFound, update_changelog
|
from src.utils import AppNotFound, handle_response, update_changelog
|
||||||
|
|
||||||
|
|
||||||
class Downloader(object):
|
class Downloader(object):
|
||||||
@@ -32,8 +32,19 @@ class Downloader(object):
|
|||||||
logger.debug(f"Trying to download {file_name} from {url}")
|
logger.debug(f"Trying to download {file_name} from {url}")
|
||||||
self._QUEUE_LENGTH += 1
|
self._QUEUE_LENGTH += 1
|
||||||
start = perf_counter()
|
start = perf_counter()
|
||||||
resp = self.config.session.get(url, stream=True)
|
headers = {}
|
||||||
total = int(resp.headers.get("content-length", 0))
|
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(
|
bar = tqdm(
|
||||||
desc=file_name,
|
desc=file_name,
|
||||||
total=total,
|
total=total,
|
||||||
@@ -43,7 +54,7 @@ class Downloader(object):
|
|||||||
colour="green",
|
colour="green",
|
||||||
)
|
)
|
||||||
with self.config.temp_folder.joinpath(file_name).open("wb") as dl_file, bar:
|
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)
|
size = dl_file.write(chunk)
|
||||||
bar.update(size)
|
bar.update(size)
|
||||||
self._QUEUE.put((perf_counter() - start, file_name))
|
self._QUEUE.put((perf_counter() - start, file_name))
|
||||||
@@ -176,7 +187,7 @@ class Downloader(object):
|
|||||||
match = re.search(r"\d", main_page)
|
match = re.search(r"\d", main_page)
|
||||||
if not match:
|
if not match:
|
||||||
logger.error("Cannot find app main page")
|
logger.error("Cannot find app main page")
|
||||||
sys.exit(-1)
|
raise AppNotFound()
|
||||||
int_version = match.start()
|
int_version = match.start()
|
||||||
extra_release = main_page.rfind("release") - 1
|
extra_release = main_page.rfind("release") - 1
|
||||||
version: str = main_page[int_version:extra_release]
|
version: str = main_page[int_version:extra_release]
|
||||||
@@ -197,14 +208,21 @@ class Downloader(object):
|
|||||||
"""
|
"""
|
||||||
logger.debug(f"Trying to download {name} from github")
|
logger.debug(f"Trying to download {name} from github")
|
||||||
repo_url = f"https://api.github.com/repos/{owner}/{name}/releases/latest"
|
repo_url = f"https://api.github.com/repos/{owner}/{name}/releases/latest"
|
||||||
r = requests.get(
|
headers = {
|
||||||
repo_url, headers={"Content-Type": "application/vnd.github.v3+json"}
|
"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":
|
if name == "revanced-patches":
|
||||||
download_url = r.json()["assets"][1]["browser_download_url"]
|
download_url = response.json()["assets"][1]["browser_download_url"]
|
||||||
else:
|
else:
|
||||||
download_url = r.json()["assets"][0]["browser_download_url"]
|
download_url = response.json()["assets"][0]["browser_download_url"]
|
||||||
update_changelog(f"{owner}/{name}", r.json())
|
update_changelog(f"{owner}/{name}", response.json())
|
||||||
self._download(download_url, file_name=file_name)
|
self._download(download_url, file_name=file_name)
|
||||||
|
|
||||||
def download_revanced(self) -> None:
|
def download_revanced(self) -> None:
|
||||||
|
|||||||
+7
-5
@@ -6,7 +6,7 @@ from loguru import logger
|
|||||||
from requests import Session
|
from requests import Session
|
||||||
|
|
||||||
from src.config import RevancedConfig
|
from src.config import RevancedConfig
|
||||||
from src.utils import AppNotFound
|
from src.utils import AppNotFound, handle_response
|
||||||
|
|
||||||
|
|
||||||
class Patches(object):
|
class Patches(object):
|
||||||
@@ -60,10 +60,11 @@ class Patches(object):
|
|||||||
session = Session()
|
session = Session()
|
||||||
|
|
||||||
logger.debug("fetching all patches")
|
logger.debug("fetching all patches")
|
||||||
resp = session.get(
|
response = session.get(
|
||||||
"https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json"
|
"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):
|
for app_name in (self.revanced_app_ids[x][1] for x in self.revanced_app_ids):
|
||||||
setattr(self, app_name, [])
|
setattr(self, app_name, [])
|
||||||
@@ -83,8 +84,9 @@ class Patches(object):
|
|||||||
else:
|
else:
|
||||||
url = "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json"
|
url = "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json"
|
||||||
|
|
||||||
resp_extended = session.get(url)
|
response = session.get(url)
|
||||||
extended_patches = resp_extended.json()
|
handle_response(response)
|
||||||
|
extended_patches = response.json()
|
||||||
for app_name in (
|
for app_name in (
|
||||||
self.revanced_extended_app_ids[x][1] for x in self.revanced_extended_app_ids
|
self.revanced_extended_app_ids[x][1] for x in self.revanced_extended_app_ids
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
"""Utilities."""
|
"""Utilities."""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
from requests import Response
|
||||||
|
|
||||||
default_build = [
|
default_build = [
|
||||||
"youtube",
|
"youtube",
|
||||||
]
|
]
|
||||||
@@ -55,3 +58,10 @@ class AppNotFound(ValueError):
|
|||||||
"""Not a valid Revanced App."""
|
"""Not a valid Revanced App."""
|
||||||
|
|
||||||
pass
|
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