Refactor downloaders to separate package to utilize an interface
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"main/downloaders"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@@ -35,7 +36,7 @@ func init() {
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
}
|
||||
|
||||
const DOWNLOAD_WORKERS = 1
|
||||
var downloader downloaders.Downloader = &downloaders.YTDLPLibDownloader{}
|
||||
|
||||
type DLHandler struct{}
|
||||
|
||||
@@ -65,7 +66,7 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
||||
}
|
||||
}()
|
||||
|
||||
err = DownloadR(data.Link)
|
||||
err = downloader.Download(data.Link)
|
||||
if err != nil {
|
||||
Error.Printf("Error downloading %s: %v", data.Link, err)
|
||||
return err
|
||||
@@ -75,9 +76,15 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// err := DownloadR("https://www.youtube.com/watch?v=QnvGX0C-LKE")
|
||||
// if err != nil {
|
||||
// Error.Printf("Error downloading: %v", err)
|
||||
// }
|
||||
// return
|
||||
|
||||
config := nsq.NewConfig()
|
||||
config.MaxAttempts = 5
|
||||
config.MaxInFlight = DOWNLOAD_WORKERS
|
||||
config.MaxInFlight = downloaders.DOWNLOAD_WORKERS
|
||||
config.MsgTimeout = 10 * time.Second
|
||||
|
||||
consumer, err := nsq.NewConsumer("ytdqueue", "dl", config)
|
||||
@@ -85,7 +92,7 @@ func main() {
|
||||
Error.Printf("Error creating consumer: %v", err)
|
||||
return
|
||||
}
|
||||
for i := 0; i < DOWNLOAD_WORKERS; i++ {
|
||||
for i := 0; i < downloaders.DOWNLOAD_WORKERS; i++ {
|
||||
consumer.AddHandler(&DLHandler{})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user