Skip to content

Commit 472005a

Browse files
authored
Merge pull request #1687 from rsteube/ytlpd-fields
yt-dlp: added fields
2 parents f8695ba + 1d86d31 commit 472005a

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed

completers/yt-dlp_completer/cmd/root.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,28 @@ func init() {
312312
}),
313313
"load-info-json": carapace.ActionFiles(),
314314
"merge-output-format": ytdlp.ActionOutputFormats().UniqueList("/"),
315+
"output": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
316+
index := strings.LastIndex(c.Value, "%(")
317+
if index < 0 {
318+
return carapace.ActionValues()
319+
}
320+
321+
prefix := c.Value[:index+2]
322+
c.Value = c.Value[index+2:]
323+
batch := carapace.Batch(
324+
ytdlp.ActionFields(),
325+
ytdlp.ActionNumericMetaFields(),
326+
ytdlp.ActionStringMetaFields(),
327+
ytdlp.ActionChapterFields(),
328+
ytdlp.ActionEpisodeFields(),
329+
ytdlp.ActionTrackFields(),
330+
)
331+
332+
if rootCmd.Flag("download-sections").Changed { // TODO also enabled when chapter: prefix?
333+
batch = append(batch, ytdlp.ActionSectionFields())
334+
}
335+
return batch.Invoke(c).Merge().Prefix(prefix).ToA().NoSpace()
336+
}),
315337
"print-to-file": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
316338
switch len(c.Parts) {
317339
case 1:

pkg/actions/tools/ytdlp/field.go

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
package ytdlp
2+
3+
import "github.com/rsteube/carapace"
4+
5+
// ActionFields completes fields
6+
func ActionFields() carapace.Action {
7+
return carapace.ActionValuesDescribed(
8+
"id", "(string): Video identifier",
9+
"title", "(string): Video title",
10+
"fulltitle", "(string): Video title ignoring live timestamp and generic title",
11+
"ext", "(string): Video filename extension",
12+
"alt_title", "(string): A secondary title of the video",
13+
"description", "(string): The description of the video",
14+
"display_id", "(string): An alternative identifier for the video",
15+
"uploader", "(string): Full name of the video uploader",
16+
"license", "(string): License name the video is licensed under",
17+
"creator", "(string): The creator of the video",
18+
"timestamp", "(numeric): UNIX timestamp of the moment the video became available",
19+
"upload_date", "(string): Video upload date in UTC (YYYYMMDD)",
20+
"release_timestamp", "(numeric): UNIX timestamp of the moment the video was released",
21+
"release_date", "(string): The date (YYYYMMDD) when the video was released in UTC",
22+
"modified_timestamp", "(numeric): UNIX timestamp of the moment the video was last modified",
23+
"modified_date", "(string): The date (YYYYMMDD) when the video was last modified in UTC",
24+
"uploader_id", "(string): Nickname or id of the video uploader",
25+
"channel", "(string): Full name of the channel the video is uploaded on",
26+
"channel_id", "(string): Id of the channel",
27+
"channel_follower_count", "(numeric): Number of followers of the channel",
28+
"location", "(string): Physical location where the video was filmed",
29+
"duration", "(numeric): Length of the video in seconds",
30+
"duration_string", "(string): Length of the video (HH:mm:ss)",
31+
"view_count", "(numeric): How many users have watched the video on the platform",
32+
"concurrent_view_count", "(numeric): How many users are currently watching the video on the platform.",
33+
"like_count", "(numeric): Number of positive ratings of the video",
34+
"dislike_count", "(numeric): Number of negative ratings of the video",
35+
"repost_count", "(numeric): Number of reposts of the video",
36+
"average_rating", "(numeric): Average rating give by users, the scale used depends on the webpage",
37+
"comment_count", "(numeric): Number of comments on the video (For some extractors, comments are only downloaded at the end, and so this field cannot be used)",
38+
"age_limit", "(numeric): Age restriction for the video (years)",
39+
"live_status", "(string): One of \"not_live\", \"is_live\", \"is_upcoming\", \"was_live\", \"post_live\" (was live, but VOD is not yet processed)",
40+
"is_live", "(boolean): Whether this video is a live stream or a fixed-length video",
41+
"was_live", "(boolean): Whether this video was originally a live stream",
42+
"playable_in_embed", "(string): Whether this video is allowed to play in embedded players on other sites",
43+
"availability", "(string): Whether the video is \"private\", \"premium_only\", \"subscriber_only\", \"needs_auth\", \"unlisted\" or \"public\"",
44+
"start_time", "(numeric): Time in seconds where the reproduction should start, as specified in the URL",
45+
"end_time", "(numeric): Time in seconds where the reproduction should end, as specified in the URL",
46+
"extractor", "(string): Name of the extractor",
47+
"extractor_key", "(string): Key name of the extractor",
48+
"epoch", "(numeric): Unix epoch of when the information extraction was completed",
49+
"autonumber", "(numeric): Number that will be increased with each download, starting at --autonumber-start",
50+
"video_autonumber", "(numeric): Number that will be increased with each video",
51+
"n_entries", "(numeric): Total number of extracted items in the playlist",
52+
"playlist_id", "(string): Identifier of the playlist that contains the video",
53+
"playlist_title", "(string): Name of the playlist that contains the video",
54+
"playlist", "(string): playlist_id or playlist_title",
55+
"playlist_count", "(numeric): Total number of items in the playlist. May not be known if entire playlist is not extracted",
56+
"playlist_index", "(numeric): Index of the video in the playlist padded with leading zeros according the final index",
57+
"playlist_autonumber", "(numeric): Position of the video in the playlist download queue padded with leading zeros according to the total length of the playlist",
58+
"playlist_uploader", "(string): Full name of the playlist uploader",
59+
"playlist_uploader_id", "(string): Nickname or id of the playlist uploader",
60+
"webpage_url", "(string): A URL to the video webpage which if given to yt-dlp should allow to get the same result again",
61+
"webpage_url_basename", "(string): The basename of the webpage URL",
62+
"webpage_url_domain", "(string): The domain of the webpage URL",
63+
"original_url", "(string): The URL given by the user (or same as webpage_url for playlist entries)",
64+
).Tag("fields")
65+
}
66+
67+
// ActionChapterFields completes chapter fields
68+
func ActionChapterFields() carapace.Action {
69+
return carapace.ActionValuesDescribed(
70+
"chapter", "(string): Name or title of the chapter the video belongs to",
71+
"chapter_number", "(numeric): Number of the chapter the video belongs to",
72+
"chapter_id", "(string): Id of the chapter the video belongs to",
73+
).Tag("chapter fields")
74+
}
75+
76+
// ActionEpisodeFields completes episode fields
77+
func ActionEpisodeFields() carapace.Action {
78+
return carapace.ActionValuesDescribed(
79+
"series", "(string): Title of the series or programme the video episode belongs to",
80+
"season", "(string): Title of the season the video episode belongs to",
81+
"season_number", "(numeric): Number of the season the video episode belongs to",
82+
"season_id", "(string): Id of the season the video episode belongs to",
83+
"episode", "(string): Title of the video episode",
84+
"episode_number", "(numeric): Number of the video episode within a season",
85+
"episode_id", "(string): Id of the video episode",
86+
).Tag("episode fields")
87+
}
88+
89+
// ActionTrackFields completes track fields
90+
func ActionTrackFields() carapace.Action {
91+
return carapace.ActionValuesDescribed(
92+
"track", "(string): Title of the track",
93+
"track_number", "(numeric): Number of the track within an album or a disc",
94+
"track_id", "(string): Id of the track",
95+
"artist", "(string): Artist(s) of the track",
96+
"genre", "(string): Genre(s) of the track",
97+
"album", "(string): Title of the album the track belongs to",
98+
"album_type", "(string): Type of the album",
99+
"album_artist", "(string): List of all artists appeared on the album",
100+
"disc_number", "(numeric): Number of the disc or other physical medium the track belongs to",
101+
"release_year", "(numeric): Year (YYYY) when the album was released",
102+
).Tag("track fields")
103+
}
104+
105+
// ActionSectionFields completes section fields
106+
func ActionSectionFields() carapace.Action {
107+
return carapace.ActionValuesDescribed(
108+
"section_title", "(string): Title of the chapter",
109+
"section_number", "(numeric): Number of the chapter within the file",
110+
"section_start", "(numeric): Start time of the chapter in seconds",
111+
"section_end", "(numeric): End time of the chapter in seconds",
112+
).Tag("section fields")
113+
}
114+
115+
// ActionPrintFields completes print fields
116+
func ActionPrintFields() carapace.Action {
117+
return carapace.ActionValuesDescribed(
118+
"urls", "(string): The URLs of all requested formats, one in each line",
119+
"filename", "(string): Name of the video file. Note that the actual filename may differ",
120+
"formats_table", "(table): The video format table as printed by --list-formats",
121+
"thumbnails_table", "(table): The thumbnail format table as printed by --list-thumbnails",
122+
"subtitles_table", "(table): The subtitle format table as printed by --list-subs",
123+
"automatic_captions_table", "(table): The automatic subtitle format table as printed by --list-subs",
124+
).Tag("print fields")
125+
}
126+
127+
// ActionSponsorblockFields completes sponsorblock fields
128+
func ActionSponsorblockFields() carapace.Action {
129+
return carapace.ActionValuesDescribed(
130+
"start_time", "(numeric): Start time of the chapter in seconds",
131+
"end_time", "(numeric): End time of the chapter in seconds",
132+
"categories", "(list): The SponsorBlock categories the chapter belongs to",
133+
"category", "(string): The smallest SponsorBlock category the chapter belongs to",
134+
"category_names", "(list): Friendly names of the categories",
135+
"name", "(string): Friendly name of the smallest category",
136+
"type", "(string): The SponsorBlock action type of the chapter",
137+
).Tag("sponsorblock fields")
138+
}
139+
140+
// ActionNumericMetaFields completes numeric meta fields
141+
func ActionNumericMetaFields() carapace.Action {
142+
return carapace.ActionValuesDescribed(
143+
"filesize", "The number of bytes, if known in advance",
144+
"filesize_approx", "An estimate for the number of bytes",
145+
"width", "Width of the video, if known",
146+
"height", "Height of the video, if known",
147+
"aspect_ratio", "Aspect ratio of the video, if known",
148+
"tbr", "Average bitrate of audio and video in KBit/s",
149+
"abr", "Average audio bitrate in KBit/s",
150+
"vbr", "Average video bitrate in KBit/s",
151+
"asr", "Audio sampling rate in Hertz",
152+
"fps", "Frame rate",
153+
"audio_channels", "The number of audio channels",
154+
"stretched_ratio", "width:height of the video's pixels, if not square)",
155+
).Tag("numeric meta fields")
156+
}
157+
158+
// ActionStringMetaFields completes string meta fields
159+
func ActionStringMetaFields() carapace.Action {
160+
return carapace.ActionValuesDescribed(
161+
"url", "Video URL",
162+
"ext", "File extension",
163+
"acodec", "Name of the audio codec in use",
164+
"vcodec", "Name of the video codec in use",
165+
"container", "Name of the container format",
166+
"protocol", "The protocol that will be used for the actual download, lower-case (http, https, rtsp, rtmp, rtmpe, mms, f4m, ism, http_dash_segments, m3u8, or m3u8_native)",
167+
"language", "Language code",
168+
"dynamic_range", "The dynamic range of the video",
169+
"format_id", "A short description of the format",
170+
"format", "A human-readable description of the format",
171+
"format_note", "Additional info about the format",
172+
"resolution", "Textual description of width and height",
173+
).Tag("string meta fields")
174+
}

0 commit comments

Comments
 (0)