mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-09 04:27:16 +00:00
Download videos by hashtag; get json data without video downloading; limit option
This commit is contained in:
36
workflows/downloadHashtag.go
Normal file
36
workflows/downloadHashtag.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CanUseDownloadHashtag - Test's if this workflow can be used for parameter
|
||||
func CanUseDownloadHashtag(url string) bool {
|
||||
match := strings.Contains(url, "/tag/")
|
||||
return match
|
||||
}
|
||||
|
||||
// DownloadHashtag - Download videos marked with given hashtag
|
||||
func DownloadHashtag(url string) {
|
||||
uploads := client.GetHashtagUploads(url)
|
||||
uploadCount := len(uploads)
|
||||
hashtag := utils.GetHashtagFromURL(url)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, hashtag)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
|
||||
for index, upload := range uploads {
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
}
|
||||
|
||||
func GetHashtagJson(url string) {
|
||||
uploads := client.GetHashtagUploads(url)
|
||||
fmt.Printf("%s", uploads)
|
||||
}
|
||||
@@ -1,31 +1,36 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
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
|
||||
match, _ := regexp.MatchString(".com\\/music\\/.+", url)
|
||||
return match
|
||||
}
|
||||
|
||||
// DownloadMusic - Download all videos by given music
|
||||
func DownloadMusic(url string) {
|
||||
uploads := client.GetMusicUploads(url)
|
||||
uploadCount := len(uploads)
|
||||
uploads := client.GetMusicUploads(url)
|
||||
uploadCount := len(uploads)
|
||||
|
||||
for index, upload := range uploads {
|
||||
username := utils.GetUsernameFromString(upload.Uploader)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
for index, upload := range uploads {
|
||||
username := utils.GetUsernameFromString(upload.Uploader)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
}
|
||||
|
||||
func GetMusicJson(url string) {
|
||||
uploads := client.GetMusicUploadsJson(url)
|
||||
fmt.Printf("%s", uploads)
|
||||
}
|
||||
|
||||
@@ -28,3 +28,8 @@ func DownloadUser(username string) {
|
||||
}
|
||||
utils.Log()
|
||||
}
|
||||
|
||||
func GetUserVideosJson(username string) {
|
||||
uploads := client.GetUserUploadsJson(username)
|
||||
fmt.Printf("%s", uploads)
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
client "../client"
|
||||
models "../models"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
client "../client"
|
||||
models "../models"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// CanUseDownloadSingleVideo - Check's if DownloadSingleVideo can be used for parameter
|
||||
func CanUseDownloadSingleVideo(url string) bool {
|
||||
match, _ := regexp.MatchString("\\/@.+\\/video\\/[0-9]+", url)
|
||||
return match
|
||||
match, _ := regexp.MatchString("\\/@.+\\/video\\/[0-9]+", url)
|
||||
return match
|
||||
}
|
||||
|
||||
// DownloadSingleVideo - Downloads single video
|
||||
func DownloadSingleVideo(url string) {
|
||||
username := utils.GetUsernameFromString(url)
|
||||
upload := client.GetVideoDetails(url)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
username := utils.GetUsernameFromString(url)
|
||||
upload := client.GetVideoDetails(url)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Log("[1/1] Downloaded\n")
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Log("[1/1] Downloaded\n")
|
||||
}
|
||||
|
||||
// DownloadVideo - Downloads one video
|
||||
func downloadVideo(upload models.Upload, downloadDir string) {
|
||||
uploadID := upload.GetUploadID()
|
||||
downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID)
|
||||
uploadID := upload.GetUploadID()
|
||||
downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID)
|
||||
|
||||
if utils.CheckIfExists(downloadPath) {
|
||||
return
|
||||
}
|
||||
if utils.CheckIfExists(downloadPath) {
|
||||
return
|
||||
}
|
||||
|
||||
utils.DownloadFile(downloadPath, upload.URL)
|
||||
utils.DownloadFile(downloadPath, upload.URL)
|
||||
|
||||
if config.Config.MetaData {
|
||||
metadataPath := fmt.Sprintf("%s/%s.json", downloadDir, uploadID)
|
||||
upload.WriteToFile(metadataPath)
|
||||
}
|
||||
}
|
||||
if config.Config.MetaData {
|
||||
metadataPath := fmt.Sprintf("%s/%s.json", downloadDir, uploadID)
|
||||
upload.WriteToFile(metadataPath)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
)
|
||||
@@ -10,7 +11,11 @@ func StartWorkflowByParameter(url string) {
|
||||
|
||||
// Music
|
||||
if CanUseDownloadMusic(url) {
|
||||
DownloadMusic(url)
|
||||
if config.Config.JSONOnly {
|
||||
GetMusicJson(url)
|
||||
} else {
|
||||
DownloadMusic(url)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -22,7 +27,22 @@ func StartWorkflowByParameter(url string) {
|
||||
|
||||
// Tiktok user
|
||||
if CanUseDownloadUser(url) {
|
||||
DownloadUser(utils.GetUsernameFromString(url))
|
||||
if config.Config.JSONOnly {
|
||||
GetUserVideosJson(utils.GetUsernameFromString(url))
|
||||
} else {
|
||||
DownloadUser(utils.GetUsernameFromString(url))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Tiktok hashtag
|
||||
if CanUseDownloadHashtag(url) {
|
||||
if config.Config.JSONOnly {
|
||||
GetHashtagJson(url)
|
||||
} else {
|
||||
DownloadHashtag(url)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user