-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle.go
35 lines (30 loc) · 1.11 KB
/
handle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
)
func TransferPlaylist(newPlaylistName, playlistName string, ogAccount, acceptingAccount ServiceAccount) (SyncedSongs, error) {
songs, err := ogAccount.GetPlaylist(playlistName)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"playlistName": playlistName,
"newName": newPlaylistName,
"OriginalAccount": ogAccount.GetName(),
"acceptingAccount": acceptingAccount.GetName(),
}).Warn("Failed get og playlist")
return SyncedSongs{}, err
}
if newPlaylistName == "" {
newPlaylistName = playlistName
}
if newPlaylistName, err = acceptingAccount.CreatePlaylist(newPlaylistName, fmt.Sprintf("Copied playlist: %s from service: %s", playlistName, ogAccount.GetName())); err != nil {
log.WithError(err).WithFields(log.Fields{
"playlistName": playlistName,
"newName": newPlaylistName,
"OriginalAccount": ogAccount.GetName(),
"acceptingAccount": acceptingAccount.GetName(),
}).Warn("Failed create playlist")
return SyncedSongs{}, err
}
return acceptingAccount.AddSongs(newPlaylistName, songs)
}