mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-29 06:32:55 +00:00
Added ability to download from scrapeData (json)
This commit is contained in:
39
workflows/downloadScrapedData.go
Normal file
39
workflows/downloadScrapedData.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package workflows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
models "github.com/pikami/tiktok-dl/models"
|
||||
config "github.com/pikami/tiktok-dl/models/config"
|
||||
res "github.com/pikami/tiktok-dl/resources"
|
||||
utils "github.com/pikami/tiktok-dl/utils"
|
||||
fileio "github.com/pikami/tiktok-dl/utils/fileio"
|
||||
log "github.com/pikami/tiktok-dl/utils/log"
|
||||
)
|
||||
|
||||
// CanUseDownloadScrapedData - Check's if DownloadScrapedData can be used
|
||||
func CanUseDownloadScrapedData(scrapedDataFilePath string) bool {
|
||||
return scrapedDataFilePath != ""
|
||||
}
|
||||
|
||||
// DownloadScrapedData - Download items from scraped data file
|
||||
func DownloadScrapedData(scrapedDataFilePath string) {
|
||||
if !fileio.CheckIfExists(scrapedDataFilePath) {
|
||||
log.LogFatal(res.ErrorPathNotFound, scrapedDataFilePath)
|
||||
}
|
||||
|
||||
dataFileContent := fileio.ReadFileToString(scrapedDataFilePath)
|
||||
uploads := models.ParseUploads(dataFileContent)
|
||||
uploads = utils.RemoveArchivedItems(uploads)
|
||||
|
||||
uploadCount := len(uploads)
|
||||
|
||||
for index, upload := range uploads {
|
||||
username := utils.GetUsernameFromString(upload.Uploader)
|
||||
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
||||
|
||||
fileio.InitOutputDirectory(downloadDir)
|
||||
downloadVideo(upload, downloadDir)
|
||||
log.Logf(res.Downloaded, index+1, uploadCount)
|
||||
}
|
||||
log.Log()
|
||||
}
|
||||
Reference in New Issue
Block a user