Add files only mode

This commit is contained in:
2026-03-11 17:37:18 +01:00
parent c9fa079893
commit 352315b041
2 changed files with 36 additions and 7 deletions

View File

@@ -21,13 +21,15 @@ type Client struct {
AccessToken string
CourseID string
CourseName string
FilesOnly bool
}
func NewClient(httpClient *http.Client, accessToken, courseID string) *Client {
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly bool) *Client {
return &Client{
HTTPClient: httpClient,
AccessToken: accessToken,
CourseID: courseID,
FilesOnly: filesOnly,
}
}
@@ -83,7 +85,10 @@ func (c *Client) DownloadCourseFiles(root string) {
rawFolderPath := folderMap[file.FolderID]
safeFolderPath := utils.SanitizePath(rawFolderPath)
subDir := filepath.Join(root, "Course Files", safeFolderPath)
subDir := root
if !c.FilesOnly {
subDir = filepath.Join(root, "Course Files", safeFolderPath)
}
os.MkdirAll(subDir, 0o755)
path := filepath.Join(subDir, utils.Sanitize(file.DisplayName))
@@ -125,9 +130,15 @@ func (c *Client) DownloadModules(courseRoot string) {
resp.Body.Close()
for _, mod := range modules {
modBaseDir := filepath.Join(courseRoot, "Modules", utils.Sanitize(mod.Name))
modBaseDir := courseRoot
if !c.FilesOnly {
modBaseDir = filepath.Join(courseRoot, "Modules", utils.Sanitize(mod.Name))
}
os.MkdirAll(modBaseDir, 0o755)
fmt.Printf("\n[Module] %s\n", mod.Name)
if !c.FilesOnly {
fmt.Printf("\n[Module] %s\n", mod.Name)
}
subHeaderStack := []string{}
lastIndent := 0
@@ -135,13 +146,16 @@ func (c *Client) DownloadModules(courseRoot string) {
for _, item := range mod.Items {
targetDir := modBaseDir
if len(subHeaderStack) > 0 {
if len(subHeaderStack) > 0 && !c.FilesOnly {
targetDir = filepath.Join(modBaseDir, filepath.Join(subHeaderStack...))
}
os.MkdirAll(targetDir, 0o755)
switch item.Type {
case "SubHeader":
if c.FilesOnly {
continue
}
currentIndent := item.Indent
if currentIndent <= lastIndent && len(subHeaderStack) > 0 {
levelsToKeep := currentIndent
@@ -162,11 +176,17 @@ func (c *Client) DownloadModules(courseRoot string) {
c.downloadModuleFile(item, targetDir)
case "ExternalTool":
if c.FilesOnly {
continue
}
indent := strings.Repeat(" ", len(subHeaderStack)+1)
fmt.Printf("%s- Found video tool: %s\n", indent, item.Title)
panopto.DownloadVideo(c.HTTPClient, c.AccessToken, c.CourseID, targetDir, item.URL, item.Title)
case "ExternalUrl":
if c.FilesOnly {
continue
}
if strings.Contains(item.ExternalURL, "panopto.eu") {
indent := strings.Repeat(" ", len(subHeaderStack)+1)
fmt.Printf("%s- Found direct video link: %s\n", indent, item.Title)
@@ -175,6 +195,9 @@ func (c *Client) DownloadModules(courseRoot string) {
}
case "Page":
if c.FilesOnly {
continue
}
c.searchPageForVideos(item, targetDir)
}
}