mirror of
https://github.com/pikami/tiktok-dl.git
synced 2024-11-25 09:15:41 +00:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package workflows
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
|
|
client "../client"
|
|
config "../models/config"
|
|
utils "../utils"
|
|
fileio "../utils/fileio"
|
|
log "../utils/log"
|
|
)
|
|
|
|
// CanUseDownloadMusic - Check's if DownloadMusic can be used for parameter
|
|
func CanUseDownloadMusic(url string) bool {
|
|
match, _ := regexp.MatchString(".com\\/music\\/.+", url)
|
|
return match
|
|
}
|
|
|
|
// DownloadMusic - Download all videos by given music
|
|
func DownloadMusic(url string) {
|
|
uploads, err := client.GetMusicUploads(url)
|
|
if err != nil {
|
|
OnWorkflowFail(err, url)
|
|
return
|
|
}
|
|
|
|
uploads = utils.RemoveArchivedItems(uploads)
|
|
uploadCount := len(uploads)
|
|
|
|
for index, upload := range uploads {
|
|
username := utils.GetUsernameFromString(upload.Uploader)
|
|
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
|
|
|
fileio.InitOutputDirectory(downloadDir)
|
|
downloadVideo(upload, downloadDir)
|
|
log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
|
}
|
|
log.Log()
|
|
}
|
|
|
|
// GetMusicJSON - Prints scraped info from music
|
|
func GetMusicJSON(url string) {
|
|
uploads, err := client.GetMusicUploadsJSON(url)
|
|
if err != nil {
|
|
OnWorkflowFail(err, url)
|
|
return
|
|
}
|
|
fmt.Printf("%s", uploads)
|
|
}
|