From b3d9ef88ec55335db93601f4b2ec9ad30eca93ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Mon, 23 Dec 2013 10:23:13 +0100 Subject: [PATCH] =?utf8?q?YoutubeDL:=20only=20set=20the=20=E2=80=98formats?= =?utf8?q?=E2=80=99=20field=20of=20the=20info=5Fdict=20if=20it=20was=20alr?= =?utf8?q?eady=20set=20before?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It caused a circular reference error, when trying to dump it to json (for example with the test video for myvideo.de or any other video without formats) --- youtube_dl/YoutubeDL.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 04771c637..adeef23af 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -688,7 +688,12 @@ class YoutubeDL(object): 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 -- 2.22.2