add playlist position

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

View file

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

View file

@ -46,6 +46,10 @@ func (v YoutubeVideo) ID() string {
return v.id return v.id
} }
func (v YoutubeVideo) PlaylistPosition() int {
return int(v.playlistPosition)
}
func (v YoutubeVideo) IDAndNum() string { func (v YoutubeVideo) IDAndNum() string {
return v.ID() + " (" + strconv.Itoa(int(v.playlistPosition)) + " in channel)" 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) 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 { func (v YoutubeVideo) triggerThumbnailSave() error {
client := &http.Client{Timeout: 30 * time.Second} 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) 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 return nil
} }

View file

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