diff --git a/YTDL_OPTIONS-Cookbook.md b/YTDL_OPTIONS-Cookbook.md index 7349c41..52f5058 100644 --- a/YTDL_OPTIONS-Cookbook.md +++ b/YTDL_OPTIONS-Cookbook.md @@ -9,7 +9,7 @@ Embeds English subtitles and chapter markers (for videos that have them), change - 'YTDL_OPTIONS={"writesubtitles":true,"subtitleslangs":["en","-live_chat"],"updatetime":false,"postprocessors":[{"key":"Exec","exec_cmd":"chmod 0664","when":"after_move"},{"key":"FFmpegEmbedSubtitle","already_have_subtitle":false},{"key":"FFmpegMetadata","add_chapters":true}]}' ``` -### Embed metadata +### Embed metadata and a cover image in **video** downloads Contributed by [@PikuZheng](https://github.com/PikuZheng). @@ -20,6 +20,12 @@ NOTE: May cause errors for non-Youtube videos. - 'YTDL_OPTIONS={ "ignoreerrors":true, "writethumbnail":true, "postprocessors":[ {"key":"FFmpegMetadata","add_metadata":true,"add_chapters":true,"add_infojson":"if_exists"}, {"key":"EmbedThumbnail"}]}' ``` +> ⚠️ **Do not apply this to audio downloads.** Picking Audio in the UI already +> embeds a cover image, and the `writethumbnail` above *switches that off* — see +> [What MeTube already sets for you](#what-metube-already-sets-for-you). To use +> this for video only, define it as a named preset via `YTDL_OPTIONS_PRESETS` +> instead of setting it globally. + ### Automatically marking MeTube downloads with SponsorBlock chapters Contributed by [@loomweaver](https://github.com/loomweaver). @@ -89,3 +95,77 @@ To convert the video container instead (e.g. everything as MKV): (Note: yt-dlp's option is really spelled `preferedformat`, with one `r`.) Define these as named presets via `YTDL_OPTIONS_PRESETS` to pick them per-download in the UI instead of applying them globally. + +## What MeTube already sets for you + +MeTube builds part of the yt-dlp configuration itself from what you pick in the +UI, then merges your `YTDL_OPTIONS` on top. Options it already handles are best +left out of `YTDL_OPTIONS` — setting them again is at best redundant, and in one +case actively harmful. + +Picking **Audio** (any format except `wav`) makes MeTube add all of this: + +| Option | Purpose | +|---|---| +| `writethumbnail` | download the cover image | +| `FFmpegExtractAudio` | extract to your chosen format and quality | +| `FFmpegThumbnailsConvertor` | convert the cover to jpg **before** embedding | +| `FFmpegMetadata` | write tags | +| `EmbedThumbnail` | embed the cover | + +Picking **Video** adds no postprocessors at all, which is why the metadata +recipe above is useful there and unnecessary for audio. + +> ⚠️ **The `writethumbnail` trap.** MeTube adds that audio chain only when +> `writethumbnail` is *absent* from your options. The intent was to let you turn +> cover art off with `"writethumbnail": false`, but the check looks at whether the +> key is present rather than at its value — so setting it to **`true`** switches +> the chain off just the same: +> +> ``` +> Audio + mp3, no YTDL_OPTIONS -> ExtractAudio, ThumbnailsConvertor, Metadata, EmbedThumbnail +> Audio + mp3, "writethumbnail": true -> ExtractAudio +> ``` +> +> Without `FFmpegThumbnailsConvertor` the cover stays in its original format +> (webp, from YouTube). Embedding that into an mp3 fails with *"Supported +> filetypes for thumbnail embedding are: mp3..."*, or leaves the image sitting +> next to the audio file as a separate `.webp`. If cover art has stopped working +> on your audio downloads, this is almost always why — remove `writethumbnail` +> from `YTDL_OPTIONS`. + +## Converting a yt-dlp command line into JSON + +yt-dlp ships [`devscripts/cli_to_api.py`](https://github.com/yt-dlp/yt-dlp/blob/master/devscripts/cli_to_api.py), +which turns command-line flags into the API options that `YTDL_OPTIONS` expects. +It is the right starting point, but **do not paste its output in wholesale** — it +emits everything, including the keys MeTube manages from the UI. Delete those and +keep only what remains. + +For example, a square-cropped cover image: + +``` +yt-dlp -x --audio-format mp3 --embed-thumbnail --convert-thumbnail jpg \ + --ppa "EmbedThumbnail+ffmpeg_o:-c:v mjpeg -vf crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\"" +``` + +The converter turns that into a block containing `format`, `writethumbnail`, +`final_ext`, `FFmpegExtractAudio`, `FFmpegThumbnailsConvertor` and +`EmbedThumbnail` — every one of which MeTube already does when you pick Audio + +mp3, and one of which (`writethumbnail`) would break it. The only part MeTube +does not provide is the postprocessor argument, so that is all you need: + +```json +{ + "postprocessor_args": { + "embedthumbnail+ffmpeg_o": [ + "-c:v", "mjpeg", + "-vf", "crop='if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'" + ] + } +} +``` + +The `--ppa` prefix becomes the lowercased key `embedthumbnail+ffmpeg_o`, and the +arguments become a list rather than a single string, which removes the shell +quoting problem entirely.