Implemented basic multi-platform support

This commit is contained in:
Logan G 2024-12-31 17:48:18 -07:00
parent 44994bd14e
commit e10528b00c
Signed by: logan
GPG key ID: E328528C921E7A7A
3 changed files with 71 additions and 8 deletions

View file

@ -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

View file

@ -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,7 +92,10 @@ 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")
@ -100,6 +103,20 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
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")
}
}
/*
extension, err := getExtension(path)

36
file.go
View file

@ -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
}