add video-only mode

This commit is contained in:
2026-05-16 17:33:40 +02:00
parent 14a71e7dca
commit 13063c6cc5
3 changed files with 44 additions and 17 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")
videosOnly := flag.Bool("vo", false, "Videos only mode - download only Panopto videos to a single directory")
me := flag.Bool("me", false, "Download all enrolled courses")
moduleNumbers := flag.Bool("n", false, "Prefix modules with order numbers [1], [2], etc.")
flag.Parse()
@@ -28,7 +29,7 @@ func main() {
}
if *me {
canvasClient := canvas.NewClient(httpClient, accessToken, "", *filesOnly, *moduleNumbers)
canvasClient := canvas.NewClient(httpClient, accessToken, "", *filesOnly, *videosOnly, *moduleNumbers)
courses, err := canvasClient.GetEnrolledCourses()
if err != nil {
fmt.Printf("Error fetching courses: %v\n", err)
@@ -38,7 +39,7 @@ func main() {
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)
downloadCourse(httpClient, accessToken, fmt.Sprintf("%d", course.ID), *filesOnly, *videosOnly, *moduleNumbers)
}
return
}
@@ -47,11 +48,11 @@ func main() {
fmt.Print("Enter Course ID: ")
fmt.Scanln(&courseID)
downloadCourse(httpClient, accessToken, courseID, *filesOnly, *moduleNumbers)
downloadCourse(httpClient, accessToken, courseID, *filesOnly, *videosOnly, *moduleNumbers)
}
func downloadCourse(httpClient *http.Client, accessToken, courseID string, filesOnly, moduleNumbers bool) {
canvasClient := canvas.NewClient(httpClient, accessToken, courseID, filesOnly, moduleNumbers)
func downloadCourse(httpClient *http.Client, accessToken, courseID string, filesOnly, videosOnly, moduleNumbers bool) {
canvasClient := canvas.NewClient(httpClient, accessToken, courseID, filesOnly, videosOnly, moduleNumbers)
if err := canvasClient.GetCourseInfo(); err != nil {
fmt.Printf("Error: %v\n", err)
@@ -66,7 +67,8 @@ func downloadCourse(httpClient *http.Client, accessToken, courseID string, files
canvasClient.DownloadModules(courseRoot)
if !filesOnly {
panopto.DownloadMainRecordings(httpClient, accessToken, courseID, courseRoot)
// Run recordings: always in -vo mode; skipped in -fo mode; normal otherwise.
if videosOnly || !filesOnly {
panopto.DownloadMainRecordings(httpClient, accessToken, courseID, courseRoot, videosOnly)
}
}