cleaned code, flags

This commit is contained in:
gkiviv
2024-11-03 13:41:17 +02:00
parent 3632bb4af5
commit d985d89e9b
3 changed files with 36 additions and 32 deletions

View File

@@ -102,9 +102,9 @@ func DownloadSeason(url string, seasonName string, subtitleLang string, maxConcu
id := ExtractContentId(url)
data := GetContentPageData(id)
var wg sync.WaitGroup
currentConcurrent := 1
currentConcurrent := 1
title := data.Data.MainContent.Title
seasonList := data.Data.SeasonList
if seasonList.Type != "seasonal" {
@@ -116,18 +116,18 @@ func DownloadSeason(url string, seasonName string, subtitleLang string, maxConcu
for _, seasonContent := range season.Contents {
parentDirName := title
_ = os.Mkdir(parentDirName, os.ModePerm) // dont care if directory fails to create
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)
}
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)
}
}
}
}

View File

@@ -49,8 +49,8 @@ func TestDownloadUrl(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("bad status: %s", resp.Status)
t.Fatalf("bad status: %s", resp.Status)
}
}