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" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sync"
) )
type ContentPageData struct { type ContentPageData struct {
@@ -97,10 +98,13 @@ func DownloadSingle(url string, subtitleLang string, parentDirectory string) {
fmt.Println() fmt.Println()
} }
func DownloadSeason(url string, seasonName string, subtitleLang string) { func DownloadSeason(url string, seasonName string, subtitleLang string, maxConcurrent int) {
id := ExtractContentId(url) id := ExtractContentId(url)
data := GetContentPageData(id) data := GetContentPageData(id)
var wg sync.WaitGroup
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" {
@@ -112,10 +116,22 @@ func DownloadSeason(url string, seasonName string, subtitleLang string) {
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
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 { func GetContentPageData(contentId string) *ContentPageData {

30
main.go
View File

@@ -1,18 +1,26 @@
package main package main
import ( import (
"jupiter_downloader/downloader" // "fmt"
"jupiter_downloader/downloader"
"flag"
) )
func main() { func main() {
// downloader.Download("1038278") // downloader.DownloadSingle("https://jupiter.err.ee/1038278/aktuaalne-kaamera", "", "")
downloader.DownloadSingle("https://jupiter.err.ee/1038278/aktuaalne-kaamera", "", "") urlParam := flag.String("url", "", "URL of the Jupiter show or movie you want to download")
// downloader.DownloadSingle("https://jupiter.err.ee/1609406782/babulon-berliin", "ET", "")
// downloader.DownloadSeason("https://jupiter.err.ee/1235599/babulon-berliin", "4", "ET") seasonNameParam := flag.String("seasonName", "", "Season of the show you want to download")
// fs := http.FileServer(http.Dir("static/")) maxConcurrentParam := flag.Int("maxConcurrent", 4, "Parameter to toggle how many episodes to download at the same time")
//
// http.Handle("/", fs) 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.")
//
// fmt.Println("Listening on 8080") flag.Parse()
// http.ListenAndServe(":8080", nil)
if *seasonNameParam != "" {
downloader.DownloadSeason(*urlParam, *seasonNameParam, *subtitleLanguageParam, *maxConcurrentParam)
} else {
downloader.DownloadSingle(*urlParam, *subtitleLanguageParam, "")
}
// fmt.Println(*urlParam, *seasonNameParam, *maxConcurrentParam, *subtitleLanguageParam)
} }