package main import ( "flag" "fmt" "net/http" "os" "git.directme.in/Joren/CanvasArchiver/internal/auth" "git.directme.in/Joren/CanvasArchiver/internal/canvas" "git.directme.in/Joren/CanvasArchiver/internal/panopto" "git.directme.in/Joren/CanvasArchiver/internal/utils" ) 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{} authenticator := auth.NewAuthenticator(httpClient) accessToken, err := authenticator.GetAccessToken() if err != nil { fmt.Printf("Authentication failed: %v\n", err) 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) 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) return } courseRoot := utils.Sanitize(canvasClient.CourseName) fmt.Printf("[+] Target Course: %s\n", canvasClient.CourseName) os.MkdirAll(courseRoot, 0o755) canvasClient.DownloadCourseFiles(courseRoot) canvasClient.DownloadModules(courseRoot) if !filesOnly { panopto.DownloadMainRecordings(httpClient, accessToken, courseID, courseRoot) } }