Compare commits

...

4 commits

Author SHA1 Message Date
5e569df5ab
Adding (currently useless) options to yt-dlp 2025-01-03 18:30:40 -07:00
f62e8232d6
Cleaned up example config 2025-01-03 18:30:32 -07:00
1d454fb886
Added ExtractAudio example 2025-01-03 18:30:19 -07:00
7c72c89950
Added ExtractAudio option
Let's you extract audio from combined video+audio media (most websites
supported by yt-dlp)
2025-01-03 18:29:08 -07:00
4 changed files with 83 additions and 15 deletions

View file

@ -2,7 +2,7 @@ TempDir = "/tmp/"
[Group.LinuxYouTubers]
URL = [ "https://www.youtube.com/@DistroTube", "https://www.youtube.com/@MentalOutlaw" ]
OutputDir = "videos/%Channel%/%Playlist%/"
OutputDir = "videos/Linux/%Channel%/%Playlist%/"
FileName = "%Timestamp% - %Title%.mkv"
CFormat = "matroska"
VideoFormat = "bestvideo[height<=720]"
@ -12,16 +12,16 @@ SizeLimit = 200000000
[Group.Odysee]
URL = [ "https://odysee.com/@DistroTube:2", "https://odysee.com/@AlphaNerd:8" ]
OutputDir = "videos2/%Channel%/"
OutputDir = "videos/Odysee/%Channel%/"
FileName = "%Timestamp% - %Title%.mp4"
CFormat = "mp4"
VideoFormat = "best[height<=720]"
NumVideos = 5
SizeLimit = 200000000
[Group.Music]
[Group.YouTubeMusic]
URL = [ "https://www.youtube.com/@NoCopyrightSounds", "https://www.youtube.com/@incompetech_kmac" ]
OutputDir = "music/%Channel%/"
OutputDir = "videos/Music/%Channel%/"
FileName = "%Title%.webm"
CFormat = "webm"
AudioFormat = "bestaudio"
@ -30,3 +30,12 @@ SizeLimit = 10000000
Filters = [
{Name = "No Shorts", Input = "%Playlist%", Pattern = ".*- Shorts$", AllowDeny = false}
]
[Group.OdyseeAudio]
URL = [ "https://odysee.com/@DistroTube:2", "https://odysee.com/@AlphaNerd:8" ]
OutputDir = "videos/Audio/%Channel%/"
FileName = "%Timestamp% - %Title%.m4a"
CFormat = "ipod"
ExtractFormat = "best"
NumVideos = 5
SizeLimit = 10000000

View file

@ -43,7 +43,11 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
log.Debugf("URL \"%s\" exists.", url)
video, err := goutubedl.New(context.Background(), url, goutubedl.Options{})
video, err := goutubedl.New(context.Background(), url, goutubedl.Options{
MergeOutputFormat: "",
DownloadSubtitles: group.DownloadSubtitles,
DownloadThumbnail: group.DownloadThumbnails,
})
if err != nil {
return err
}
@ -78,7 +82,28 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
}
/* 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)
audioDLResult, err := video.Download(context.Background(), group.AudioFormat)
@ -112,6 +137,14 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
if err := os.Remove(tempPath+"-audio"); err != nil {
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 != "" {
copyFile(tempPath+"-vid", path)

View file

@ -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()
}
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
View file

@ -41,15 +41,18 @@ type _config struct {
}
type GroupConfig struct {
URL []string
OutputDir string
FileName string
CFormat string
VideoFormat string
AudioFormat string
NumVideos uint
SizeLimit float64
Filters []struct {
URL []string
OutputDir string
FileName string
CFormat string
ExtractFormat string
VideoFormat string
AudioFormat string
DownloadSubtitles bool // Currently useless
DownloadThumbnails bool // Currently useless
NumVideos uint
SizeLimit float64
Filters []struct {
Name string
Input string
Pattern string