add playlist position

add delete function
This commit is contained in:
Niko Storni 2018-04-25 14:56:26 -04:00
parent 5d6204a349
commit e976cd0fa0
3 changed files with 26 additions and 0 deletions

View file

@ -44,6 +44,10 @@ func (v ucbVideo) ID() string {
return v.id
}
func (v ucbVideo) PlaylistPosition() int {
return 0
}
func (v ucbVideo) IDAndNum() string {
return v.ID() + " (?)"
}

View file

@ -46,6 +46,10 @@ func (v YoutubeVideo) ID() string {
return v.id
}
func (v YoutubeVideo) PlaylistPosition() int {
return int(v.playlistPosition)
}
func (v YoutubeVideo) IDAndNum() string {
return v.ID() + " (" + strconv.Itoa(int(v.playlistPosition)) + " in channel)"
}
@ -120,6 +124,16 @@ func (v YoutubeVideo) download() error {
return videoInfo.Download(videoInfo.Formats.Best(ytdl.FormatAudioEncodingKey)[0], downloadedFile)
}
func (v YoutubeVideo) delete() error {
videoPath := v.getFilename()
err := os.Remove(videoPath)
if err != nil {
return err
}
log.Debugln(v.id + " deleted from disk (" + videoPath + ")")
return nil
}
func (v YoutubeVideo) triggerThumbnailSave() error {
client := &http.Client{Timeout: 30 * time.Second}
@ -199,6 +213,13 @@ func (v YoutubeVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount f
return errors.Prefix("publish error", err)
}
err = v.delete()
if err != nil {
// the video was published anyway so it should be marked as published
// for that to happen, no errors should be returned any further than here
log.Debugln(errors.Prefix("delete error", err))
}
return nil
}

View file

@ -36,6 +36,7 @@ const (
type video interface {
ID() string
IDAndNum() string
PlaylistPosition() int
PublishedAt() time.Time
Sync(*jsonrpc.Client, string, float64, string) error
}