Skip to content

Commit

Permalink
Don't marshal some fields into .nfo files
Browse files Browse the repository at this point in the history
There are some fields of the video.Video struct that are for my code
only and should not make it into the actual .nfo file.
  • Loading branch information
xordspar0 committed Oct 6, 2017
1 parent 2e6ff6d commit 25abe8e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions video/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (
)

type Video struct {
Url string
XMLName xml.Name `xml:"movie"`
Title string `xml:"title"`
Description string `xml:"plot"`
DownloadDate string
FileName string
url string
downloadDate string
fileName string
}

func NewVideo(url string) *Video {
currentTime := time.Now().Local().Format(time.RFC3339)
v := &Video{
Url: url,
url: url,
Title: youtubedl.GetTitle(url),
Description: youtubedl.GetDescription(url),
DownloadDate: currentTime,
FileName: fmt.Sprintf("%s %s", currentTime, youtubedl.GetTitleSafe(url)),
downloadDate: currentTime,
fileName: fmt.Sprintf("%s %s", currentTime, youtubedl.GetTitleSafe(url)),
}

if v.Title == "" {
Expand All @@ -37,16 +37,16 @@ func NewVideo(url string) *Video {

func (v *Video) WriteVideo(directory string) error {
return youtubedl.DownloadTo(
v.Url,
fmt.Sprintf("%s/%s.%s", directory, v.FileName, "%(ext)s"),
v.url,
fmt.Sprintf("%s/%s.%s", directory, v.fileName, "%(ext)s"),
)
}

// WriteNfo saves a thumbnail file for the video.
func (v *Video) WriteThumb(directory string) error {
return youtubedl.DownloadThumbnailTo(
v.Url,
fmt.Sprintf("%s/%s-thumb.%s", directory, v.FileName, "%(ext)s"),
v.url,
fmt.Sprintf("%s/%s-thumb.%s", directory, v.fileName, "%(ext)s"),
)
}

Expand All @@ -60,10 +60,10 @@ func (v *Video) WriteNfo(directory string) error {

nfoXml = []byte(fmt.Sprintf("%s\n%s\n%s",
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`,
fmt.Sprintf("<!-- Created on %s by SquirrelBot -->", v.DownloadDate),
fmt.Sprintf("<!-- Created on %s by SquirrelBot -->", v.downloadDate),
nfoXml,
))
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.nfo", directory, v.FileName), nfoXml, 0644)
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.nfo", directory, v.fileName), nfoXml, 0644)
if err != nil {
return err
}
Expand Down

0 comments on commit 25abe8e

Please sign in to comment.