From 4730de163f44ab59b21a28ad4253cd14d55958bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 29 Oct 2023 15:57:21 +0100 Subject: [PATCH] [patreon] refactor _extract_bootstrap() --- gallery_dl/extractor/patreon.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gallery_dl/extractor/patreon.py b/gallery_dl/extractor/patreon.py index 6e05afd5..351c5e3c 100644 --- a/gallery_dl/extractor/patreon.py +++ b/gallery_dl/extractor/patreon.py @@ -249,14 +249,23 @@ class PatreonExtractor(Extractor): return [genmap[ft] for ft in filetypes] def _extract_bootstrap(self, page): - if "window.patreon.bootstrap," in page: - return util.json_loads(text.extr( - page, "window.patreon.bootstrap,", "});") + "}") - elif 'window.patreon = {"bootstrap":' in page: - return util.json_loads(text.extr( - page, 'window.patreon = {"bootstrap":', '},"apiServer"') + "}") - else: - raise Exception("unknown HTML and JS structure") + bootstrap = text.extr( + page, 'window.patreon = {"bootstrap":', '},"apiServer"') + if bootstrap: + return util.json_loads(bootstrap + "}") + + bootstrap = text.extr(page, "window.patreon.bootstrap,", "});") + if bootstrap: + return util.json_loads(bootstrap + "}") + + data = text.extr(page, "window.patreon = {", "};\n") + if data: + try: + return util.json_loads("{" + data + "}")["bootstrap"] + except Exception: + pass + + raise exception.StopExtraction("Unable to extract bootstrap data") class PatreonCreatorExtractor(PatreonExtractor):