added CLI flags
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user