mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-09 04:27:16 +00:00
TTDL-7 Added flag; Code clean up
This commit is contained in:
@@ -3,6 +3,7 @@ package workflows
|
||||
import (
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
log "../utils/log"
|
||||
)
|
||||
|
||||
// CanUseDownloadBatchFile - Check's if DownloadBatchFile can be used
|
||||
@@ -13,7 +14,7 @@ func CanUseDownloadBatchFile(batchFilePath string) bool {
|
||||
// DownloadBatchFile - Download items from batch file
|
||||
func DownloadBatchFile(batchFilePath string) {
|
||||
if !utils.CheckIfExists(batchFilePath) {
|
||||
utils.LogFatal(res.ErrorPathNotFound, batchFilePath)
|
||||
log.LogFatal(res.ErrorPathNotFound, batchFilePath)
|
||||
}
|
||||
|
||||
utils.ReadFileLineByLine(batchFilePath, downloadItem)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"strings"
|
||||
log "../utils/log"
|
||||
)
|
||||
|
||||
// CanUseDownloadHashtag - Test's if this workflow can be used for parameter
|
||||
@@ -19,10 +21,13 @@ func CanUseDownloadHashtag(url string) bool {
|
||||
func DownloadHashtag(url string) {
|
||||
uploads, err := client.GetHashtagUploads(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
uploads = utils.RemoveArchivedItems(uploads)
|
||||
uploadCount := len(uploads)
|
||||
|
||||
hashtag := utils.GetHashtagFromURL(url)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, hashtag)
|
||||
|
||||
@@ -30,15 +35,16 @@ func DownloadHashtag(url string) {
|
||||
|
||||
for index, upload := range uploads {
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
log.Log()
|
||||
}
|
||||
|
||||
func GetHashtagJson(url string) {
|
||||
uploads, err := client.GetHashtagUploads(url)
|
||||
// GetHashtagJSON - Prints scraped info from hashtag
|
||||
func GetHashtagJSON(url string) {
|
||||
uploads, err := client.GetHashtagUploadsJSON(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s", uploads)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
log "../utils/log"
|
||||
)
|
||||
|
||||
// CanUseDownloadMusic - Check's if DownloadMusic can be used for parameter
|
||||
@@ -19,9 +21,11 @@ func CanUseDownloadMusic(url string) bool {
|
||||
func DownloadMusic(url string) {
|
||||
uploads, err := client.GetMusicUploads(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
uploads = utils.RemoveArchivedItems(uploads)
|
||||
uploadCount := len(uploads)
|
||||
|
||||
for index, upload := range uploads {
|
||||
@@ -30,15 +34,16 @@ func DownloadMusic(url string) {
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
log.Log()
|
||||
}
|
||||
|
||||
func GetMusicJson(url string) {
|
||||
uploads, err := client.GetMusicUploadsJson(url)
|
||||
// GetMusicJSON - Prints scraped info from music
|
||||
func GetMusicJSON(url string) {
|
||||
uploads, err := client.GetMusicUploadsJSON(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s", uploads)
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
log "../utils/log"
|
||||
)
|
||||
|
||||
// CanUseDownloadUser - Test's if this workflow can be used for parameter
|
||||
@@ -21,25 +23,29 @@ func CanUseDownloadUser(url string) bool {
|
||||
func DownloadUser(username string) {
|
||||
uploads, err := client.GetUserUploads(username)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
uploads = utils.RemoveArchivedItems(uploads)
|
||||
uploadCount := len(uploads)
|
||||
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
|
||||
for index, upload := range uploads {
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
log.Log()
|
||||
}
|
||||
|
||||
func GetUserVideosJson(username string) {
|
||||
uploads, err := client.GetUserUploadsJson(username)
|
||||
// GetUserVideosJSON - Prints scraped info from user
|
||||
func GetUserVideosJSON(username string) {
|
||||
uploads, err := client.GetUserUploadsJSON(username)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s", uploads)
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
client "../client"
|
||||
models "../models"
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
log "../utils/log"
|
||||
)
|
||||
|
||||
// CanUseDownloadSingleVideo - Check's if DownloadSingleVideo can be used for parameter
|
||||
@@ -21,14 +23,18 @@ func DownloadSingleVideo(url string) {
|
||||
username := utils.GetUsernameFromString(url)
|
||||
upload, err := client.GetVideoDetails(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if utils.IsItemInArchive(upload) {
|
||||
return
|
||||
}
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Log("[1/1] Downloaded\n")
|
||||
log.Log("[1/1] Downloaded\n")
|
||||
}
|
||||
|
||||
// DownloadVideo - Downloads one video
|
||||
@@ -46,4 +52,6 @@ func downloadVideo(upload models.Upload, downloadDir string) {
|
||||
metadataPath := fmt.Sprintf("%s/%s.json", downloadDir, uploadID)
|
||||
upload.WriteToFile(metadataPath)
|
||||
}
|
||||
|
||||
utils.AddItemToArchive(upload.GetUploadID())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
log "../utils/log"
|
||||
)
|
||||
|
||||
// StartWorkflowByParameter - Start needed workflow by given parameter
|
||||
@@ -12,7 +13,7 @@ func StartWorkflowByParameter(url string) {
|
||||
// Music
|
||||
if CanUseDownloadMusic(url) {
|
||||
if config.Config.JSONOnly {
|
||||
GetMusicJson(url)
|
||||
GetMusicJSON(url)
|
||||
} else {
|
||||
DownloadMusic(url)
|
||||
}
|
||||
@@ -28,7 +29,7 @@ func StartWorkflowByParameter(url string) {
|
||||
// Tiktok user
|
||||
if CanUseDownloadUser(url) {
|
||||
if config.Config.JSONOnly {
|
||||
GetUserVideosJson(utils.GetUsernameFromString(url))
|
||||
GetUserVideosJSON(utils.GetUsernameFromString(url))
|
||||
} else {
|
||||
DownloadUser(utils.GetUsernameFromString(url))
|
||||
}
|
||||
@@ -39,12 +40,12 @@ func StartWorkflowByParameter(url string) {
|
||||
// Tiktok hashtag
|
||||
if CanUseDownloadHashtag(url) {
|
||||
if config.Config.JSONOnly {
|
||||
GetHashtagJson(url)
|
||||
GetHashtagJSON(url)
|
||||
} else {
|
||||
DownloadHashtag(url)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
utils.LogFatal(res.ErrorCouldNotRecogniseURL, url)
|
||||
log.LogFatal(res.ErrorCouldNotRecogniseURL, url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user