all playlist functionality works now

This commit is contained in:
Drew Weymouth
2023-11-14 09:05:02 -08:00
parent 470fe4b31a
commit 80a3104e79
6 changed files with 22 additions and 29 deletions
@@ -14,7 +14,10 @@ import (
"github.com/dweymouth/supersonic/sharedutil" "github.com/dweymouth/supersonic/sharedutil"
) )
const cacheValidDurationSeconds = 60 const (
cacheValidDurationSeconds = 60
runTimeTicksPerSecond = 10_000_000
)
type JellyfinServer struct { type JellyfinServer struct {
jellyfin.Client jellyfin.Client
@@ -65,18 +68,20 @@ func (j *jellyfinMediaProvider) AddPlaylistTracks(id string, trackIDsToAdd []str
return j.client.AddSongsToPlaylist(id, trackIDsToAdd) return j.client.AddSongsToPlaylist(id, trackIDsToAdd)
} }
func (j *jellyfinMediaProvider) RemovePlaylistTracks(playlistID string, removeInfo []mediaprovider.IDAndIndex) error { func (j *jellyfinMediaProvider) RemovePlaylistTracks(playlistID string, removeIdxs []int) error {
ids := sharedutil.MapSlice(removeInfo, func(x mediaprovider.IDAndIndex) string { return x.ID }) return j.client.RemoveSongsFromPlaylist(playlistID, removeIdxs)
return j.client.RemoveSongsFromPlaylist(playlistID, ids)
} }
func (j *jellyfinMediaProvider) ReplacePlaylistTracks(playlistID string, trackIDs []string) error { func (j *jellyfinMediaProvider) ReplacePlaylistTracks(playlistID string, trackIDs []string) error {
trs, err := j.client.GetPlaylistSongs(playlistID) pl, err := j.client.GetPlaylist(playlistID)
if err != nil { if err != nil {
return err return err
} }
idsToDelete := sharedutil.MapSlice(trs, func(t *jellyfin.Song) string { return t.Id }) allIndexes := make([]int, pl.SongCount)
if err = j.client.RemoveSongsFromPlaylist(playlistID, idsToDelete); err != nil { for i := range allIndexes {
allIndexes[i] = i
}
if err = j.client.RemoveSongsFromPlaylist(playlistID, allIndexes); err != nil {
return err return err
} }
return j.client.AddSongsToPlaylist(playlistID, trackIDs) return j.client.AddSongsToPlaylist(playlistID, trackIDs)
@@ -372,7 +377,7 @@ func toTrack(ch *jellyfin.Song) *mediaprovider.Track {
CoverArtID: coverArtID, CoverArtID: coverArtID,
ParentID: ch.AlbumID, ParentID: ch.AlbumID,
Name: ch.Name, Name: ch.Name,
Duration: int(ch.RunTimeTicks / 10_000_000), Duration: int(ch.RunTimeTicks / runTimeTicksPerSecond),
TrackNumber: ch.IndexNumber, TrackNumber: ch.IndexNumber,
DiscNumber: ch.DiscNumber, DiscNumber: ch.DiscNumber,
//Genre: ch.Genres, //Genre: ch.Genres,
@@ -423,7 +428,7 @@ func fillAlbum(a *jellyfin.Album, album *mediaprovider.Album) {
album.ID = a.ID album.ID = a.ID
album.CoverArtID = a.ID album.CoverArtID = a.ID
album.Name = a.Name album.Name = a.Name
album.Duration = int(a.RunTimeTicks / 10_000_000) album.Duration = int(a.RunTimeTicks / runTimeTicksPerSecond)
album.ArtistIDs = artistIDs album.ArtistIDs = artistIDs
album.ArtistNames = artistNames album.ArtistNames = artistNames
album.Year = a.Year album.Year = a.Year
@@ -444,7 +449,7 @@ func (j *jellyfinMediaProvider) fillPlaylist(p *jellyfin.Playlist, pl *mediaprov
pl.CoverArtID = p.ID pl.CoverArtID = p.ID
pl.Description = p.Overview pl.Description = p.Overview
pl.TrackCount = p.SongCount pl.TrackCount = p.SongCount
pl.Duration = int(p.RunTimeTicks / 1_000_000) pl.Duration = int(p.RunTimeTicks / runTimeTicksPerSecond)
// Jellyfin does not have public playlists // Jellyfin does not have public playlists
pl.Owner = j.client.LoggedInUser() pl.Owner = j.client.LoggedInUser()
pl.Public = false pl.Public = false
+1 -8
View File
@@ -66,11 +66,6 @@ type Server interface {
MediaProvider() MediaProvider MediaProvider() MediaProvider
} }
type IDAndIndex struct {
ID string
Index int
}
type MediaProvider interface { type MediaProvider interface {
SetPrefetchCoverCallback(cb func(coverArtID string)) SetPrefetchCoverCallback(cb func(coverArtID string))
@@ -124,9 +119,7 @@ type MediaProvider interface {
AddPlaylistTracks(id string, trackIDsToAdd []string) error AddPlaylistTracks(id string, trackIDsToAdd []string) error
// Some MediaProviders use ids and others indexes for removing tracks, RemovePlaylistTracks(id string, trackIdxsToRemove []int) error
// so need to supply both.
RemovePlaylistTracks(id string, trackRemoveInfo []IDAndIndex) error
ReplacePlaylistTracks(id string, trackIDs []string) error ReplacePlaylistTracks(id string, trackIDs []string) error
@@ -59,9 +59,8 @@ func (s *subsonicMediaProvider) AddPlaylistTracks(id string, trackIDsToAdd []str
return s.client.UpdatePlaylistTracks(id, trackIDsToAdd, nil) return s.client.UpdatePlaylistTracks(id, trackIDsToAdd, nil)
} }
func (s *subsonicMediaProvider) RemovePlaylistTracks(id string, removeInfo []mediaprovider.IDAndIndex) error { func (s *subsonicMediaProvider) RemovePlaylistTracks(id string, removeIdxs []int) error {
idx := sharedutil.MapSlice(removeInfo, func(x mediaprovider.IDAndIndex) int { return x.Index }) return s.client.UpdatePlaylistTracks(id, nil, removeIdxs)
return s.client.UpdatePlaylistTracks(id, nil, idx)
} }
func (s *subsonicMediaProvider) GetTrack(trackID string) (*mediaprovider.Track, error) { func (s *subsonicMediaProvider) GetTrack(trackID string) (*mediaprovider.Track, error) {
+1 -1
View File
@@ -6,7 +6,7 @@ require (
fyne.io/fyne/v2 v2.4.1 fyne.io/fyne/v2 v2.4.1
github.com/20after4/configdir v0.1.1 github.com/20after4/configdir v0.1.1
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1 github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1
github.com/dweymouth/go-jellyfin v0.0.0-20231113161404-7697fc026881 github.com/dweymouth/go-jellyfin v0.0.0-20231114014232-1e011bb03a9f
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee
github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363 github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363
github.com/fsnotify/fsnotify v1.6.0 github.com/fsnotify/fsnotify v1.6.0
+2 -2
View File
@@ -71,8 +71,8 @@ github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1 h1:mGvOb3zxl4vCLv+
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1/go.mod h1:ZNCLJfehvEf34B7BbLKjgpsL9lyW7q938w/GY1XgV4E= github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1/go.mod h1:ZNCLJfehvEf34B7BbLKjgpsL9lyW7q938w/GY1XgV4E=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20231110162149-a0e470497555 h1:8S+d0LuwdTUEipEzFeXp8rNwTQD47dBdDOg9+FI1+Vw= github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20231110162149-a0e470497555 h1:8S+d0LuwdTUEipEzFeXp8rNwTQD47dBdDOg9+FI1+Vw=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20231110162149-a0e470497555/go.mod h1:AWM1iPM2YfliduZ4u/kQzP9E6ARIWm0gg+57GpYzWro= github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20231110162149-a0e470497555/go.mod h1:AWM1iPM2YfliduZ4u/kQzP9E6ARIWm0gg+57GpYzWro=
github.com/dweymouth/go-jellyfin v0.0.0-20231113161404-7697fc026881 h1:CAbdL67fYdR3anSJB6VJDqXURAP1dpeUfS65h9Moq8g= github.com/dweymouth/go-jellyfin v0.0.0-20231114014232-1e011bb03a9f h1:sJY4MjrNaPdJTcXakVcUF+ndh+uvpgAcX6BPObG9nOA=
github.com/dweymouth/go-jellyfin v0.0.0-20231113161404-7697fc026881/go.mod h1:BMwS4vdjEYf1gmjPGSKCzWP/I6YlI6fkefJ9nsjBjaU= github.com/dweymouth/go-jellyfin v0.0.0-20231114014232-1e011bb03a9f/go.mod h1:BMwS4vdjEYf1gmjPGSKCzWP/I6YlI6fkefJ9nsjBjaU=
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee h1:ZGyJ6wp7CAfT31BugypcF/TPKEy2RrGR9JFq1JOjOpY= github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee h1:ZGyJ6wp7CAfT31BugypcF/TPKEy2RrGR9JFq1JOjOpY=
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee/go.mod h1:Ov0ieN90M7i+0k3OxhA/g1dozGs+UcPHDsMKqPgRDk0= github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee/go.mod h1:Ov0ieN90M7i+0k3OxhA/g1dozGs+UcPHDsMKqPgRDk0=
github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363 h1:MIH7MAWWPPVRKEKxz+RJubn+ycyQPimHn1Zvoxs1KRI= github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363 h1:MIH7MAWWPPVRKEKxz+RJubn+ycyQPimHn1Zvoxs1KRI=
+1 -5
View File
@@ -220,11 +220,7 @@ func (a *PlaylistPage) onRemoveSelectedFromPlaylist() {
idxs = append(idxs, i) idxs = append(idxs, i)
} }
} }
idIndex := make([]mediaprovider.IDAndIndex, 0, len(ids)) a.sm.Server.RemovePlaylistTracks(a.playlistID, idxs)
for i := 0; i < len(ids); i++ {
idIndex = append(idIndex, mediaprovider.IDAndIndex{ID: ids[i], Index: idxs[i]})
}
a.sm.Server.RemovePlaylistTracks(a.playlistID, idIndex)
a.tracklist.UnselectAll() a.tracklist.UnselectAll()
a.Reload() a.Reload()
} }