mirror of https://github.com/pikami/tiktok-dl.git
error handling
This commit is contained in:
parent
7b9b7688a1
commit
208bffb846
|
@ -7,13 +7,20 @@ import (
|
|||
)
|
||||
|
||||
// GetUserUploads - Get all uploads marked with given hashtag
|
||||
func GetHashtagUploads(hashtagURL string) []models.Upload {
|
||||
func GetHashtagUploads(hashtagURL string) ([]models.Upload, error) {
|
||||
jsMethod := fmt.Sprintf("bootstrapIteratingVideos(%d)", config.Config.Limit)
|
||||
actionOutput := executeClientAction(hashtagURL, jsMethod)
|
||||
return models.ParseUploads(actionOutput)
|
||||
actionOutput, err := executeClientAction(hashtagURL, jsMethod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return models.ParseUploads(actionOutput), nil
|
||||
}
|
||||
|
||||
func GetHashtagUploadsJson(hashtagURL string) string {
|
||||
func GetHashtagUploadsJson(hashtagURL string) (string, error) {
|
||||
jsMethod := fmt.Sprintf("bootstrapIteratingVideos(%d)", config.Config.Limit)
|
||||
return executeClientAction(hashtagURL, jsMethod)
|
||||
actionOutput, err := executeClientAction(hashtagURL, jsMethod)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return actionOutput, nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,11 @@ func GetMusicUploads(url string) ([]models.Upload, error) {
|
|||
return models.ParseUploads(actionOutput), nil
|
||||
}
|
||||
|
||||
func GetMusicUploadsJson(url string) string {
|
||||
func GetMusicUploadsJson(url string) (string, error) {
|
||||
jsMethod := fmt.Sprintf("bootstrapIteratingVideos(%d)", config.Config.Limit)
|
||||
return executeClientAction(url, jsMethod)
|
||||
actionOutput, err := executeClientAction(url, jsMethod)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return actionOutput, nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,11 @@ func GetUserUploads(username string) ([]models.Upload, error) {
|
|||
return models.ParseUploads(actionOutput), nil
|
||||
}
|
||||
|
||||
func GetUserUploadsJson(username string) string {
|
||||
func GetUserUploadsJson(username string) (string, error) {
|
||||
jsMethod := fmt.Sprintf("bootstrapIteratingVideos(%d)", config.Config.Limit)
|
||||
return executeClientAction(`https://www.tiktok.com/@`+username, jsMethod)
|
||||
actionOutput, err := executeClientAction(`https://www.tiktok.com/@`+username, jsMethod)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return actionOutput, nil
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package workflows
|
|||
import (
|
||||
client "../client"
|
||||
config "../models/config"
|
||||
res "../resources"
|
||||
utils "../utils"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
@ -16,7 +17,11 @@ func CanUseDownloadHashtag(url string) bool {
|
|||
|
||||
// DownloadHashtag - Download videos marked with given hashtag
|
||||
func DownloadHashtag(url string) {
|
||||
uploads := client.GetHashtagUploads(url)
|
||||
uploads, err := client.GetHashtagUploads(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
uploadCount := len(uploads)
|
||||
hashtag := utils.GetHashtagFromURL(url)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, hashtag)
|
||||
|
@ -31,6 +36,10 @@ func DownloadHashtag(url string) {
|
|||
}
|
||||
|
||||
func GetHashtagJson(url string) {
|
||||
uploads := client.GetHashtagUploads(url)
|
||||
uploads, err := client.GetHashtagUploads(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s", uploads)
|
||||
}
|
||||
|
|
|
@ -36,6 +36,10 @@ func DownloadMusic(url string) {
|
|||
}
|
||||
|
||||
func GetMusicJson(url string) {
|
||||
uploads := client.GetMusicUploadsJson(url)
|
||||
uploads, err := client.GetMusicUploadsJson(url)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s", uploads)
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ func DownloadUser(username string) {
|
|||
}
|
||||
|
||||
func GetUserVideosJson(username string) {
|
||||
uploads := client.GetUserUploadsJson(username)
|
||||
uploads, err := client.GetUserUploadsJson(username)
|
||||
if err != nil {
|
||||
utils.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s", uploads)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue