Is there an addon with direct db access ?
#1
Can anybody tell me if there's an addon with direct db access i can look at?

I'm new to python,but i don't think i can do it via json.

What i want to do is count the number of music of artists via the first letter (A=2, E=70 & so on)

This is the mysql query i want to run:

SELECT LEFT(strArtist, 1) AS artist, COUNT(*) AS COUNT FROM artist GROUP BY artist;

If anybody can point me in the right direction so i can run mysql query's that would be great.

Thanks
Reply
#2
If you run a sql query your addon wont be able to go into the XBMC Repository.

Your problem can be solved by using JSON RPC to get the artists names and then looping across the dictionary that is returned to create another dictionary that holds the tally of the letter count.
Reply
#3
This ought to do it.

Code:
import xbmc
import json

    albums = {"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums",  "params": { "properties": [ "artist",] }, "id": 1}

    xbmc_request = json.dumps(albums)
    result = xbmc.executeJSONRPC(xbmc_request)
    result = json.loads(result)

    artists_acc = []
    letter_tally = {}

    if result.has_key('result') and result['result'].has_key('albums'):
        for album in result['result']['albums']:
            if album['artist'] not in artists_acc:
                if album['artist'][0][0:4.lower()] == 'the ':
                    letter = album['artist'][0][4]
                else:
                    letter = album['artist'][0][0]
                if letter not in letter_tally:
                    letter_tally[letter] = 1
                else:
                    letter_tally[letter] += 1
                artists_acc.append(album['artist'])
Reply
#4
@ Karnagious

Sorry for the late reply.

Thanks for giving me a starting block, it's very much appreciated.

Thanks
Reply
#5
No worries. The tip jar is to the left and starts with "Reputation: " Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Is there an addon with direct db access ?0