tiktok-dl/workflows/downloadUser.go

47 lines
1.1 KiB
Go
Raw Normal View History

2020-01-21 21:46:30 +00:00
package workflows
import (
client "../client"
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
}
uploadCount := len(uploads)
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
2020-01-21 21:46:30 +00:00
utils.InitOutputDirectory(downloadDir)
for index, upload := range uploads {
2020-01-21 21:46:30 +00:00
downloadVideo(upload, downloadDir)
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
2020-01-21 21:46:30 +00:00
}
utils.Log()
2020-01-21 21:46:30 +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)
}