mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-04-23 06:48:50 +01:00
Added option to download items by music
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
28
workflows/downloadMusic.go
Normal file
28
workflows/downloadMusic.go
Normal 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)
|
||||
}
|
||||
}
|
||||
30
workflows/startWorkflowByParameter.go
Normal file
30
workflows/startWorkflowByParameter.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user