Skip to content

Commit

Permalink
Segment Playlist adds.
Browse files Browse the repository at this point in the history
Kodi has a limit on how much it will accept in a single playlist add
call, so make multiple calls if necessary.

NOTE that this is incredibly slow, but because there is no other way to
shuffle playlists from Kodi's JSON-RPC interface, this is all we can do
at the moment.

Addresses Issue #79.
  • Loading branch information
jingai committed Apr 19, 2017
1 parent 176f7e9 commit b4f58eb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,13 @@ def AddSongsToPlaylist(song_ids, shuffle=False):
if shuffle:
random.shuffle(songs_array)

return SendCommand(RPCString("Playlist.Add", {"playlistid": 0, "item": songs_array}))
# Segment the requests into chunks that Kodi will accept in a single call
song_groups = [songs_array[x:x+2000] for x in range(0, len(songs_array), 2000)]
for a in song_groups:
print "Adding %d items to the queue..." % (len(a))
res = SendCommand(RPCString("Playlist.Add", {"playlistid": 0, "item": a}))

return res


def AddAlbumToPlaylist(album_id):
Expand Down Expand Up @@ -354,7 +360,13 @@ def AddVideosToPlaylist(video_files, shuffle=False):
if shuffle:
random.shuffle(videos_array)

return SendCommand(RPCString("Playlist.Add", {"playlistid": 1, "item": videos_array}))
# Segment the requests into chunks that Kodi will accept in a single call
video_groups = [videos_array[x:x+2000] for x in range(0, len(videos_array), 2000)]
for a in video_groups:
print "Adding %d items to the queue..." % (len(a))
res = SendCommand(RPCString("Playlist.Add", {"playlistid": 1, "item": a}))

return res


def GetVideoPlaylistItems():
Expand Down

0 comments on commit b4f58eb

Please sign in to comment.