Limit download speed to not kill internet

This commit is contained in:
2024-06-21 22:23:02 +02:00
parent be38b3d602
commit 089e7f637f
2 changed files with 12 additions and 4 deletions

View File

@@ -13,12 +13,12 @@ var dl = ytdlp.New().
// FormatSort("bestvideo[ext=mp4]+bestaudio[ext=m4a]"). // FormatSort("bestvideo[ext=mp4]+bestaudio[ext=m4a]").
FormatSort("res,ext:mp4:m4a"). FormatSort("res,ext:mp4:m4a").
Output("C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s"). Output("C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s").
LimitRate("50M"). LimitRate("5M").
// HTTPChunkSize("20M"). // HTTPChunkSize("20M").
MarkWatched(). MarkWatched().
SponsorblockMark("all"). SponsorblockMark("all").
RecodeVideo("mp4"). RecodeVideo("mp4").
ConcurrentFragments(4) ConcurrentFragments(6)
// func Download(event PBEvent, status chan error) { // func Download(event PBEvent, status chan error) {
// _, err := dl.Run(context.TODO(), event.Record.Link) // _, err := dl.Run(context.TODO(), event.Record.Link)
@@ -40,4 +40,5 @@ func DownloadURL(url string, status chan error) {
} }
log.Printf("Downloaded %s", url) log.Printf("Downloaded %s", url)
close(status)
} }

View File

@@ -43,13 +43,20 @@ func main() {
ws.url = WEBSOCKET_SERVER ws.url = WEBSOCKET_SERVER
ws.Open() ws.Open()
status := make(chan error, 16) sem := make(chan struct{}, 4)
for { for {
select { select {
case event := <-ws.ReadChan: case event := <-ws.ReadChan:
eventCopy := event eventCopy := event
log.Printf("New event: %+v", eventCopy) status := make(chan error)
sem <- struct{}{}
log.Printf("New event: %+v; semaphore at: %d", eventCopy, len(sem))
go func() { go func() {
defer func() {
<-sem
log.Printf("Semaphore at: %d", len(sem))
}()
// Download(eventCopy, status) // Download(eventCopy, status)
DownloadURL(eventCopy, status) DownloadURL(eventCopy, status)
// go DownloadNative(event, status) // go DownloadNative(event, status)