tiktok-dl/workflows/downloadMusic.go

52 lines
1.3 KiB
Go
Raw Normal View History

package workflows
import (
2020-03-22 00:10:24 +00:00
"fmt"
"regexp"
2020-04-12 01:22:00 +01: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 01:22:00 +01:00
utils "github.com/pikami/tiktok-dl/utils"
fileio "github.com/pikami/tiktok-dl/utils/fileio"
log "github.com/pikami/tiktok-dl/utils/log"
)
// CanUseDownloadMusic - Check's if DownloadMusic can be used for parameter
func CanUseDownloadMusic(url string) bool {
2020-02-24 23:01:10 +00:00
match, _ := regexp.MatchString(".com\\/music\\/.+", url)
return match
}
// DownloadMusic - Download all videos by given music
func DownloadMusic(url string) {
2020-02-25 18:12:01 +00:00
uploads, err := client.GetMusicUploads(url)
if err != nil {
OnWorkflowFail(err, url)
2020-02-25 18:12:01 +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-02-24 23:01:10 +00:00
for index, upload := range uploads {
username := utils.GetUsernameFromString(upload.Uploader)
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
2020-03-21 22:22:08 +00:00
fileio.InitOutputDirectory(downloadDir)
2020-02-24 23:01:10 +00:00
downloadVideo(upload, downloadDir)
log.Logf(res.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
// GetMusicJSON - Prints scraped info from music
func GetMusicJSON(url string) {
uploads, err := client.GetMusicUploadsJSON(url)
2020-02-25 19:16:57 +00:00
if err != nil {
OnWorkflowFail(err, url)
2020-02-25 19:16:57 +00:00
return
}
2020-02-24 23:01:10 +00:00
fmt.Printf("%s", uploads)
}