From a8fbb690ec53e3d594b21f502537912f228291d8 Mon Sep 17 00:00:00 2001 From: Joakim Holm Date: Sat, 8 Apr 2023 11:20:41 +0200 Subject: [PATCH] Add throttle error --- grawlix/exceptions.py | 3 +++ grawlix/sources/saxo.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/grawlix/exceptions.py b/grawlix/exceptions.py index 6c25975..ece0c69 100644 --- a/grawlix/exceptions.py +++ b/grawlix/exceptions.py @@ -18,3 +18,6 @@ class SourceNotAuthenticated(GrawlixError): class MissingArgument(GrawlixError): pass + +class ThrottleError(GrawlixError): + pass diff --git a/grawlix/sources/saxo.py b/grawlix/sources/saxo.py index 03a2fbf..b9d1a8f 100644 --- a/grawlix/sources/saxo.py +++ b/grawlix/sources/saxo.py @@ -1,5 +1,6 @@ from grawlix.book import Book, Metadata, SingleFile, OnlineFile from grawlix import AESEncryption +from grawlix.exceptions import ThrottleError import re from .source import Source @@ -87,11 +88,14 @@ class Saxo(Source): :param ebook_id: Id of ebook file :returns: Link to ebook file + :raises ThrottleError: If there have been too many downloads """ response = self._session.get( f"https://api-read.saxo.com/api/v1/book/{ebook_id}/content/encryptedstream/" - ) - return response.json()["link"] + ).json() + if not "link" in response: + raise ThrottleError + return response["link"] @staticmethod