tiktok-dl/workflows/downloadHashtag.go

53 lines
1.2 KiB
Go
Raw Normal View History

package workflows
import (
2020-03-22 00:10:24 +00:00
"fmt"
"strings"
2020-02-24 23:01:10 +00:00
client "../client"
config "../models/config"
2020-02-25 19:16:57 +00:00
res "../resources"
2020-02-24 23:01:10 +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"
)
// CanUseDownloadHashtag - Test's if this workflow can be used for parameter
func CanUseDownloadHashtag(url string) bool {
2020-02-24 23:01:10 +00:00
match := strings.Contains(url, "/tag/")
return match
}
// DownloadHashtag - Download videos marked with given hashtag
func DownloadHashtag(url string) {
2020-02-25 19:16:57 +00:00
uploads, err := client.GetHashtagUploads(url)
if err != nil {
2020-03-22 00:10:24 +00:00
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
2020-02-25 19:16:57 +00:00
return
}
2020-03-22 00:10:24 +00:00
uploads = utils.RemoveArchivedItems(uploads)
2020-02-24 23:01:10 +00:00
uploadCount := len(uploads)
2020-03-22 00:10:24 +00:00
2020-02-24 23:01:10 +00:00
hashtag := utils.GetHashtagFromURL(url)
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, hashtag)
2020-03-21 22:22:08 +00:00
fileio.InitOutputDirectory(downloadDir)
2020-02-24 23:01:10 +00:00
for index, upload := range uploads {
downloadVideo(upload, downloadDir)
2020-03-22 00:10:24 +00:00
log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
2020-02-24 23:01:10 +00:00
}
2020-03-22 00:10:24 +00:00
log.Log()
}
2020-03-22 00:10:24 +00:00
// GetHashtagJSON - Prints scraped info from hashtag
func GetHashtagJSON(url string) {
uploads, err := client.GetHashtagUploadsJSON(url)
2020-02-25 19:16:57 +00:00
if err != nil {
2020-03-22 00:10:24 +00:00
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
2020-02-25 19:16:57 +00:00
return
}
2020-02-24 23:01:10 +00:00
fmt.Printf("%s", uploads)
}