tiktok-dl/workflows/downloadUser.go

54 lines
1.3 KiB
Go
Raw Normal View History

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