import json as simplejson
import xbmc

class List():
    def __init__(self):
        content = []
        response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title","rating"], "sort": {"method": "rating" }}, "id": 1}')
        data = simplejson.loads(response)        
        total = data['result']['limits']['total']        

        txt = open("C:/Users/USER/Desktop/Movies.txt", "w") 
        for i in range(0, total):
            movie = data['result']['movies'][i]['title'] + ' - ' + str(data['result']['movies'][i]['rating'])
            movie = movie.encode("utf-8")  
            txt.write(str(i) + ' - ' + movie + "\n") 
        txt.close()
        
L = List()
del L
