Improve deletification
It was meant to run once and not as a service... So it's bursting at the seams But it will work I will make it work
This commit is contained in:
14
downloader/vendor/github.com/kkdai/youtube/v2/downloader/downloader.go
generated
vendored
14
downloader/vendor/github.com/kkdai/youtube/v2/downloader/downloader.go
generated
vendored
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -85,26 +86,28 @@ func (dl *Downloader) DownloadComposite(ctx context.Context, outputFile string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(videoFile.Name())
|
defer Delete(videoFile.Name(), log)
|
||||||
|
|
||||||
// Create temporary audio file
|
// Create temporary audio file
|
||||||
audioFile, err := os.CreateTemp(outputDir, "youtube_*.m4a")
|
audioFile, err := os.CreateTemp(outputDir, "youtube_*.m4a")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(audioFile.Name())
|
defer Delete(audioFile.Name(), log)
|
||||||
|
|
||||||
log.Debug("Downloading video file...")
|
log.Debug("Downloading video file...")
|
||||||
err = dl.videoDLWorker(ctx, videoFile, v, videoFormat)
|
err = dl.videoDLWorker(ctx, videoFile, v, videoFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
videoFile.Close()
|
||||||
|
|
||||||
log.Debug("Downloading audio file...")
|
log.Debug("Downloading audio file...")
|
||||||
err = dl.videoDLWorker(ctx, audioFile, v, audioFormat)
|
err = dl.videoDLWorker(ctx, audioFile, v, audioFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
audioFile.Close()
|
||||||
|
|
||||||
//nolint:gosec
|
//nolint:gosec
|
||||||
ffmpegVersionCmd := exec.Command("ffmpeg", "-y",
|
ffmpegVersionCmd := exec.Command("ffmpeg", "-y",
|
||||||
@@ -122,6 +125,13 @@ func (dl *Downloader) DownloadComposite(ctx context.Context, outputFile string,
|
|||||||
return ffmpegVersionCmd.Run()
|
return ffmpegVersionCmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Delete(path string, log *slog.Logger) {
|
||||||
|
err := os.Remove(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed deleting file", "path", path, "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getVideoAudioFormats(v *youtube.Video, quality string, mimetype, language string) (*youtube.Format, *youtube.Format, error) {
|
func getVideoAudioFormats(v *youtube.Video, quality string, mimetype, language string) (*youtube.Format, *youtube.Format, error) {
|
||||||
var videoFormats, audioFormats youtube.FormatList
|
var videoFormats, audioFormats youtube.FormatList
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user