mirror of
https://github.com/pikami/tiktok-dl.git
synced 2024-11-29 03:05:42 +00:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package workflows
|
|
|
|
import (
|
|
client "../client"
|
|
config "../models/config"
|
|
res "../resources"
|
|
utils "../utils"
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// CanUseDownloadUser - Test's if this workflow can be used for parameter
|
|
func CanUseDownloadUser(url string) bool {
|
|
isURL := strings.Contains(url, "/")
|
|
match, _ := regexp.MatchString(".+com\\/@[^\\/]+", url)
|
|
return !isURL || match
|
|
}
|
|
|
|
// DownloadUser - Download all user's videos
|
|
func DownloadUser(username string) {
|
|
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)
|
|
|
|
utils.InitOutputDirectory(downloadDir)
|
|
|
|
for index, upload := range uploads {
|
|
downloadVideo(upload, downloadDir)
|
|
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
|
}
|
|
utils.Log()
|
|
}
|
|
|
|
func GetUserVideosJson(username string) {
|
|
uploads, err := client.GetUserUploadsJson(username)
|
|
if err != nil {
|
|
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
|
return
|
|
}
|
|
fmt.Printf("%s", uploads)
|
|
}
|