Added ExtractAudio option
Let's you extract audio from combined video+audio media (most websites supported by yt-dlp)
This commit is contained in:
parent
5e9774f70d
commit
7c72c89950
3 changed files with 65 additions and 10 deletions
31
download.go
31
download.go
|
@ -78,7 +78,28 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* AUDIO */
|
/* AUDIO */
|
||||||
if group.AudioFormat != "" {
|
if group.ExtractFormat != "" {
|
||||||
|
log.Debugf("Extracting audio from \"%s\" with format \"%s\"", video.Info.ID, group.ExtractFormat)
|
||||||
|
|
||||||
|
audioDLResult, err := video.Download(context.Background(), group.ExtractFormat)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer audioDLResult.Close()
|
||||||
|
|
||||||
|
file, err := os.OpenFile(tempPath+"-extract", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
io.Copy(file, audioDLResult)
|
||||||
|
|
||||||
|
audioDLResult.Close()
|
||||||
|
file.Close()
|
||||||
|
} else if group.AudioFormat != "" {
|
||||||
log.Debugf("Downloading audio \"%s\" with format \"%s\"", video.Info.ID, group.AudioFormat)
|
log.Debugf("Downloading audio \"%s\" with format \"%s\"", video.Info.ID, group.AudioFormat)
|
||||||
|
|
||||||
audioDLResult, err := video.Download(context.Background(), group.AudioFormat)
|
audioDLResult, err := video.Download(context.Background(), group.AudioFormat)
|
||||||
|
@ -112,6 +133,14 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
|
||||||
if err := os.Remove(tempPath+"-audio"); err != nil {
|
if err := os.Remove(tempPath+"-audio"); err != nil {
|
||||||
log.Warnf("Could not remove file \"%s\"", tempPath+"-audio")
|
log.Warnf("Could not remove file \"%s\"", tempPath+"-audio")
|
||||||
}
|
}
|
||||||
|
} else if group.ExtractFormat != "" {
|
||||||
|
if err := extractAudio(tempPath+"-extract", group.CFormat, path); err != nil {
|
||||||
|
log.Errorf("Could not extract audio from \"%s\" to \"%s\"", tempPath+"-extract", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Remove(tempPath+"-extract"); err != nil {
|
||||||
|
log.Warnf("Could not remove file \"%s\"", tempPath+"-extract")
|
||||||
|
}
|
||||||
} else if group.VideoFormat != "" {
|
} else if group.VideoFormat != "" {
|
||||||
copyFile(tempPath+"-vid", path)
|
copyFile(tempPath+"-vid", path)
|
||||||
|
|
||||||
|
|
23
ffmpeg.go
23
ffmpeg.go
|
@ -29,3 +29,26 @@ func mergeStreams(path1 string, path2 string, format string, output string) (err
|
||||||
|
|
||||||
return ffmpeg.Output(input, output, kwArgs).OverWriteOutput().ErrorToStdOut().Silent(silent).Run()
|
return ffmpeg.Output(input, output, kwArgs).OverWriteOutput().ErrorToStdOut().Silent(silent).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractAudio(path1 string, format string, output string) (err error) {
|
||||||
|
input := []*ffmpeg.Stream{ffmpeg.Input(path1)}
|
||||||
|
|
||||||
|
defaultArgs := ffmpeg.KwArgs{"map": "0:a", "c:a": "copy", "format": format}
|
||||||
|
|
||||||
|
var ffmpegLogLevel ffmpeg.KwArgs
|
||||||
|
var silent bool
|
||||||
|
|
||||||
|
if Flags.Verbose {
|
||||||
|
ffmpegLogLevel = ffmpeg.KwArgs{"v": "info"}
|
||||||
|
silent = false
|
||||||
|
} else if Flags.Quiet {
|
||||||
|
ffmpegLogLevel = ffmpeg.KwArgs{"v": "quiet"}
|
||||||
|
silent = true
|
||||||
|
} else {
|
||||||
|
ffmpegLogLevel = ffmpeg.KwArgs{"v": "error"}
|
||||||
|
silent = true
|
||||||
|
}
|
||||||
|
|
||||||
|
kwArgs := ffmpeg.MergeKwArgs([]ffmpeg.KwArgs{ffmpegLogLevel, defaultArgs})
|
||||||
|
return ffmpeg.Output(input, output, kwArgs).OverWriteOutput().ErrorToStdOut().Silent(silent).Run()
|
||||||
|
}
|
||||||
|
|
21
ytva.go
21
ytva.go
|
@ -41,15 +41,18 @@ type _config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupConfig struct {
|
type GroupConfig struct {
|
||||||
URL []string
|
URL []string
|
||||||
OutputDir string
|
OutputDir string
|
||||||
FileName string
|
FileName string
|
||||||
CFormat string
|
CFormat string
|
||||||
VideoFormat string
|
ExtractFormat string
|
||||||
AudioFormat string
|
VideoFormat string
|
||||||
NumVideos uint
|
AudioFormat string
|
||||||
SizeLimit float64
|
DownloadSubtitles bool // Currently useless
|
||||||
Filters []struct {
|
DownloadThumbnails bool // Currently useless
|
||||||
|
NumVideos uint
|
||||||
|
SizeLimit float64
|
||||||
|
Filters []struct {
|
||||||
Name string
|
Name string
|
||||||
Input string
|
Input string
|
||||||
Pattern string
|
Pattern string
|
||||||
|
|
Loading…
Reference in a new issue