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

View File

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

34
main.go
View File

@@ -1,26 +1,30 @@
package main package main
import ( import (
// "fmt"
"jupiter_downloader/downloader"
"flag" "flag"
"fmt"
"jupiter_downloader/downloader"
) )
func main() { 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") 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") 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.") 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() flag.Parse()
if *seasonNameParam != "" { if *urlParam == "" {
downloader.DownloadSeason(*urlParam, *seasonNameParam, *subtitleLanguageParam, *maxConcurrentParam) fmt.Print("Enter the url: ")
} else { _, err := fmt.Scanln(urlParam)
downloader.DownloadSingle(*urlParam, *subtitleLanguageParam, "") if err != nil {
} panic(err)
// fmt.Println(*urlParam, *seasonNameParam, *maxConcurrentParam, *subtitleLanguageParam) }
}
if *seasonNameParam != "" {
downloader.DownloadSeason(*urlParam, *seasonNameParam, *subtitleLanguageParam, *maxConcurrentParam)
} else {
downloader.DownloadSingle(*urlParam, *subtitleLanguageParam, "")
}
} }