Refactor downloaders to separate package to utilize an interface
This commit is contained in:
57
downloader/downloaders/ytdlp-lib.go
Normal file
57
downloader/downloaders/ytdlp-lib.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package downloaders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gen2brain/beeep"
|
||||
"github.com/lrstanley/go-ytdlp"
|
||||
)
|
||||
|
||||
var dl = ytdlp.New().
|
||||
// FormatSort("bestvideo[ext=mp4]+bestaudio[ext=m4a]").
|
||||
FormatSort("res,ext:mp4:m4a").
|
||||
Output("C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s").
|
||||
LimitRate(fmt.Sprintf("%dM", 150/DOWNLOAD_WORKERS)).
|
||||
// HTTPChunkSize("20M").
|
||||
MarkWatched().
|
||||
SponsorblockMark("all").
|
||||
RecodeVideo("mp4").
|
||||
ConcurrentFragments(6)
|
||||
|
||||
type YTDLPLibDownloader struct{}
|
||||
|
||||
func (d *YTDLPLibDownloader) Download(url string) error {
|
||||
_, ongoing := ongoingDownloads[url]
|
||||
if ongoing {
|
||||
// return fmt.Errorf("Download %s is already ongoing", url)
|
||||
log.Printf("Download %s is already ongoing", url)
|
||||
return nil
|
||||
}
|
||||
ongoingDownloadsMutex.Lock()
|
||||
ongoingDownloads[url] = struct{}{}
|
||||
ongoingDownloadsMutex.Unlock()
|
||||
|
||||
log.Printf("Downloading %s", url)
|
||||
|
||||
err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
|
||||
if err != nil {
|
||||
log.Printf("Failed beeping with %+v", err)
|
||||
}
|
||||
err = beeep.Alert("Download Started", url, "assets/information.png")
|
||||
if err != nil {
|
||||
log.Printf("Failed alerting with %+v", err)
|
||||
}
|
||||
|
||||
_, err = dl.Run(context.TODO(), url)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed downloading %s with %+v", url, err)
|
||||
}
|
||||
|
||||
log.Printf("Downloaded %s", url)
|
||||
ongoingDownloadsMutex.Lock()
|
||||
delete(ongoingDownloads, url)
|
||||
ongoingDownloadsMutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user