dropin

alternative frontend for dropout.tv
git clone https://git.ce9e.org/dropin.git

commit
3f751b7b2c8a7e16119556e6246973805961d227
parent
8b8a379f2c2e18e8b1064b6a2e978e77d60d0331
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-09-25 17:45
improve raise_for_status()

Diffstat

M dropin.py 22 ++++++++++++++++------

1 files changed, 16 insertions, 6 deletions


diff --git a/dropin.py b/dropin.py

@@ -125,6 +125,18 @@ def linebreaks(text):
  125   125 env.filters['linebreaks'] = linebreaks
  126   126 
  127   127 
   -1   128 def raise_for_status(response):
   -1   129     if response.status == 404:
   -1   130         raise web.HTTPNotFound
   -1   131     elif response.status == 429:
   -1   132         raise web.HTTPServiceUnavailable
   -1   133     else:
   -1   134         try:
   -1   135             response.raise_for_status()
   -1   136         except aiohttp.ClientResponseError as e:
   -1   137             raise web.HTTPBadGateway from e
   -1   138 
   -1   139 
  128   140 class Auth:
  129   141     def __init__(self, email=None, password=None):
  130   142         self.email = email
@@ -148,7 +160,7 @@ class Auth:
  148   160             async with session.get('https://watch.dropout.tv/login', headers={
  149   161                 'Accept': 'text/html',
  150   162             }) as response:
  151    -1                 response.raise_for_status()
   -1   163                 raise_for_status(response)
  152   164                 html = await response.text()
  153   165                 authenticity_token = re.search(
  154   166                     r'name="authenticity_token" value="([^"]+)', html
@@ -158,6 +170,7 @@ class Auth:
  158   170                 'password': self.password,
  159   171                 'authenticity_token': authenticity_token,
  160   172             }) as response:
   -1   173                 raise_for_status(response)
  161   174                 html = await response.text()
  162   175                 return re.search(r'token: "([^"]+)', html).group(1)
  163   176 
@@ -168,6 +181,7 @@ class Auth:
  168   181             aiohttp.ClientSession() as session,
  169   182             session.get('https://watch.dropout.tv/browse') as response,
  170   183         ):
   -1   184             raise_for_status(response)
  171   185             html = await response.text()
  172   186             return re.search(r'token: "([^"]+)', html).group(1)
  173   187 
@@ -227,11 +241,7 @@ async def fetch(url, *, need_auth=False, **params):
  227   241             headers={'Authorization': f'Bearer {token}'},
  228   242             params=params,
  229   243         ) as response:
  230    -1             if response.status == 404:
  231    -1                 raise web.HTTPNotFound
  232    -1             if response.status == 429:
  233    -1                 raise web.HTTPServiceUnavailable
  234    -1             response.raise_for_status()
   -1   244             raise_for_status(response)
  235   245             return await response.json()
  236   246 
  237   247