How to filter Json File in Python?

Hi,

Thanks for your great answer!

Yes, that JSON data are a dump file.
and i tried replace my command : command = f'yt-dlp "{url}" -j --no-playlist' to command = ['youtube-dl', url, '-j', '--no-playlist'] and add this line below.

from subprocess import run, PIPE

P = subprocess.run(command, stdout=PIPE)
output = P.stdout.read()

however, it show error AttributeError: 'bytes' object has no attribute 'read' in output = P.stdout.read()

To be honest, i really want to replace my approach using youtube-dl as binary file like i’m wrote. using youtube-dl as a package make me confuse as well.

because i don’t know how to integrated the code :

ydl_opts = {
     'progress_hooks': [self.update_progress],
     'format': DEFAULT_OUTPUT_FORMAT,
     'logger': logging.getLogger(),
     'outtmpl': DEFAULT_OUTPUT_FILENAME_TEMPLATE,
     ##'skip_download': True,
     'writeinfojson': False,
     'updatetime': False,
     'process_info': [self.process_info]
 }
 ydl = YoutubeDL(ydl_opts)
 ie_result = ydl.extract_info(url, download=False, process=True)

in my python code. if still using my code at python.py :

def extract_video_data_from_url(url):    
    
    command = f'youtube-dl"{url}" -j --no-playlist'
    #command = ['youtube-dl', url, '-j', '--no-playlist']
    #P = subprocess.run(command, stdout=PIPE)
    #output = P.stdout.read()
    output = os.popen(command).read()
    video_data = json.loads(output)
    title = video_data["title"]
    formats = video_data["formats"]
    for element in formats:
        if '251' in element['format_id']:
            element['format_id'] = "Download MP3 (64KBPS)"
        elif '18' in element['format_id']:
            element['format_id'] = "Download MP4 (360p)"
        elif '22' in element['format_id']:
            element['format_id'] = "Download MP4 (720p)"
        elif 'Playback video' in element['format_note']:
            element['format_note'] = "Download MP4 No Watermark"
        else:
            element['format_id'] = "Broken Link"
    thumbnail = video_data["thumbnail"]
    formats = [extract_format_data(format_data) for format_data in formats]
    return {
        "title": title,
        "formats": formats,
        "thumbnail": thumbnail
    }

where should i replace it?
thanks!