diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index 422c865f..dd1272f4 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -14,7 +14,6 @@ from .. import text, util, exception from ..cache import cache, memcache import itertools import binascii -import json import re BASE_PATTERN = r"(?:https?://)?(?:www\.)?instagram\.com" @@ -913,7 +912,7 @@ class InstagramGraphqlAPI(): self.user_collection = self.user_saved = self.reels_media = \ self.highlights_media = self.guide = self.guide_media = \ self._unsupported - self._json_dumps = json.JSONEncoder(separators=(",", ":")).encode + self._json_dumps = util.json_dumps api = InstagramRestAPI(extractor) self.user_by_name = api.user_by_name diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index d4ec343c..9c9d5052 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -13,7 +13,6 @@ from .. import text, util, exception from ..cache import cache, memcache import itertools import random -import json import re BASE_PATTERN = (r"(?:https?://)?(?:www\.|mobile\.)?" @@ -1034,7 +1033,7 @@ class TwitterAPI(): self.root = "https://x.com/i/api" self._nsfw_warning = True - self._json_dumps = json.JSONEncoder(separators=(",", ":")).encode + self._json_dumps = util.json_dumps cookies = extractor.cookies cookies_domain = extractor.cookies_domain diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 128f48b7..d5bc1717 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -253,7 +253,11 @@ def json_default(obj): json_loads = json._default_decoder.decode -json_dumps = json.JSONEncoder(default=json_default).encode +json_dumps = json.JSONEncoder( + check_circular=False, + separators=(",", ":"), + default=json_default, +).encode def dump_json(obj, fp=sys.stdout, ensure_ascii=True, indent=4): diff --git a/test/test_formatter.py b/test/test_formatter.py index f1d752da..c0b504da 100644 --- a/test/test_formatter.py +++ b/test/test_formatter.py @@ -64,7 +64,7 @@ class TestFormatter(unittest.TestCase): self._run_test("{t!d}", datetime.datetime(2010, 1, 1)) self._run_test("{t!d:%Y-%m-%d}", "2010-01-01") self._run_test("{dt!T}", "1262304000") - self._run_test("{l!j}", '["a", "b", "c"]') + self._run_test("{l!j}", '["a","b","c"]') self._run_test("{dt!j}", '"2010-01-01 00:00:00"') self._run_test("{a!g}", "hello-world") self._run_test("{a!L}", 11)