-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
572 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/rsteube/carapace-bin/completers/yt-dlp_completer/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ytdlp | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/rsteube/carapace" | ||
) | ||
|
||
type dump struct { | ||
ID string `json:"id"` | ||
Title string `json:"title"` | ||
Formats []struct { | ||
FormatID string `json:"format_id"` | ||
FormatNote string `json:"format_note"` | ||
Ext string `json:"ext"` | ||
Protocol string `json:"protocol"` | ||
Acodec string `json:"acodec"` | ||
Vcodec string `json:"vcodec"` | ||
URL string `json:"url"` | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
Fps float64 `json:"fps"` | ||
Rows int `json:"rows,omitempty"` | ||
Columns int `json:"columns,omitempty"` | ||
Fragments []struct { | ||
URL string `json:"url"` | ||
Duration float64 `json:"duration"` | ||
} `json:"fragments,omitempty"` | ||
Resolution string `json:"resolution"` | ||
AspectRatio float64 `json:"aspect_ratio"` | ||
HTTPHeaders struct { | ||
UserAgent string `json:"User-Agent"` | ||
Accept string `json:"Accept"` | ||
AcceptLanguage string `json:"Accept-Language"` | ||
SecFetchMode string `json:"Sec-Fetch-Mode"` | ||
} `json:"http_headers"` | ||
AudioExt string `json:"audio_ext"` | ||
VideoExt string `json:"video_ext"` | ||
Format string `json:"format"` | ||
Asr int `json:"asr,omitempty"` | ||
Filesize int `json:"filesize,omitempty"` | ||
SourcePreference int `json:"source_preference,omitempty"` | ||
AudioChannels int `json:"audio_channels,omitempty"` | ||
Quality float64 `json:"quality,omitempty"` | ||
HasDrm bool `json:"has_drm,omitempty"` | ||
Tbr float64 `json:"tbr,omitempty"` | ||
Language any `json:"language,omitempty"` | ||
LanguagePreference int `json:"language_preference,omitempty"` | ||
Preference any `json:"preference,omitempty"` | ||
DynamicRange any `json:"dynamic_range,omitempty"` | ||
Abr float64 `json:"abr,omitempty"` | ||
Container string `json:"container,omitempty"` | ||
Vbr float64 `json:"vbr,omitempty"` | ||
FilesizeApprox int `json:"filesize_approx,omitempty"` | ||
} `json:"formats"` | ||
Thumbnails []struct { | ||
URL string `json:"url"` | ||
Preference int `json:"preference"` | ||
ID string `json:"id"` | ||
Height int `json:"height,omitempty"` | ||
Width int `json:"width,omitempty"` | ||
Resolution string `json:"resolution,omitempty"` | ||
} `json:"thumbnails"` | ||
Subtitles map[string][]struct { | ||
Ext string `json:"ext"` | ||
URL string `json:"url"` | ||
Name string `json:"name"` | ||
} `json:"subtitles"` | ||
} | ||
|
||
func actionDump(url string, f func(d dump) carapace.Action) carapace.Action { | ||
return carapace.ActionExecCommand("yt-dlp", "--dump-json", url)(func(output []byte) carapace.Action { | ||
var d dump | ||
if err := json.Unmarshal(output, &d); err != nil { | ||
return carapace.ActionMessage(err.Error()) | ||
} | ||
return f(d) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ytdlp | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/rsteube/carapace" | ||
) | ||
|
||
// ActionExtractors completes extractors | ||
// | ||
// 1News | ||
// 1tv | ||
func ActionExtractors() carapace.Action { | ||
return carapace.ActionExecCommand("yt-dlp", "--list-extractors")(func(output []byte) carapace.Action { | ||
lines := strings.Split(string(output), "\n") | ||
return carapace.ActionValues(lines[:len(lines)-1]...) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package ytdlp | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"strings" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/rsteube/carapace/pkg/style" | ||
) | ||
|
||
// ActionOutputFormats completes output formats | ||
// | ||
// avi | ||
// flv | ||
func ActionOutputFormats() carapace.Action { | ||
return carapace.ActionValues( | ||
"avi", | ||
"flv", | ||
"mkv", | ||
"mov", | ||
"mp4", | ||
"webm", | ||
) | ||
} | ||
|
||
// ActionSubtitleFormats completes subtitle formats | ||
// | ||
// ass | ||
// lrc | ||
func ActionSubtitleFormats() carapace.Action { | ||
return carapace.ActionValues( | ||
"ass", | ||
"lrc", | ||
"srt", | ||
"vtt", | ||
) | ||
} | ||
|
||
// ActionThumbnailFormats completes thumbnail formats | ||
// | ||
// jpg | ||
// png | ||
func ActionThumbnailFormats() carapace.Action { | ||
return carapace.ActionValues( | ||
"jpg", | ||
"png", | ||
"webp", | ||
) | ||
} | ||
|
||
// ActionVideoFormats completes video formats | ||
// | ||
// avi | ||
// flv | ||
func ActionVideoFormats() carapace.Action { | ||
return carapace.ActionValues( | ||
"avi", | ||
"flv", | ||
"gif", | ||
"mkv", | ||
"mov", | ||
"mp4", | ||
"webm", | ||
"aac", | ||
"aiff", | ||
"alac", | ||
"flac", | ||
"m4a", | ||
"mka", | ||
"mp3", | ||
"ogg", | ||
"opus", | ||
"vorbis", | ||
"wav", | ||
) | ||
} | ||
|
||
// ActionFormats completes formats | ||
// | ||
// 133 (426x240 - avc1 - none - 0) | ||
// 134 (640x360 - avc1 - none - 0) | ||
func ActionFormats(url string) carapace.Action { | ||
return actionDump(url, func(d dump) carapace.Action { | ||
vals := make([]string, 0) | ||
for _, format := range d.Formats { | ||
description := fmt.Sprintf("%v - %v - %v - %v", | ||
format.Resolution, | ||
strings.Split(format.Vcodec, ".")[0], | ||
strings.Split(format.Acodec, ".")[0], | ||
math.Round(format.Abr), | ||
) | ||
|
||
s := style.Default | ||
switch { | ||
case format.Vcodec == "none": | ||
s = style.Yellow | ||
} | ||
|
||
vals = append(vals, format.FormatID, description, s) // TODO enrich description | ||
} | ||
return carapace.ActionStyledValuesDescribed(vals...) | ||
}) | ||
} | ||
|
||
// ActionSubtitles completes subtitles | ||
// | ||
// en (English) | ||
// fr (French) | ||
func ActionSubtitles(url string) carapace.Action { | ||
return actionDump(url, func(d dump) carapace.Action { | ||
vals := make([]string, 0) | ||
for id, s := range d.Subtitles { | ||
vals = append(vals, id, s[0].Name) | ||
} | ||
return carapace.ActionValuesDescribed(vals...) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ytdlp | ||
|
||
import "github.com/rsteube/carapace" | ||
|
||
// ActionSponsorblockCategories completes sponsorblock categories | ||
// | ||
// sponsor | ||
// intro | ||
func ActionSponsorblockCategories() carapace.Action { | ||
return carapace.ActionValues( | ||
"sponsor", | ||
"intro", | ||
"outro", | ||
"selfpromo", | ||
"preview", | ||
"filler", | ||
"interaction", | ||
"music_offtopic", | ||
"poi_highlight", | ||
"chapter", | ||
"all", | ||
"default", | ||
) | ||
} |