Exemplo n.º 1
0
async def list_formats(info_dict: dict) -> str:
    """YoutubeDL's list_formats method but without format notes.

    Args:
        info_dict (``dict``):
            Dictionary which is returned by YoutubeDL's extract_info method.

    Returns:
        ``str``:
            All available formats in order as a string instead of stdout.
    """
    formats = info_dict.get('formats', [info_dict])
    table = [[
        f['format_id'], f['ext'],
        youtube_dl.YoutubeDL.format_resolution(f)
    ] for f in formats
             if f.get('preference') is None or f['preference'] >= -1000]
    if len(formats) > 1:
        table[-1][-1] += (' ' if table[-1][-1] else '') + '(best)'

    header_line = ['format code', 'extension', 'resolution']
    fmtStr = (
        '`Available formats for %s:`\n`%s`' %
        (info_dict['title'], youtube_dl.render_table(header_line, table)))
    return fmtStr
Exemplo n.º 2
0
async def list_formats(info_dict: dict) -> str:
    """YoutubeDL's list_formats method but without format notes.

    Args:
        info_dict (``dict``):
            Dictionary which is returned by YoutubeDL's extract_info method.

    Returns:
        ``str``:
            All available formats in order as a string instead of stdout.
    """
    formats = info_dict.get("formats", [info_dict])
    table = [[
        f["format_id"], f["ext"],
        youtube_dl.YoutubeDL.format_resolution(f)
    ] for f in formats
             if f.get("preference") is None or f["preference"] >= -1000]
    if len(formats) > 1:
        table[-1][-1] += (" " if table[-1][-1] else "") + "(best)"

    header_line = ["format code", "extension", "resolution"]
    return "Available formats for %s:\n%s" % (
        info_dict["title"],
        youtube_dl.render_table(header_line, table),
    )