From c83229f3be7c9435895de98f988cfd0460bb7904 Mon Sep 17 00:00:00 2001 From: minie4 Date: Tue, 9 Jan 2024 13:51:24 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Put=20files=20in=20the=20correct=20?= =?UTF-8?q?subfolders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index cb8b5dd..155c8cf 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "minie4/itslearningdl/itslearning" "os" + "regexp" "sync" "github.com/charmbracelet/log" @@ -79,7 +80,7 @@ func main() { return "Downloading files" }) for _, resource := range resouceList { - var out_path = "./out/" + course.Title + "/" + resource.Title + var out_path = "./out" + sanitizePath(resource.Path) + "/" + resource.Title if _, err := os.Stat(out_path); err == nil { logger.Info("Skipping element", "course", course.Title, "element", resource.Title, "id", resource.ElementID) continue @@ -122,6 +123,11 @@ func fetchResourcesRecursive(itsl itslearning.Itslearning, course itslearning.Co } } +func sanitizePath(path string) string { + var regex = regexp.MustCompile(`\s*?/\s*`) + return regex.ReplaceAllString(path, "/") +} + func appendProgress(b *uiprogress.Bar) string { return fmt.Sprintf("%d/%d (%.2f%%)", b.Current(), b.Total, (float32(b.Current())/float32(b.Total))*100.0) }