Playlist.Add alphabetical order only ? (Workaround and python skript for testing)
#1
Hi,
I think I am overlooking something, but I just cant add audio playlists in the right order, they always come out in alphabetical order.

they are in correct order if I do this:
{"jsonrpc":"2.0","id":1,"method":"Files.GetDirectory","params":{"directory":"/home/pat/3TB/_music_/test/test.m3u"}}

when I add them:
{"id":1,"jsonrpc":"2.0","method":"Playlist.Add","params":{"item":{"directory":"/home/pat/3TB/_music_/test.m3u"},"playlistid":0}}

they will be in alphabetical order / filename order / not in the original order.

if I add the playlist in xbmc via "Q" key everything is fine ....
is there a parameter in Playlist.Add which disbles this sorting ? If not, are there plans to change it ?

btw I am on 12.2 Git32b1a5e May 2 2013 (xbmcbuntu)
Reply
#2
well, I found a way to add playlists remotely in the right order and play it

@Montellese: Can you confirm that Playlist.Add only works in alphabetically order ? (see above...)

just can't believe it... but if it is so, here's my python script to add them one by one in the right order:
- json-rpc function was taken from somewhere in this forum
- adding 60 songs take about 20secs ... I will look into batch-sending

Code:
# TODO: batch upload
# by roscoe for xbmc and yatse forum  
#

import json, urllib2, time

host = 'xbmcbuntu'
port = '8080'

#plistfile='/home/pat/3TB/_music_/Playlists/error.m3u'
plistfile='/home/pat/3TB/_music_/Playlists/80er.m3u'

def getJsonRemote(host,port,method,params=None):
    url = 'http://%s:%s/jsonrpc' %(host, port)
    values ={}
    values['jsonrpc'] = '2.0'
    values['method'] = method
    if params is not None:
        values['params'] = params
    values['id'] = '1'
    headers = {'Content-Type':'application/json'}

    data = json.dumps(values)

    req = urllib2.Request(url, data, headers)

    response = urllib2.urlopen(req)
    return response.read()

# read playlist and put it to queue item per item
def readpl_to_queue(pl):
    try:
        #clear playlist
        received=getJsonRemote(host, port,'Playlist.Clear' , { 'playlistid' : 0 } )

        #read directory/playlist
        received=getJsonRemote(host, port,'Files.GetDirectory', { 'directory' : '%s' %pl , 'media':'video' })

        #get just the files json-> dict
        data=json.loads(received)

        #with open('output.json','w') as f:   # store if needed
        #    f.write(received)

        playlist=[]

        for i in range(len(data[u'result'][u'files'])):
            playlist.append(data[u'result'][u'files'][i]['file'])
            #print data[u'result'][u'files'][i]['file']
            i=i+1

        # add item per item
        for item in playlist:
            received=getJsonRemote(host, port, 'Playlist.Add' , { 'playlistid' : 0 , 'item' : {'file' : '%s' % item } } )
            print 'added: %s' % item
            print

    except KeyError:
        print '\nthere was an error while sending JSON-RPC (wrong playlistname?)\n'

def print_current_pl():
    received=getJsonRemote(host,port,'Playlist.GetItems', { 'properties' : ['title', 'album', 'artist', 'duration'] , 'playlistid': 0 } )
    print received

def play_current_pl():
        #received=getJsonRemote(host,port,'Player.Open', {"item":{"playlistid":0},"options":{"repeat":"all"}})
        received=getJsonRemote(host,port,'Player.Open', {'item':{'playlistid':0}})
        print received

#------------------ main -----------------------------------------------------

timestart = time.clock()

readpl_to_queue(plistfile)

print_current_pl()

play_current_pl()

print '\ntime elapsed: \t%s' % (time.clock() - timestart)
Reply
#3
Be careful as stated by topfs batch commands are not order constrained.

So if you batch you may end up with songs in wrong order in any future Xbmc patch Smile
Reply
#4
edited a typo ... should work now
except KeyError
instead of
except (KeyError )
Confused

and added play function
Reply

Logout Mark Read Team Forum Stats Members Help
Playlist.Add alphabetical order only ? (Workaround and python skript for testing)0