2020-01-21 21:46:30 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
2020-03-22 00:10:24 +00:00
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
|
2020-01-21 21:46:30 +00:00
|
|
|
client "../client"
|
2020-02-07 23:51:17 +00:00
|
|
|
config "../models/config"
|
2020-01-21 21:46:30 +00:00
|
|
|
utils "../utils"
|
2020-03-21 22:22:08 +00:00
|
|
|
fileio "../utils/fileio"
|
2020-03-22 00:10:24 +00:00
|
|
|
log "../utils/log"
|
2020-01-21 21:46:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CanUseDownloadUser - Test's if this workflow can be used for parameter
|
|
|
|
func CanUseDownloadUser(url string) bool {
|
2020-02-25 18:12:01 +00:00
|
|
|
isURL := strings.Contains(url, "/")
|
|
|
|
match, _ := regexp.MatchString(".+com\\/@[^\\/]+", url)
|
|
|
|
return !isURL || match
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadUser - Download all user's videos
|
|
|
|
func DownloadUser(username string) {
|
2020-02-25 18:12:01 +00:00
|
|
|
uploads, err := client.GetUserUploads(username)
|
|
|
|
if err != nil {
|
2020-04-09 16:10:33 +01:00
|
|
|
OnWorkflowFail(err, username)
|
2020-02-25 18:12:01 +00:00
|
|
|
return
|
|
|
|
}
|
2020-03-22 00:10:24 +00:00
|
|
|
|
|
|
|
uploads = utils.RemoveArchivedItems(uploads)
|
2020-02-07 23:51:17 +00:00
|
|
|
uploadCount := len(uploads)
|
2020-03-22 00:10:24 +00:00
|
|
|
|
2020-02-07 23:51:17 +00:00
|
|
|
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
2020-01-21 21:46:30 +00:00
|
|
|
|
2020-03-21 22:22:08 +00:00
|
|
|
fileio.InitOutputDirectory(downloadDir)
|
2020-01-21 21:46:30 +00:00
|
|
|
|
2020-02-07 23:51:17 +00:00
|
|
|
for index, upload := range uploads {
|
2020-01-21 21:46:30 +00:00
|
|
|
downloadVideo(upload, downloadDir)
|
2020-03-22 00:10:24 +00:00
|
|
|
log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|
2020-03-22 00:10:24 +00:00
|
|
|
log.Log()
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|
2020-02-24 22:56:19 +00:00
|
|
|
|
2020-03-22 00:10:24 +00:00
|
|
|
// GetUserVideosJSON - Prints scraped info from user
|
|
|
|
func GetUserVideosJSON(username string) {
|
|
|
|
uploads, err := client.GetUserUploadsJSON(username)
|
2020-02-25 19:16:57 +00:00
|
|
|
if err != nil {
|
2020-04-09 16:10:33 +01:00
|
|
|
OnWorkflowFail(err, username)
|
2020-02-25 19:16:57 +00:00
|
|
|
return
|
|
|
|
}
|
2020-02-24 23:01:10 +00:00
|
|
|
fmt.Printf("%s", uploads)
|
2020-02-24 22:56:19 +00:00
|
|
|
}
|