Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 79 additions & 48 deletions README.md

Large diffs are not rendered by default.

63 changes: 38 additions & 25 deletions cmd/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/goccy/go-yaml"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/scheduler"
"github.com/tanq16/danzo/internal/utils"
Expand All @@ -26,21 +27,26 @@ func newBatchCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
yamlFile := args[0]
data, err := os.ReadFile(yamlFile)
log.Debug().Str("op", "cmd/batch").Msgf("Reading YAML file: %s", yamlFile)
if err != nil {
log.Error().Str("op", "cmd/batch").Msgf("Error reading YAML file: %v", err)
fmt.Fprintf(os.Stderr, "Error reading YAML file: %v\n", err)
os.Exit(1)
}
var batchFile BatchFile
if err := yaml.Unmarshal(data, &batchFile); err != nil {
log.Error().Str("op", "cmd/batch").Msgf("Error parsing YAML file: %v", err)
fmt.Fprintf(os.Stderr, "Error parsing YAML file: %v\n", err)
os.Exit(1)
}
jobs := buildJobsFromBatch(batchFile)
if len(jobs) == 0 {
log.Error().Str("op", "cmd/batch").Msgf("No valid jobs found in the batch file")
fmt.Fprintf(os.Stderr, "No valid jobs found in the batch file\n")
os.Exit(1)
}
scheduler.Run(jobs, workers, fileLog)
log.Debug().Str("op", "cmd/batch").Msgf("Starting scheduler with %d jobs", len(jobs))
scheduler.Run(jobs, workers)
},
}
return cmd
Expand All @@ -51,11 +57,13 @@ func buildJobsFromBatch(batchFile BatchFile) []utils.DanzoJob {
for jobType, entries := range batchFile {
normalizedType := normalizeJobType(jobType)
if normalizedType == "" {
log.Warn().Str("op", "cmd/batch").Msgf("Unknown job type '%s', skipping...", jobType)
fmt.Fprintf(os.Stderr, "Warning: Unknown job type '%s', skipping...\n", jobType)
continue
}
for _, entry := range entries {
if entry.Link == "" {
log.Warn().Str("op", "cmd/batch").Msgf("Empty link found in %s section, skipping...", jobType)
fmt.Fprintf(os.Stderr, "Warning: Empty link found in %s section, skipping...\n", jobType)
continue
}
Expand All @@ -67,14 +75,14 @@ func buildJobsFromBatch(batchFile BatchFile) []utils.DanzoJob {
Metadata: make(map[string]any),
}
switch normalizedType {
case "http", "gdrive", "ghrelease", "m3u8":
case "http", "google-drive", "github-release", "live-stream":
job.Connections = connections
job.ProgressType = "progress"
case "s3":
job.Connections = connections
job.ProgressType = "progress"
job.Metadata["profile"] = "default"
case "youtube", "ytmusic", "gitclone":
case "youtube", "youtube-music", "git-clone":
job.ProgressType = "stream"
default:
job.ProgressType = "progress"
Expand All @@ -83,31 +91,36 @@ func buildJobsFromBatch(batchFile BatchFile) []utils.DanzoJob {
jobs = append(jobs, job)
}
}
log.Debug().Str("op", "cmd/batch").Msgf("Built %d jobs from batch file", len(jobs))
return jobs
}

func normalizeJobType(jobType string) string {
typeMap := map[string]string{
"http": "http",
"https": "http",
"s3": "s3",
"gdrive": "gdrive",
"googledrive": "gdrive",
"google-drive": "gdrive",
"gitclone": "gitclone",
"git-clone": "gitclone",
"git": "gitclone",
"ghrelease": "ghrelease",
"gh-release": "ghrelease",
"github": "ghrelease",
"github-release": "ghrelease",
"m3u8": "m3u8",
"hls": "m3u8",
"youtube": "youtube",
"yt": "youtube",
"ytmusic": "ytmusic",
"youtube-music": "ytmusic",
"yt-music": "ytmusic",
"http": "http",
"https": "http",
"s3": "s3",
"gdrive": "google-drive",
"googledrive": "google-drive",
"google-drive": "google-drive",
"gitclone": "git-clone",
"git-clone": "git-clone",
"git": "git-clone",
"ghr": "github-release",
"ghrelease": "github-release",
"gh-release": "github-release",
"github": "github-release",
"github-release": "github-release",
"m3u8": "live-stream",
"hls": "live-stream",
"http-livestream": "live-stream",
"live-stream": "live-stream",
"youtube": "youtube",
"yt": "youtube",
"ytm": "yt-music",
"ytmusic": "yt-music",
"youtube-music": "yt-music",
"yt-music": "yt-music",
}
normalized := ""
for key, value := range typeMap {
Expand All @@ -125,9 +138,9 @@ func addJobTypeSpecificMetadata(job *utils.DanzoJob, jobType string) {
if _, ok := job.Metadata["format"]; !ok {
job.Metadata["format"] = "decent"
}
case "ghrelease":
case "github-release":
job.Metadata["manual"] = false
case "gitclone":
case "git-clone":
if _, ok := job.Metadata["depth"]; !ok {
job.Metadata["depth"] = 0
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"path/filepath"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/utils"
)
Expand All @@ -14,8 +15,10 @@ func newCleanCmd() *cobra.Command {
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Debug().Str("op", "cmd/clean").Msgf("Cleaning local files in current directory")
utils.CleanLocal()
} else {
log.Debug().Str("op", "cmd/clean").Msgf("Cleaning local files in %s", filepath.Dir(args[0]))
utils.CleanFunction(filepath.Dir(args[0]))
}
},
Expand Down
13 changes: 8 additions & 5 deletions cmd/gitclone.go → cmd/git-clone.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/scheduler"
"github.com/tanq16/danzo/internal/utils"
Expand All @@ -13,12 +14,13 @@ func newGitCloneCmd() *cobra.Command {
var sshKey string

cmd := &cobra.Command{
Use: "gitclone [REPO_URL] [--output OUTPUT_PATH] [--depth DEPTH] [--token GIT_TOKEN] [--ssh SSH_KEY_PATH]",
Short: "Clone a Git repository",
Args: cobra.ExactArgs(1),
Use: "git-clone [REPO_URL] [--output OUTPUT_PATH] [--depth DEPTH] [--token GIT_TOKEN] [--ssh SSH_KEY_PATH]",
Short: "Clone a Git repository",
Aliases: []string{"gitclone", "gitc", "git", "clone"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
job := utils.DanzoJob{
JobType: "gitclone",
JobType: "git-clone",
URL: args[0],
OutputPath: outputPath,
ProgressType: "stream",
Expand All @@ -35,7 +37,8 @@ func newGitCloneCmd() *cobra.Command {
job.Metadata["sshKey"] = sshKey
}
jobs := []utils.DanzoJob{job}
scheduler.Run(jobs, workers, fileLog)
log.Debug().Str("op", "cmd/git-clone").Msgf("Starting scheduler with %d jobs", len(jobs))
scheduler.Run(jobs, workers)
},
}

Expand Down
13 changes: 8 additions & 5 deletions cmd/ghrelease.go → cmd/github-release.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/scheduler"
"github.com/tanq16/danzo/internal/utils"
Expand All @@ -11,12 +12,13 @@ func newGHReleaseCmd() *cobra.Command {
var manual bool

cmd := &cobra.Command{
Use: "ghrelease [USER/REPO or URL] [--output OUTPUT_PATH] [--manual]",
Short: "Download a release asset for a GitHub repository",
Args: cobra.ExactArgs(1),
Use: "github-release [USER/REPO or URL] [--output OUTPUT_PATH] [--manual]",
Short: "Download a release asset for a GitHub repository",
Aliases: []string{"ghrelease", "ghr"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
job := utils.DanzoJob{
JobType: "ghrelease",
JobType: "github-release",
URL: args[0],
OutputPath: outputPath,
Connections: connections,
Expand All @@ -26,7 +28,8 @@ func newGHReleaseCmd() *cobra.Command {
}
job.Metadata["manual"] = manual
jobs := []utils.DanzoJob{job}
scheduler.Run(jobs, workers, fileLog)
log.Debug().Str("op", "cmd/github-release").Msgf("Starting scheduler with %d jobs", len(jobs))
scheduler.Run(jobs, workers)
},
}

Expand Down
13 changes: 8 additions & 5 deletions cmd/gdrive.go → cmd/google-drive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/scheduler"
"github.com/tanq16/danzo/internal/utils"
Expand All @@ -12,12 +13,13 @@ func newGDriveCmd() *cobra.Command {
var credentialsFile string

cmd := &cobra.Command{
Use: "gdrive [URL] [--output OUTPUT_PATH] [--api-key YOUR_KEY] [--creds creds.json]",
Short: "Download files or folders from Google Drive",
Args: cobra.ExactArgs(1),
Use: "google-drive [URL] [--output OUTPUT_PATH] [--api-key YOUR_KEY] [--creds creds.json]",
Short: "Download files or folders from Google Drive",
Aliases: []string{"gdrive", "gd", "drive"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
job := utils.DanzoJob{
JobType: "gdrive",
JobType: "google-drive",
URL: args[0],
OutputPath: outputPath,
Connections: connections,
Expand All @@ -32,7 +34,8 @@ func newGDriveCmd() *cobra.Command {
job.Metadata["credentialsFile"] = credentialsFile
}
jobs := []utils.DanzoJob{job}
scheduler.Run(jobs, workers, fileLog)
log.Debug().Str("op", "cmd/google-drive").Msgf("Starting scheduler with %d jobs", len(jobs))
scheduler.Run(jobs, workers)
},
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/scheduler"
"github.com/tanq16/danzo/internal/utils"
Expand All @@ -25,7 +26,8 @@ func newHTTPCmd() *cobra.Command {
Metadata: make(map[string]any),
}
jobs := []utils.DanzoJob{job}
scheduler.Run(jobs, workers, fileLog)
log.Debug().Str("op", "cmd/http").Msgf("Starting scheduler with %d jobs", len(jobs))
scheduler.Run(jobs, workers)
},
}

Expand Down
13 changes: 8 additions & 5 deletions cmd/m3u8.go → cmd/live-stream.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/tanq16/danzo/internal/scheduler"
"github.com/tanq16/danzo/internal/utils"
Expand All @@ -10,12 +11,13 @@ func newM3U8Cmd() *cobra.Command {
var outputPath string

cmd := &cobra.Command{
Use: "m3u8 [URL] [--output OUTPUT_PATH]",
Short: "Download HLS/M3U8 streams",
Args: cobra.ExactArgs(1),
Use: "live-stream [URL] [--output OUTPUT_PATH]",
Short: "Download HLS/M3U8 live streams",
Aliases: []string{"hls", "m3u8", "livestream", "stream"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
job := utils.DanzoJob{
JobType: "m3u8",
JobType: "live-stream",
URL: args[0],
OutputPath: outputPath,
Connections: connections,
Expand All @@ -24,7 +26,8 @@ func newM3U8Cmd() *cobra.Command {
Metadata: make(map[string]any),
}
jobs := []utils.DanzoJob{job}
scheduler.Run(jobs, workers, fileLog)
log.Debug().Str("op", "cmd/live-stream").Msgf("Starting scheduler with %d jobs", len(jobs))
scheduler.Run(jobs, workers)
},
}

Expand Down
Loading