Improve function docstring
[youtube-dl.el.git] / youtube-dl-transient.el
blob94d67d8b9d7a97d28cdeaa0573a1e78affca26b3
1 ;;; youtube-dl-transient.el --- transient interface for youtube-dl -*- lexical-binding: t; -*-
2 ;; -*- coding: utf-8 -*-
4 ;; Copyright (C) 2020-2021 Christopher M. Miles, all rights reserved.
6 ;;; Commentary:
10 ;;; Code:
12 (require 'transient)
14 ;;; transient interface for youtube-dl download to toggle command-line options.
15 ;;; Reference command man page options.
16 (transient-define-prefix youtube-dl-general-options ()
17 "youtube-dl command-line general options."
18 ["General Options"
19 :class transient-column
20 :pad-keys t
21 ("-ie" "ignore errors" "--ignore-errors")
22 ("-ae" "abort on error" "--abort-on-error")
23 ("-ic" "ignore config" "--ignore-config")
24 ("-nc" "no output colors" "--no-colors")
25 ("-mw" "mark videos watched" "--mark-watched")])
27 (transient-define-prefix youtube-dl-network-options ()
28 "youtube-dl command-line network options."
29 ["Network Options"
30 :class transient-column
31 :pad-keys t
32 ("-p" "specify proxy" "--proxy <URL>")])
34 (transient-define-prefix youtube-dl-video-options ()
35 "youtube-dl command-line video options."
36 ["Video Selection"
37 :class transient-column
38 :pad-keys t
39 ("-PI" "Comma separated playlist_index of the items to download by range [START]:[STOP][:STEP]" "--playlist-items <ITEM_SPEC>")
40 ("-PL" "Download the playlist" "--yes-playlist")
41 ("-MD" "Abort after downloading NUMBER files" "--max-downloads <NUMBER>")])
43 (transient-define-prefix youtube-dl-download-options ()
44 "youtube-dl command-line download options."
45 ["Download Options"
46 :class transient-column
47 :pad-keys t
48 ("-nd" "Number of fragments of a dash/hlsnative video that should be downloaded concurrently." "--concurrent-fragments <N>")
49 ("-lr" "Maximum download rate in bytes per second, e.g. 50K or 4.2M" "--limit-rate <RATE>")
50 ("-RT" "Number of retries (default is 10), or \"infinite\"." "--retries <RETRIES>")
51 ("-RS" "Time to sleep between retries in seconds." "--retry-sleep linear=1::2")
52 ("-SI" "Number of seconds to sleep before each download." "--sleep-interval <SECONDS>")])
54 (transient-define-prefix youtube-dl-filesystem-options ()
55 "youtube-dl command-line filesystem options."
56 ["Filesystem Options"
57 :class transient-column
58 :pad-keys t
59 ("-a" "File containing URLs to download (\"-\" for stdin), one URL per line. (support comment start with # ; )." "--batch-file <FILE>")
60 ("-o" "Output filename template; see \"OUTPUT TEMPLATE\" for details." "--output <[TYPES:]TEMPLATE>")
61 ("-rf" "Restrict filenames to only ASCII characters, and avoid \"&\" and spaces in filenames." "--restrict-filenames")
62 ("-tf" "Limit the filename length (excluding extension) to the specified number of characters." "--trim-filenames <LENGTH>")
63 ("-w" "Do not overwrite any files." "--no-overwrites")
64 ("-O" "Overwrite all video and metadata files." "--force-overwrites")
65 ("-W" "Do not overwrite the video, but overwrite related files (default)." "--no-force-overwrites")
66 ("-c" "Resume partially downloaded files/fragments (default)" "--continue")
67 ("-J" "Write video metadata to a .info.json file." "--write-info-json")
68 ("-C" "Retrieve video comments to be placed in the .info.json." "--write-comments")
69 ("-b" "Load cookies from web browser." "--cookies-from-browser chrome")])
71 (transient-define-prefix youtube-dl-thumbnail-options ()
72 "youtube-dl command-line thumbnail options."
73 ["Thumbnail Options"
74 :class transient-column
75 :pad-keys t
76 ("-t" "Write thumbnail image to disk." "--write-thumbnail")
77 ("-lt" "List available thumbnails of each video." "--list-thumbnails")])
79 (transient-define-prefix youtube-dl-internet-shortcut-options ()
80 "youtube-dl command-line internet shortcut options."
81 ["Internet Shortcut Options"
82 :class transient-column
83 :pad-keys t
84 ("-L" "Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop)." "--write-link")])
86 (transient-define-prefix youtube-dl-verbosity-options ()
87 "youtube-dl command-line verbosity and simulation options."
88 ["Verbosity and Simulation Options"
89 :class transient-column
90 :pad-keys t
91 ("-q" "Activate quiet mode. If used with --verbose, print the log to stderr." "--quiet")
92 ("-nw" "Ignore warnings" "--no-warnings")
93 ("-S" "Do not download the video and do not write anything to disk." "--simulate")
94 ("-dj" "Quiet, but print JSON information for each video." "--dump-json")
95 ("-n" "Output progress bar as new lines" "--newline")
96 ("-p" "Show progress bar, even if in quiet mode." "--progress")])
98 (transient-define-prefix youtube-dl-workarounds-options ()
99 "youtube-dl command-line workarounds options."
100 ["Workarounds"
101 :class transient-column
102 :pad-keys t
103 ("-SL" "Explicitly allow HTTPS connection to servers that do not support RFC 5746 secure renegotiation." "--legacy-server-connect")
104 ("-NC" "Suppress HTTPS certificate validation." "--no-check-certificates")
105 ("-H" "Specify a custom HTTP header and its value, separated by a colon \":\"." "--add-headers <FIELD:VALUE>")])
107 (transient-define-prefix youtube-dl-video-format-options ()
108 "youtube-dl command-line video format options."
109 ["Video Format Options"
110 :class transient-column
111 :pad-keys t
112 ("-f" "Video format code, see \"FORMAT SELECTION\" for more details." "--format <FORMAT>")
113 ("-lf" "List available formats of each video. Simulate unless --no-simulate is used." "--list-formats")])
115 (transient-define-prefix youtube-dl-subtitle-options ()
116 "youtube-dl command-line subtitle options."
117 ["Subtitle Options"
118 :class transient-column
119 :pad-keys t
120 ("-s" "Write subtitle file" "--write-subs")
121 ("-sa" "Write automatically generated subtitle file." "--write-auto-subs")
122 ("-sf" "Subtitle format; accepts formats preference, e.g. \"srt\" or \"ass/srt/best\"." "--sub-format <FORMAT>")
123 ("-sl" "Languages of the subtitles to download (can be regex) or \"all\" separated by commas like \"en.*,ja\"." "--sub-langs <LANGS>")
124 ("-ls" "List available subtitles of each video." "--list-subs")])
126 (transient-define-prefix youtube-dl-authentication-options ()
127 "youtube-dl command-line authentication options."
128 ["Authentication Options"
129 :class transient-column
130 :pad-keys t
133 (transient-define-prefix youtube-dl-post-processing-options ()
134 "youtube-dl command-line post-processing options."
135 ["Post-Processing Options"
136 :class transient-column
137 :pad-keys t
138 ("-x" "Convert video files to audio-only files." "--extract-audio")
139 ("-AF" "Format to convert the audio to when -x is used. (currently supported: best (default), aac, alac, flac, m4a, mp3, opus, vorbis, wav)." "--audio-format <FORMAT>")
140 ("-AQ" "Specify ffmpeg audio quality to use when converting the audio with -x." "--audio-quality <QUALITY>")
141 ("-CS" "Convert the subtitles to another format (currently supported: ass, lrc, srt, vtt)" "--convert-subs <FORMAT>")])
143 (transient-define-prefix youtube-dl-extractor-options ()
144 "youtube-dl command-line extractor options."
145 ["Extractor Options"
146 :class transient-column
147 :pad-keys t
148 ("-ER" "Number of retries for known extractor errors (default is 3)" "--extractor-retries <RETRIES>" :transient transient--do-return)])
150 (transient-define-prefix youtube-dl-options ()
151 "youtube-dl command-line options."
152 :man-page "yt-dlp" ; youtube-dl-program
153 [:description
154 (lambda ()
155 (format "youtube-dl options: %s" youtube-dl-extra-arguments))
156 [("g" "General Options" youtube-dl-general-options :transient transient--do-recurse)
157 ("n" "Network Options" youtube-dl-network-options)
158 ("d" "Download Options" youtube-dl-download-options)
159 ("f" "Filesystem Options" youtube-dl-filesystem-options)
160 ("t" "Thumbnail Options" youtube-dl-thumbnail-options)
161 ("i" "Internet Shortcut Options" youtube-dl-internet-shortcut-options)
162 ("V" "Verbosity & Simulation Options" youtube-dl-verbosity-options)
163 ("w" "Workarounds Options" youtube-dl-workarounds-options)
164 ("v" "Video Format Options" youtube-dl-video-format-options)
165 ("s" "Subtitle Options" youtube-dl-subtitle-options)
166 ("a" "Authentication Options" youtube-dl-authentication-options)
167 ("P" "Post-Processing Options" youtube-dl-post-processing-options)
168 ("e" "Extractor Options" youtube-dl-extractor-options)]]
171 (defun youtube-dl-transient ()
172 "Entrypoint command for transient interface to specify command-line options."
173 (interactive)
174 (transient-args 'youtube-dl-options))
176 ;;; TODO: how to pass toggled options to `youtube-dl-extra-arguments'?
179 ;;; transient interface for youtube-dl list buffer.
180 (transient-define-prefix youtube-dl-list-dispatch ()
181 "youtube-dl list buffer commands dispatcher."
182 ["youtube-dl list buffer commands"
183 ["Action on Item"
184 ("y" "yank item url" youtube-dl-list-yank)
185 ("k" "kill item at point" youtube-dl-list-kill)
186 ("p" "pause item at point" youtube-dl-list-toggle-pause)
187 ("P" "pause all items" youtube-dl-list-toggle-pause-all)
188 ("r" "resume item at point" youtube-dl-list-resume)
189 ("s" "slow down item at point" youtube-dl-list-toggle-slow)
190 ("S" "slow down all items" youtube-dl-list-toggle-slow-all)
191 ("]" "increase priority up" youtube-dl-list-priority-up)
192 ("[" "decrease priority down" youtube-dl-list-priority-down)]
193 ["Download"
194 ("a" "download" youtube-dl)
195 ("A" "download playlist" youtube-dl-download-playlist)]
196 ["List buffer operations"
197 ("g" "refresh" youtube-dl-list-redisplay)
198 ("l" "open process log buffer" youtube-dl-list-log)
199 ("L" "close list log buffer" youtube-dl-list-kill-log)]
200 ["Navigation"
201 ("j" "next item" youtube-dl-list-next-item)
202 ("k" "previous item" youtube-dl-list-prev-item)]
203 ;; ["Mark item(s)"
204 ;; ("m" "mark item(s) at point" youtube-dl-mark)
205 ;; ("M" "mark all items" youtube-dl-mark-all)
206 ;; ("u" "unmark item(s) at point" youtube-dl-unmark)
207 ;; ("U" "unmark all items" youtube-dl-unmark-all)
208 ;; ("%" "mark items matching regexp" youtube-dl-mark-with-regexp)]
213 (provide 'youtube-dl-transient)
215 ;;; youtube-dl-transient.el ends here