2020-01-21 21:46:30 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
2020-03-22 00:10:24 +00:00
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
2020-01-21 21:46:30 +00:00
|
|
|
client "../client"
|
|
|
|
models "../models"
|
2020-02-07 23:51:17 +00:00
|
|
|
config "../models/config"
|
2020-01-21 21:46:30 +00:00
|
|
|
utils "../utils"
|
2020-03-21 22:22:08 +00:00
|
|
|
fileio "../utils/fileio"
|
2020-03-22 00:10:24 +00:00
|
|
|
log "../utils/log"
|
2020-01-21 21:46:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CanUseDownloadSingleVideo - Check's if DownloadSingleVideo can be used for parameter
|
|
|
|
func CanUseDownloadSingleVideo(url string) bool {
|
|
|
|
match, _ := regexp.MatchString("\\/@.+\\/video\\/[0-9]+", url)
|
|
|
|
return match
|
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadSingleVideo - Downloads single video
|
|
|
|
func DownloadSingleVideo(url string) {
|
2020-02-07 23:51:17 +00:00
|
|
|
username := utils.GetUsernameFromString(url)
|
2020-02-25 18:12:01 +00:00
|
|
|
upload, err := client.GetVideoDetails(url)
|
|
|
|
if err != nil {
|
2020-04-09 16:10:33 +01:00
|
|
|
OnWorkflowFail(err, url)
|
2020-03-22 00:10:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if utils.IsItemInArchive(upload) {
|
2020-02-25 18:12:01 +00:00
|
|
|
return
|
|
|
|
}
|
2020-02-07 23:51:17 +00:00
|
|
|
downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username)
|
2020-01-21 21:46:30 +00:00
|
|
|
|
2020-03-21 22:22:08 +00:00
|
|
|
fileio.InitOutputDirectory(downloadDir)
|
2020-01-21 21:46:30 +00:00
|
|
|
downloadVideo(upload, downloadDir)
|
2020-03-22 00:10:24 +00:00
|
|
|
log.Log("[1/1] Downloaded\n")
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadVideo - Downloads one video
|
|
|
|
func downloadVideo(upload models.Upload, downloadDir string) {
|
|
|
|
uploadID := upload.GetUploadID()
|
|
|
|
downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID)
|
|
|
|
|
2020-03-21 22:22:08 +00:00
|
|
|
if fileio.CheckIfExists(downloadPath) {
|
2020-01-21 21:46:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
utils.DownloadFile(downloadPath, upload.URL)
|
|
|
|
|
2020-02-07 23:51:17 +00:00
|
|
|
if config.Config.MetaData {
|
2020-01-21 21:46:30 +00:00
|
|
|
metadataPath := fmt.Sprintf("%s/%s.json", downloadDir, uploadID)
|
|
|
|
upload.WriteToFile(metadataPath)
|
|
|
|
}
|
2020-03-22 00:10:24 +00:00
|
|
|
|
|
|
|
utils.AddItemToArchive(upload.GetUploadID())
|
2020-01-21 21:46:30 +00:00
|
|
|
}
|