diff --git a/downloader/downloader.go b/downloader/downloader.go index c56cb70..72c0543 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -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) + } } } } diff --git a/downloader/downloader_test.go b/downloader/downloader_test.go index 9b3ed01..90b017a 100644 --- a/downloader/downloader_test.go +++ b/downloader/downloader_test.go @@ -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) } } diff --git a/main.go b/main.go index 6be6456..7ab6459 100644 --- a/main.go +++ b/main.go @@ -1,26 +1,30 @@ package main import ( - // "fmt" - "jupiter_downloader/downloader" "flag" + "fmt" + "jupiter_downloader/downloader" ) func main() { - // downloader.DownloadSingle("https://jupiter.err.ee/1038278/aktuaalne-kaamera", "", "") urlParam := flag.String("url", "", "URL of the Jupiter show or movie you want to download") - seasonNameParam := flag.String("seasonName", "", "Season of the show you want to download") - maxConcurrentParam := flag.Int("maxConcurrent", 4, "Parameter to toggle how many episodes to download at the same time") - + maxConcurrentParam := flag.Int("maxConcurrent", 1, "Parameter to toggle how many episodes to download at the same time") subtitleLanguageParam := flag.String("subtitleLanguage", "ET", "Parameter to toggle what subtitles you want to download. (ET, EN). NB! Jupiter may not have subtitles in your language of choice.") - - flag.Parse() - - if *seasonNameParam != "" { - downloader.DownloadSeason(*urlParam, *seasonNameParam, *subtitleLanguageParam, *maxConcurrentParam) - } else { - downloader.DownloadSingle(*urlParam, *subtitleLanguageParam, "") - } - // fmt.Println(*urlParam, *seasonNameParam, *maxConcurrentParam, *subtitleLanguageParam) + + flag.Parse() + + if *urlParam == "" { + fmt.Print("Enter the url: ") + _, err := fmt.Scanln(urlParam) + if err != nil { + panic(err) + } + } + + if *seasonNameParam != "" { + downloader.DownloadSeason(*urlParam, *seasonNameParam, *subtitleLanguageParam, *maxConcurrentParam) + } else { + downloader.DownloadSingle(*urlParam, *subtitleLanguageParam, "") + } }