2020-01-26 17:44:25 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
2020-02-24 23:01:10 +00:00
|
|
|
client "../client"
|
|
|
|
config "../models/config"
|
2020-02-25 18:12:01 +00:00
|
|
|
res "../resources"
|
2020-02-24 23:01:10 +00:00
|
|
|
utils "../utils"
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
2020-01-26 17:44:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2020-01-26 17:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-02-24 23:01:10 +00:00
|
|
|
uploadCount := len(uploads)
|
2020-01-26 17:44:25 +00:00
|
|
|
|
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-01-26 17:44:25 +00:00
|
|
|
|
2020-02-24 23:01:10 +00:00
|
|
|
utils.InitOutputDirectory(downloadDir)
|
|
|
|
downloadVideo(upload, downloadDir)
|
|
|
|
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
|
|
|
}
|
|
|
|
utils.Log()
|
2020-02-24 22:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMusicJson(url string) {
|
2020-02-24 23:01:10 +00:00
|
|
|
uploads := client.GetMusicUploadsJson(url)
|
|
|
|
fmt.Printf("%s", uploads)
|
2020-01-26 17:44:25 +00:00
|
|
|
}
|