2020-01-21 21:46:30 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
|
|
|
client "../client"
|
2020-02-07 23:51:17 +00:00
|
|
|
config "../models/config"
|
2020-02-25 18:12:01 +00:00
|
|
|
res "../resources"
|
2020-01-21 21:46:30 +00:00
|
|
|
utils "../utils"
|
|
|
|
"fmt"
|
2020-02-25 18:12:01 +00:00
|
|
|
"regexp"
|
2020-01-21 21:46:30 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-02-07 23:51:17 +00:00
|
|
|
uploadCount := len(uploads)
|
|
|
|
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
2020-01-21 21:46:30 +00:00
|
|
|
|
|
|
|
utils.InitOutputDirectory(downloadDir)
|
|
|
|
|
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-02-07 23:51:17 +00:00
|
|
|
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|
2020-02-07 23:51:17 +00:00
|
|
|
utils.Log()
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|
2020-02-24 22:56:19 +00:00
|
|
|
|
|
|
|
func GetUserVideosJson(username string) {
|
2020-02-25 19:16:57 +00:00
|
|
|
uploads, err := client.GetUserUploadsJson(username)
|
|
|
|
if err != nil {
|
|
|
|
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-02-24 23:01:10 +00:00
|
|
|
fmt.Printf("%s", uploads)
|
2020-02-24 22:56:19 +00:00
|
|
|
}
|