mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-01-07 17:16:08 +00:00
YoutubeDL: only set the ‘formats’ field of the info_dict if it was already set before
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)
This commit is contained in:
parent
8958b6916c
commit
b3d9ef88ec
|
@ -688,6 +688,11 @@ class YoutubeDL(object):
|
||||||
ext_ord)
|
ext_ord)
|
||||||
formats = sorted(formats, key=_free_formats_key)
|
formats = sorted(formats, key=_free_formats_key)
|
||||||
|
|
||||||
|
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
|
info_dict['formats'] = formats
|
||||||
if self.params.get('listformats', None):
|
if self.params.get('listformats', None):
|
||||||
self.list_formats(info_dict)
|
self.list_formats(info_dict)
|
||||||
|
|
Loading…
Reference in a new issue