From 1c6428f1ab2c390fb6345b4a0d0dc873861139fb Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Wed, 25 Apr 2018 14:56:26 -0400 Subject: [PATCH] add playlist position add delete function --- sources/ucbVideo.go | 4 ++++ sources/youtubeVideo.go | 21 +++++++++++++++++++++ ytsync.go | 1 + 3 files changed, 26 insertions(+) diff --git a/sources/ucbVideo.go b/sources/ucbVideo.go index 23adfb8..deb1286 100644 --- a/sources/ucbVideo.go +++ b/sources/ucbVideo.go @@ -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() + " (?)" } diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index 52c871c..15c87a2 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -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 } diff --git a/ytsync.go b/ytsync.go index 781709e..3ca763d 100644 --- a/ytsync.go +++ b/ytsync.go @@ -36,6 +36,7 @@ const ( type video interface { ID() string IDAndNum() string + PlaylistPosition() int PublishedAt() time.Time Sync(*jsonrpc.Client, string, float64, string) error }