chapmanjacobd / library

80+ CLI tools to build, browse, and blend your media library: an index for your archive.
BSD 3-Clause "New" or "Revised" License
355 stars 9 forks source link

tube: yt-dlp arguments #10

Closed chapmanjacobd closed 9 months ago

chapmanjacobd commented 1 year ago

Is your feature request related to a problem? Please describe.

Requiring the use of API subcommands is kinda weird so it would be good to allow using yt-dlp commands directly:

To distinguish from library arguments the double dash would need to be removed. Not sure how to handle single-dash arguments

import yt_dlp

def cli_to_api(*opts):
    default = yt_dlp.parse_options([]).ydl_opts
    diff = {k: v for k, v in yt_dlp.parse_options(opts).ydl_opts.items() if default[k] != v}
    diff['postprocessors'] = [pp for pp in diff['postprocessors'] if pp not in default['postprocessors']]
    return diff

from pprint import pprint

pprint(cli_to_api('--embed-metadata', '--embed-thumbnail'))  # Change according to your need

Output

{'outtmpl': {'pl_thumbnail': ''},
 'postprocessors': [{'add_chapters': True,
                     'add_infojson': 'if_exists',
                     'add_metadata': True,
                     'key': 'FFmpegMetadata'},
                    {'already_have_thumbnail': False, 'key': 'EmbedThumbnail'}],
 'writethumbnail': True}

Stolen from https://discord.com/channels/807245652072857610/1023190793491599391/1023190796826066974