diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 04771c6372..adeef23af0 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -688,7 +688,12 @@ def _free_formats_key(f): ext_ord) formats = sorted(formats, key=_free_formats_key) - info_dict['formats'] = formats + if formats[0] is not info_dict: + # only set the 'formats' fields if the original info_dict list them + # otherwise we end up with a circular reference, the first (and unique) + # element in the 'formats' field in info_dict is info_dict itself, + # wich can't be exported to json + info_dict['formats'] = formats if self.params.get('listformats', None): self.list_formats(info_dict) return