Implemented basic multi-platform support
This commit is contained in:
parent
44994bd14e
commit
e10528b00c
3 changed files with 71 additions and 8 deletions
10
config.toml
10
config.toml
|
@ -9,3 +9,13 @@ VideoFormat = "bestvideo[height<=720]"
|
||||||
AudioFormat = "bestaudio"
|
AudioFormat = "bestaudio"
|
||||||
NumVideos = 2
|
NumVideos = 2
|
||||||
SizeLimit = 4294967296
|
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
|
||||||
|
|
33
download.go
33
download.go
|
@ -53,7 +53,7 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VIDEO */
|
/* VIDEO */
|
||||||
{
|
if group.VideoFormat != "" {
|
||||||
log.Debugf("Downloading video \"%s\" with format \"%s\"", video.Info.ID, group.VideoFormat)
|
log.Debugf("Downloading video \"%s\" with format \"%s\"", video.Info.ID, group.VideoFormat)
|
||||||
|
|
||||||
videoDLResult, err := video.Download(context.Background(), 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 */
|
/* AUDIO */
|
||||||
{
|
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)
|
||||||
|
@ -92,13 +92,30 @@ func downloadVideo(url string, path string, group GroupConfig) (err error) {
|
||||||
file.Close()
|
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 {
|
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")
|
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 {
|
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")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
36
file.go
36
file.go
|
@ -21,3 +21,39 @@ func getExtension(filePath string) (extension string, err error) {
|
||||||
|
|
||||||
return kind.Extension, nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue