Add support to download all the users courses

This commit is contained in:
joren
2026-03-11 19:36:54 +01:00
parent 11d9867155
commit 8591ae283e
3 changed files with 38 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import (
func main() {
filesOnly := flag.Bool("fo", false, "Files only mode - download all files to a single directory without module structure")
me := flag.Bool("me", false, "Download all enrolled courses")
flag.Parse()
httpClient := &http.Client{}
@@ -25,11 +26,31 @@ func main() {
return
}
if *me {
canvasClient := canvas.NewClient(httpClient, accessToken, "", *filesOnly)
courses, err := canvasClient.GetEnrolledCourses()
if err != nil {
fmt.Printf("Error fetching courses: %v\n", err)
return
}
fmt.Printf("[+] Found %d enrolled courses\n", len(courses))
for _, course := range courses {
fmt.Printf(" -> Downloading: %s (ID: %d)\n", course.Name, course.ID)
downloadCourse(httpClient, accessToken, fmt.Sprintf("%d", course.ID), *filesOnly)
}
return
}
var courseID string
fmt.Print("Enter Course ID: ")
fmt.Scanln(&courseID)
canvasClient := canvas.NewClient(httpClient, accessToken, courseID, *filesOnly)
downloadCourse(httpClient, accessToken, courseID, *filesOnly)
}
func downloadCourse(httpClient *http.Client, accessToken, courseID string, filesOnly bool) {
canvasClient := canvas.NewClient(httpClient, accessToken, courseID, filesOnly)
if err := canvasClient.GetCourseInfo(); err != nil {
fmt.Printf("Error: %v\n", err)
@@ -44,7 +65,7 @@ func main() {
canvasClient.DownloadModules(courseRoot)
if !*filesOnly {
if !filesOnly {
panopto.DownloadMainRecordings(httpClient, accessToken, courseID, courseRoot)
}
}