sync playlists between spotify and navidrome
This commit is contained in:
@@ -28,6 +28,7 @@ type NavidromePlaylist struct {
|
||||
}
|
||||
|
||||
type NavidromeTrack struct {
|
||||
ID string `json:"id"` // position ID within the playlist or id of the song. See MediaFileID
|
||||
Title string `json:"title"`
|
||||
Artist string `json:"artist"`
|
||||
ArtistID string `json:"artistId"`
|
||||
@@ -65,7 +66,6 @@ type NavidromeTrack struct {
|
||||
type NavidromePlaylistTrack struct {
|
||||
NavidromeTrack
|
||||
|
||||
ID string `json:"id"` // position ID within the playlist
|
||||
MediaFileID string `json:"mediaFileId"` // the actual song ID
|
||||
}
|
||||
|
||||
@@ -168,6 +168,25 @@ func (c *NavidromeClient) getPlaylistTracks(playlistID string) ([]NavidromePlayl
|
||||
return tracks, nil
|
||||
}
|
||||
|
||||
func (c *NavidromeClient) GetSongBySpotifyID(spotifyID string) ([]NavidromeTrack, error) {
|
||||
// https://navi.kapelle.org/api/song?_end=100&_order=ASC&_sort=title&_start=0&spotifyid=0NhcaHA0cyJyhk3g8tUsZP&missing=false
|
||||
params := url.Values{
|
||||
"spotifyid": {spotifyID},
|
||||
}
|
||||
var songs []NavidromeTrack
|
||||
err := c.getList("/api/song", params, &songs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return songs, nil
|
||||
}
|
||||
|
||||
func (c *NavidromeClient) AddTracks(playlistID string, songIDs []string) error {
|
||||
body := map[string]interface{}{"ids": songIDs}
|
||||
return c.request(http.MethodPost, "/api/playlist/"+playlistID+"/tracks", body, nil)
|
||||
}
|
||||
|
||||
func (c *NavidromeClient) getList(path string, extra url.Values, dest any) error {
|
||||
const pageSize = 500
|
||||
var all []json.RawMessage
|
||||
@@ -207,7 +226,7 @@ func (c *NavidromeClient) getList(path string, extra url.Values, dest any) error
|
||||
return json.Unmarshal(merged, dest)
|
||||
}
|
||||
|
||||
func (c *NavidromeClient) request(method, path string, body interface{}, dest interface{}) error {
|
||||
func (c *NavidromeClient) request(method, path string, body any, dest any) error {
|
||||
httpResp, err := c.do(method, path, body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user