diff --git a/config.toml b/config.toml index 5d73b2d..b7aad7c 100644 --- a/config.toml +++ b/config.toml @@ -9,3 +9,13 @@ VideoFormat = "bestvideo[height<=720]" AudioFormat = "bestaudio" NumVideos = 2 SizeLimit = 4294967296 + +[Group.Odysee] +URL = [ "https://odysee.com/@AlphaNerd:8", "https://odysee.com/@rossmanngroup:a" ] +OutputDir = "out2/%Channel%/" +FileName = "%Timestamp% - %Title%.mkv" +CFormat = "mp4" +VideoFormat = "best[height<=720]" +AudioFormat = "" +NumVideos = 2 +SizeLimit = 4294967296 diff --git a/download.go b/download.go index 3f4852f..055704d 100644 --- a/download.go +++ b/download.go @@ -53,7 +53,7 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) { } /* VIDEO */ - { + if group.VideoFormat != "" { log.Debugf("Downloading video \"%s\" with format \"%s\"", video.Info.ID, group.VideoFormat) videoDLResult, err := video.Download(context.Background(), group.VideoFormat) @@ -73,7 +73,7 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) { } /* AUDIO */ - { + if group.AudioFormat != "" { log.Debugf("Downloading audio \"%s\" with format \"%s\"", video.Info.ID, group.AudioFormat) audioDLResult, err := video.Download(context.Background(), group.AudioFormat) @@ -92,13 +92,30 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) { file.Close() } - mergeStreams(MainConfig.TempDir+"/"+video.Info.ID+"-vid",MainConfig.TempDir+"/"+video.Info.ID+"-audio", group.CFormat, path) + if group.VideoFormat != "" && group.AudioFormat != "" { + if err := mergeStreams(MainConfig.TempDir+"/"+video.Info.ID+"-vid",MainConfig.TempDir+"/"+video.Info.ID+"-audio", group.CFormat, path); err != nil { + log.Errorf("Could not merge files \"%s\" and \"%s\" to \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-vid", MainConfig.TempDir+"/"+video.Info.ID+"-audio", path) + } - if err := os.Remove(MainConfig.TempDir+"/"+video.Info.ID+"-vid"); err != nil { - log.Warnf("Could not remove file \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-vid") - } - if err := os.Remove(MainConfig.TempDir+"/"+video.Info.ID+"-audio"); err != nil { - log.Warnf("Could not remove file \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-audio") + if err := os.Remove(MainConfig.TempDir+"/"+video.Info.ID+"-vid"); err != nil { + log.Warnf("Could not remove file \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-vid") + } + if err := os.Remove(MainConfig.TempDir+"/"+video.Info.ID+"-audio"); err != nil { + log.Warnf("Could not remove file \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-audio") + } + } else if group.VideoFormat != "" { + copyFile(MainConfig.TempDir+"/"+video.Info.ID+"-vid", path) + + if err := os.Remove(MainConfig.TempDir+"/"+video.Info.ID+"-vid"); err != nil { + log.Warnf("Could not remove file \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-vid") + } + } else if group.AudioFormat != "" { + if err := copyFile(MainConfig.TempDir+"/"+video.Info.ID+"-audio", path); err != nil { + log.Errorf("Could not copy file \"%s\" to \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-audio", path) + } + if err := os.Remove(MainConfig.TempDir+"/"+video.Info.ID+"-audio"); err != nil { + log.Warnf("Could not remove file \"%s\"", MainConfig.TempDir+"/"+video.Info.ID+"-audio") + } } /* diff --git a/file.go b/file.go index b366039..15e3ff0 100644 --- a/file.go +++ b/file.go @@ -21,3 +21,39 @@ func getExtension(filePath string) (extension string, err error) { return kind.Extension, nil } + +func copyFile(src, dst string) (error) { + log.Debugf("Copying file \"%s\" to \"%s\"", src, dst) + + // Get source file stats (e.g. permissions). + srcFileStat, err := os.Stat(src) + if err != nil { + return fmt.Errorf("failed to get file info for %s: %v", src, err) + } + + // Check whether the source is a regular file. + if !srcFileStat.Mode().IsRegular() { + return fmt.Errorf("source file %s is not a regular file", src) + } + + // Open the source file. + srcFile, err := os.Open(src) + if err != nil { + return fmt.Errorf("failed to open source file %s: %v", src, err) + } + defer srcFile.Close() + + // Create the destination file, with the same permissions as the source. + dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, srcFileStat.Mode()) + if err != nil { + return fmt.Errorf("failed to create destination file %s: %v", dst, err) + } + defer dstFile.Close() + + // Copy the file contents from source to destination. + if _, err := io.Copy(dstFile, srcFile); err != nil { + return fmt.Errorf("error copying file from %s to %s: %v", src, dst, err) + } + + return nil +}