Skip to content

Commit

Permalink
Merge pull request #15 from bbtufty/ouo-fix
Browse files Browse the repository at this point in the history
Further fixes for link shortening
  • Loading branch information
bbtufty authored Oct 27, 2024
2 parents 9b1414e + 06291d0 commit bd0d310
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
================

- Exclude log folder so pip builds successfully [#16]
- Further fixes for link shortening [#15]

0.3 (2024-10-26)
================
Expand Down
16 changes: 12 additions & 4 deletions nxbrew_dl/util/download_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
import re
import time
from urllib.parse import urlparse
Expand Down Expand Up @@ -368,7 +369,7 @@ def RecaptchaV3():
def bypass_ouo(
url,
logger=None,
impersonate="safari",
impersonate=None,
n_retry=0,
max_retries=5,
):
Expand All @@ -378,14 +379,18 @@ def bypass_ouo(
url (str): URL to bypass
logger (logging.Logger): Logger to use. Defaults to None,
which will not log anything
impersonate (str): Type of browser to impersonate
impersonate (str): Type of browser to impersonate. Defaults
to None, which will choose randomly from a selection
n_retry (int): Current retry. Defaults to 0
max_retries (int): Maximum number of retries. Defaults to 5
"""

if n_retry >= max_retries:
raise ValueError("Max retries exceeded!")

if impersonate is None:
impersonate = random.choice(["chrome", "safari", "edge"])

client = cffi_requests.Session()
client.headers.update(
{
Expand Down Expand Up @@ -427,12 +432,15 @@ def bypass_ouo(

bs4 = BeautifulSoup(res.content, "lxml")

# Try and find the token. If we don't find anything, assume
# it's broken and try again
# Try and find the token
inputs = None
try:
inputs = bs4.form.findAll("input", {"name": re.compile(r"token$")})
except AttributeError:
pass

# Catch problems here
if inputs is None:
if logger is not None:
logger.warning(f"Page load error. Waiting then retrying")

Expand Down

0 comments on commit bd0d310

Please sign in to comment.