73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
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")
|
|
moduleNumbers := flag.Bool("n", false, "Prefix modules with order numbers [1], [2], etc.")
|
|
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, *moduleNumbers)
|
|
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, *moduleNumbers)
|
|
}
|
|
return
|
|
}
|
|
|
|
var courseID string
|
|
fmt.Print("Enter Course ID: ")
|
|
fmt.Scanln(&courseID)
|
|
|
|
downloadCourse(httpClient, accessToken, courseID, *filesOnly, *moduleNumbers)
|
|
}
|
|
|
|
func downloadCourse(httpClient *http.Client, accessToken, courseID string, filesOnly, moduleNumbers bool) {
|
|
canvasClient := canvas.NewClient(httpClient, accessToken, courseID, filesOnly, moduleNumbers)
|
|
|
|
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)
|
|
}
|
|
}
|