mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-30 15:12:56 +00:00
Improved status output
Added `-quiet` flag Move out error messages to separate file
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CanUseDownloadBatchFile - Check's if DownloadBatchFile can be used
|
||||
@@ -13,7 +13,7 @@ func CanUseDownloadBatchFile(batchFilePath string) bool {
|
||||
// DownloadBatchFile - Download items from batch file
|
||||
func DownloadBatchFile(batchFilePath string) {
|
||||
if !utils.CheckIfExists(batchFilePath) {
|
||||
panic(fmt.Sprintf("File path %s not found.", batchFilePath))
|
||||
utils.LogFatal(res.ErrorPathNotFound, batchFilePath)
|
||||
}
|
||||
|
||||
utils.ReadFileLineByLine(batchFilePath, downloadItem)
|
||||
|
||||
@@ -2,7 +2,7 @@ package workflows
|
||||
|
||||
import (
|
||||
client "../client"
|
||||
models "../models"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
@@ -17,12 +17,15 @@ func CanUseDownloadMusic(url string) bool {
|
||||
// DownloadMusic - Download all videos by given music
|
||||
func DownloadMusic(url string) {
|
||||
uploads := client.GetMusicUploads(url)
|
||||
uploadCount := len(uploads)
|
||||
|
||||
for _, upload := range uploads {
|
||||
username := models.GetUsernameFromString(upload.Uploader)
|
||||
downloadDir := fmt.Sprintf("%s/%s", models.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()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package workflows
|
||||
|
||||
import (
|
||||
client "../client"
|
||||
models "../models"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -16,12 +16,15 @@ func CanUseDownloadUser(url string) bool {
|
||||
|
||||
// DownloadUser - Download all user's videos
|
||||
func DownloadUser(username string) {
|
||||
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
||||
uploads := client.GetUserUploads(username)
|
||||
uploadCount := len(uploads)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
|
||||
for _, upload := range uploads {
|
||||
for index, upload := range uploads {
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Logf("\r[%d/%d] Downloaded", index+1, uploadCount)
|
||||
}
|
||||
utils.Log()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package workflows
|
||||
import (
|
||||
client "../client"
|
||||
models "../models"
|
||||
config "../models/config"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"regexp"
|
||||
@@ -16,12 +17,13 @@ func CanUseDownloadSingleVideo(url string) bool {
|
||||
|
||||
// DownloadSingleVideo - Downloads single video
|
||||
func DownloadSingleVideo(url string) {
|
||||
username := models.GetUsernameFromString(url)
|
||||
username := utils.GetUsernameFromString(url)
|
||||
upload := client.GetVideoDetails(url)
|
||||
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
utils.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
utils.Log("[1/1] Downloaded\n")
|
||||
}
|
||||
|
||||
// DownloadVideo - Downloads one video
|
||||
@@ -30,14 +32,12 @@ func downloadVideo(upload models.Upload, downloadDir string) {
|
||||
downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID)
|
||||
|
||||
if utils.CheckIfExists(downloadPath) {
|
||||
fmt.Println("Upload '" + uploadID + "' already downloaded, skipping")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Downloading upload item '" + uploadID + "' to " + downloadPath)
|
||||
utils.DownloadFile(downloadPath, upload.URL)
|
||||
|
||||
if models.Config.MetaData {
|
||||
if config.Config.MetaData {
|
||||
metadataPath := fmt.Sprintf("%s/%s.json", downloadDir, uploadID)
|
||||
upload.WriteToFile(metadataPath)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
models "../models"
|
||||
"fmt"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
)
|
||||
|
||||
// StartWorkflowByParameter - Start needed workflow by given parameter
|
||||
@@ -22,9 +22,9 @@ func StartWorkflowByParameter(url string) {
|
||||
|
||||
// Tiktok user
|
||||
if CanUseDownloadUser(url) {
|
||||
DownloadUser(models.GetUsernameFromString(url))
|
||||
DownloadUser(utils.GetUsernameFromString(url))
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("Could not recognise URL format of string %s", url))
|
||||
utils.LogFatal(res.ErrorCouldNotRecogniseURL, url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user