More better rate limiting

This commit is contained in:
2024-10-13 22:53:43 +02:00
parent ca3c3423b1
commit 48179c3a67
2 changed files with 16 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"log"
"sync"
@@ -12,7 +13,7 @@ import (
const OUTPUT_DIR = "C:/Users/Administrator/ytdlpVideos"
type DownloadWorker struct {
id int
id int
input chan *DownloadTask
}
@@ -23,7 +24,7 @@ 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("10M").
LimitRate(fmt.Sprintf("%dM", 100/DOWNLOAD_WORKERS)).
// HTTPChunkSize("20M").
MarkWatched().
SponsorblockMark("all").
@@ -56,13 +57,13 @@ func (w *DownloadWorker) Run() {
if err != nil {
log.Printf("Failed alerting with %+v", err)
}
_, err = dl.Run(context.TODO(), task.Url)
if err != nil {
log.Printf("DownloadWorker %d: Failed downloading %s with %+v", w.id, task.Url, err)
continue
}
log.Printf("DownloadWorker %d: Downloaded %s", w.id, task.Url)
ongoingDownloadsMutex.Lock()
delete(ongoingDownloads, task.Url)