Added option to download metadata

This commit is contained in:
Pijus Kamandulis
2020-01-20 19:42:34 +02:00
parent 5609abb04c
commit 4e7093250f
4 changed files with 67 additions and 4 deletions

View File

@@ -11,12 +11,14 @@ var Config struct {
URL string
OutputPath string
Debug bool
MetaData bool
}
// GetConfig - Returns Config object
func GetConfig() {
outputPath := flag.String("output", "./downloads", "Output path")
debug := flag.Bool("debug", false, "enables debug mode")
debug := flag.Bool("debug", false, "Enables debug mode")
metadata := flag.Bool("metadata", false, "Write video metadata to a .json file")
flag.Parse()
args := flag.Args()
@@ -28,4 +30,5 @@ func GetConfig() {
Config.URL = flag.Args()[len(args)-1]
Config.OutputPath = *outputPath
Config.Debug = *debug
Config.MetaData = *metadata
}

View File

@@ -2,13 +2,23 @@ package models
import (
"encoding/json"
"fmt"
"os"
"strings"
)
// Upload - Upload object
type Upload struct {
ShareLink string `json:"shareLink"`
URL string `json:"url"`
ShareLink string `json:"shareLink"`
Caption string `json:"caption"`
Sound Sound `json:"sound"`
}
// Sound - Sound object
type Sound struct {
Title string `json:"title"`
Link string `json:"link"`
}
// ParseUploads - Parses json uploads array
@@ -30,3 +40,26 @@ func (u Upload) GetUploadID() string {
parts := strings.Split(u.ShareLink, "/")
return parts[len(parts)-1]
}
// WriteToFile - Writes object to file
func (u Upload) WriteToFile(outputPath string) {
bytes, err := json.Marshal(u)
if err != nil {
fmt.Printf("Could not serialize json for video: %s", u.GetUploadID())
fmt.Println()
panic(err)
}
// Create the file
out, err := os.Create(outputPath)
if err != nil {
panic(err)
}
defer out.Close()
// Write to file
_, err = out.Write(bytes)
if err != nil {
panic(err)
}
}