added CLI flags
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ContentPageData struct {
|
||||
@@ -97,9 +98,12 @@ 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
|
||||
@@ -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
|
||||
|
||||
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 {
|
||||
|
||||
28
main.go
28
main.go
@@ -1,18 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"jupiter_downloader/downloader"
|
||||
"flag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// downloader.Download("1038278")
|
||||
downloader.DownloadSingle("https://jupiter.err.ee/1038278/aktuaalne-kaamera", "", "")
|
||||
// downloader.DownloadSingle("https://jupiter.err.ee/1609406782/babulon-berliin", "ET", "")
|
||||
// downloader.DownloadSeason("https://jupiter.err.ee/1235599/babulon-berliin", "4", "ET")
|
||||
// fs := http.FileServer(http.Dir("static/"))
|
||||
//
|
||||
// http.Handle("/", fs)
|
||||
//
|
||||
// fmt.Println("Listening on 8080")
|
||||
// http.ListenAndServe(":8080", nil)
|
||||
// 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")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user