add video-only mode
This commit is contained in:
@@ -22,16 +22,18 @@ type Client struct {
|
||||
CourseID string
|
||||
CourseName string
|
||||
FilesOnly bool
|
||||
VideosOnly bool
|
||||
ModuleNumbers bool
|
||||
downloadedFiles map[string]bool
|
||||
}
|
||||
|
||||
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly, moduleNumbers bool) *Client {
|
||||
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly, videosOnly, moduleNumbers bool) *Client {
|
||||
return &Client{
|
||||
HTTPClient: httpClient,
|
||||
AccessToken: accessToken,
|
||||
CourseID: courseID,
|
||||
FilesOnly: filesOnly,
|
||||
VideosOnly: videosOnly,
|
||||
ModuleNumbers: moduleNumbers,
|
||||
downloadedFiles: make(map[string]bool),
|
||||
}
|
||||
@@ -68,6 +70,10 @@ func (c *Client) GetEnrolledCourses() ([]models.Course, error) {
|
||||
}
|
||||
|
||||
func (c *Client) DownloadCourseFiles(root string) {
|
||||
if c.VideosOnly {
|
||||
fmt.Println("\n[*] Skipping regular course files (videos only mode)")
|
||||
return
|
||||
}
|
||||
fmt.Println("\n[*] Fetching regular course files...")
|
||||
|
||||
fReq, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/courses/%s/folders?per_page=100", config.BaseURL, c.CourseID), nil)
|
||||
@@ -164,14 +170,19 @@ func (c *Client) DownloadModules(courseRoot string) {
|
||||
modName = fmt.Sprintf("[%d] %s", i+1, mod.Name)
|
||||
}
|
||||
|
||||
// In videos-only mode everything goes flat into courseRoot.
|
||||
// In files-only mode everything goes flat into courseRoot.
|
||||
// Otherwise use the structured Modules/<name> path.
|
||||
modBaseDir := courseRoot
|
||||
if !c.FilesOnly {
|
||||
if !c.FilesOnly && !c.VideosOnly {
|
||||
modBaseDir = filepath.Join(courseRoot, "Modules", utils.Sanitize(modName))
|
||||
}
|
||||
os.MkdirAll(modBaseDir, 0o755)
|
||||
|
||||
if !c.FilesOnly {
|
||||
if !c.FilesOnly && !c.VideosOnly {
|
||||
fmt.Printf("\n[Module] %s\n", modName)
|
||||
} else if c.VideosOnly {
|
||||
fmt.Printf("\n[Module] %s (scanning for videos)\n", modName)
|
||||
}
|
||||
|
||||
subHeaderStack := []string{}
|
||||
@@ -179,15 +190,16 @@ func (c *Client) DownloadModules(courseRoot string) {
|
||||
|
||||
for _, item := range mod.Items {
|
||||
|
||||
// In videos-only mode always download to the flat courseRoot.
|
||||
targetDir := modBaseDir
|
||||
if len(subHeaderStack) > 0 && !c.FilesOnly {
|
||||
if len(subHeaderStack) > 0 && !c.FilesOnly && !c.VideosOnly {
|
||||
targetDir = filepath.Join(modBaseDir, filepath.Join(subHeaderStack...))
|
||||
}
|
||||
os.MkdirAll(targetDir, 0o755)
|
||||
|
||||
switch item.Type {
|
||||
case "SubHeader":
|
||||
if c.FilesOnly {
|
||||
if c.FilesOnly || c.VideosOnly {
|
||||
continue
|
||||
}
|
||||
currentIndent := item.Indent
|
||||
@@ -207,6 +219,9 @@ func (c *Client) DownloadModules(courseRoot string) {
|
||||
fmt.Printf("%s--- %s ---\n", indent, item.Title)
|
||||
|
||||
case "File":
|
||||
if c.VideosOnly {
|
||||
continue
|
||||
}
|
||||
c.downloadModuleFile(item, targetDir)
|
||||
|
||||
case "ExternalTool":
|
||||
|
||||
Reference in New Issue
Block a user