added CLI flags

This commit is contained in:
gkiviv
2024-11-02 10:45:16 +02:00
parent a75d50c2a3
commit 3632bb4af5
2 changed files with 38 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"sync"
)
type ContentPageData struct {
@@ -97,10 +98,13 @@ func DownloadSingle(url string, subtitleLang string, parentDirectory string) {
fmt.Println()
}
func DownloadSeason(url string, seasonName string, subtitleLang string) {
func DownloadSeason(url string, seasonName string, subtitleLang string, maxConcurrent int) {
id := ExtractContentId(url)
data := GetContentPageData(id)
var wg sync.WaitGroup
currentConcurrent := 1
title := data.Data.MainContent.Title
seasonList := data.Data.SeasonList
if seasonList.Type != "seasonal" {
@@ -112,10 +116,22 @@ func DownloadSeason(url string, seasonName string, subtitleLang string) {
for _, seasonContent := range season.Contents {
parentDirName := title
_ = os.Mkdir(parentDirName, os.ModePerm) // dont care if directory fails to create
DownloadSingle(seasonContent.Url, subtitleLang, parentDirName)
if currentConcurrent < maxConcurrent {
wg.Add(1)
currentConcurrent++
go func() {
defer wg.Done()
fmt.Println("Running in parallel")
DownloadSingle(seasonContent.Url, subtitleLang, parentDirName)
}()
} else {
DownloadSingle(seasonContent.Url, subtitleLang, parentDirName)
}
}
}
}
wg.Wait()
}
func GetContentPageData(contentId string) *ContentPageData {