all playlist functionality works now
This commit is contained in:
@@ -14,7 +14,10 @@ import (
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
)
|
||||
|
||||
const cacheValidDurationSeconds = 60
|
||||
const (
|
||||
cacheValidDurationSeconds = 60
|
||||
runTimeTicksPerSecond = 10_000_000
|
||||
)
|
||||
|
||||
type JellyfinServer struct {
|
||||
jellyfin.Client
|
||||
@@ -65,18 +68,20 @@ func (j *jellyfinMediaProvider) AddPlaylistTracks(id string, trackIDsToAdd []str
|
||||
return j.client.AddSongsToPlaylist(id, trackIDsToAdd)
|
||||
}
|
||||
|
||||
func (j *jellyfinMediaProvider) RemovePlaylistTracks(playlistID string, removeInfo []mediaprovider.IDAndIndex) error {
|
||||
ids := sharedutil.MapSlice(removeInfo, func(x mediaprovider.IDAndIndex) string { return x.ID })
|
||||
return j.client.RemoveSongsFromPlaylist(playlistID, ids)
|
||||
func (j *jellyfinMediaProvider) RemovePlaylistTracks(playlistID string, removeIdxs []int) error {
|
||||
return j.client.RemoveSongsFromPlaylist(playlistID, removeIdxs)
|
||||
}
|
||||
|
||||
func (j *jellyfinMediaProvider) ReplacePlaylistTracks(playlistID string, trackIDs []string) error {
|
||||
trs, err := j.client.GetPlaylistSongs(playlistID)
|
||||
pl, err := j.client.GetPlaylist(playlistID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
idsToDelete := sharedutil.MapSlice(trs, func(t *jellyfin.Song) string { return t.Id })
|
||||
if err = j.client.RemoveSongsFromPlaylist(playlistID, idsToDelete); err != nil {
|
||||
allIndexes := make([]int, pl.SongCount)
|
||||
for i := range allIndexes {
|
||||
allIndexes[i] = i
|
||||
}
|
||||
if err = j.client.RemoveSongsFromPlaylist(playlistID, allIndexes); err != nil {
|
||||
return err
|
||||
}
|
||||
return j.client.AddSongsToPlaylist(playlistID, trackIDs)
|
||||
@@ -372,7 +377,7 @@ func toTrack(ch *jellyfin.Song) *mediaprovider.Track {
|
||||
CoverArtID: coverArtID,
|
||||
ParentID: ch.AlbumID,
|
||||
Name: ch.Name,
|
||||
Duration: int(ch.RunTimeTicks / 10_000_000),
|
||||
Duration: int(ch.RunTimeTicks / runTimeTicksPerSecond),
|
||||
TrackNumber: ch.IndexNumber,
|
||||
DiscNumber: ch.DiscNumber,
|
||||
//Genre: ch.Genres,
|
||||
@@ -423,7 +428,7 @@ func fillAlbum(a *jellyfin.Album, album *mediaprovider.Album) {
|
||||
album.ID = a.ID
|
||||
album.CoverArtID = a.ID
|
||||
album.Name = a.Name
|
||||
album.Duration = int(a.RunTimeTicks / 10_000_000)
|
||||
album.Duration = int(a.RunTimeTicks / runTimeTicksPerSecond)
|
||||
album.ArtistIDs = artistIDs
|
||||
album.ArtistNames = artistNames
|
||||
album.Year = a.Year
|
||||
@@ -444,7 +449,7 @@ func (j *jellyfinMediaProvider) fillPlaylist(p *jellyfin.Playlist, pl *mediaprov
|
||||
pl.CoverArtID = p.ID
|
||||
pl.Description = p.Overview
|
||||
pl.TrackCount = p.SongCount
|
||||
pl.Duration = int(p.RunTimeTicks / 1_000_000)
|
||||
pl.Duration = int(p.RunTimeTicks / runTimeTicksPerSecond)
|
||||
// Jellyfin does not have public playlists
|
||||
pl.Owner = j.client.LoggedInUser()
|
||||
pl.Public = false
|
||||
|
||||
@@ -66,11 +66,6 @@ type Server interface {
|
||||
MediaProvider() MediaProvider
|
||||
}
|
||||
|
||||
type IDAndIndex struct {
|
||||
ID string
|
||||
Index int
|
||||
}
|
||||
|
||||
type MediaProvider interface {
|
||||
SetPrefetchCoverCallback(cb func(coverArtID string))
|
||||
|
||||
@@ -124,9 +119,7 @@ type MediaProvider interface {
|
||||
|
||||
AddPlaylistTracks(id string, trackIDsToAdd []string) error
|
||||
|
||||
// Some MediaProviders use ids and others indexes for removing tracks,
|
||||
// so need to supply both.
|
||||
RemovePlaylistTracks(id string, trackRemoveInfo []IDAndIndex) error
|
||||
RemovePlaylistTracks(id string, trackIdxsToRemove []int) 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)
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) RemovePlaylistTracks(id string, removeInfo []mediaprovider.IDAndIndex) error {
|
||||
idx := sharedutil.MapSlice(removeInfo, func(x mediaprovider.IDAndIndex) int { return x.Index })
|
||||
return s.client.UpdatePlaylistTracks(id, nil, idx)
|
||||
func (s *subsonicMediaProvider) RemovePlaylistTracks(id string, removeIdxs []int) error {
|
||||
return s.client.UpdatePlaylistTracks(id, nil, removeIdxs)
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetTrack(trackID string) (*mediaprovider.Track, error) {
|
||||
|
||||
@@ -6,7 +6,7 @@ require (
|
||||
fyne.io/fyne/v2 v2.4.1
|
||||
github.com/20after4/configdir v0.1.1
|
||||
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-subsonic v0.0.0-20231105161622-54b5aec28363
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
|
||||
@@ -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/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/go-jellyfin v0.0.0-20231113161404-7697fc026881 h1:CAbdL67fYdR3anSJB6VJDqXURAP1dpeUfS65h9Moq8g=
|
||||
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 h1:sJY4MjrNaPdJTcXakVcUF+ndh+uvpgAcX6BPObG9nOA=
|
||||
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/go.mod h1:Ov0ieN90M7i+0k3OxhA/g1dozGs+UcPHDsMKqPgRDk0=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363 h1:MIH7MAWWPPVRKEKxz+RJubn+ycyQPimHn1Zvoxs1KRI=
|
||||
|
||||
@@ -220,11 +220,7 @@ func (a *PlaylistPage) onRemoveSelectedFromPlaylist() {
|
||||
idxs = append(idxs, i)
|
||||
}
|
||||
}
|
||||
idIndex := make([]mediaprovider.IDAndIndex, 0, len(ids))
|
||||
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.sm.Server.RemovePlaylistTracks(a.playlistID, idxs)
|
||||
a.tracklist.UnselectAll()
|
||||
a.Reload()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user