Added option to download items by music

This commit is contained in:
Pijus Kamandulis
2020-01-26 19:44:25 +02:00
parent 6f8ab8a277
commit 884f9040db
9 changed files with 128 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
package workflows
import (
models "../models"
utils "../utils"
"fmt"
)
@@ -25,17 +24,5 @@ func downloadItem(batchItem string) {
return
}
// Single video
if CanUseDownloadSingleVideo(batchItem) {
DownloadSingleVideo(batchItem)
return
}
// Tiktok user
if CanUseDownloadUser(batchItem) {
DownloadUser(models.GetUsernameFromString(batchItem))
return
}
panic(fmt.Sprintf("Could not recognise URL format of string %s", batchItem))
StartWorkflowByParameter(batchItem)
}

View File

@@ -0,0 +1,28 @@
package workflows
import (
client "../client"
models "../models"
utils "../utils"
"fmt"
"regexp"
)
// 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 := client.GetMusicUploads(url)
for _, upload := range uploads {
username := models.GetUsernameFromString(upload.Uploader)
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
utils.InitOutputDirectory(downloadDir)
downloadVideo(upload, downloadDir)
}
}

View File

@@ -0,0 +1,30 @@
package workflows
import (
models "../models"
"fmt"
)
// StartWorkflowByParameter - Start needed workflow by given parameter
func StartWorkflowByParameter(url string) {
// Music
if CanUseDownloadMusic(url) {
DownloadMusic(url)
return
}
// Single video
if CanUseDownloadSingleVideo(url) {
DownloadSingleVideo(url)
return
}
// Tiktok user
if CanUseDownloadUser(url) {
DownloadUser(models.GetUsername())
return
}
panic(fmt.Sprintf("Could not recognise URL format of string %s", url))
}