Skip to content

Instantly share code, notes, and snippets.

@curti
Created August 10, 2016 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curti/b54c541883f68ed9dee2caf44d6880b3 to your computer and use it in GitHub Desktop.
Save curti/b54c541883f68ed9dee2caf44d6880b3 to your computer and use it in GitHub Desktop.
import base64
import json
import urllib
import urllib2
import pyqrcode # https://pypi.python.org/pypi/PyQRCode
movies = json.dumps({"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "limits": { "start" : 0}, "properties" : ["title", "rating", "runtime", "plot", "thumbnail", "file"], "sort": { "order": "ascending", "method": "label"} }, "id": "libMovies"})
def request(url, library, auth):
return json.loads(urllib2.urlopen(urllib2.Request(url, library, {'Authorization': 'Basic {0}'.format(auth), 'Content-Type': 'application/json'})).read())
def save(m, t):
html = '''
<html>
<head><title>Kodi Library</title></head>
<style type="text/css">
#movieview { width: 750px; }
</style>
<body>
<div id="movieview">
'''
for index, i in enumerate(m['result']['movies']):
j = 'http://' + ip + ':' + port + '/jsonrpc?request={"id":1,"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"' + str(i['file']) + '"}}}'
url = pyqrcode.create(j)
url.svg('{0}.svg'.format(str(i['movieid'])), scale=3)
html += '<div><img src="{0}" style="float:left; padding-right: 5px"; height="450" width="300" /> {1}<br />Rating: {2}<br />Runtime: {3}<br />Plot: {4}<br /><br /><img src="{5}.svg" /><br /><br /><br /><br /><br /></div>'.format(
urllib.unquote(i['thumbnail'][8:]), i['title'].encode('utf-8'), i['rating'], i['runtime'], i['plot'].encode('utf-8'), i['movieid'])
html += '</div></body></html>'
with open('kodi_library.html', 'wb') as f:
f.write(html)
if __name__ == '__main__':
ip = raw_input('ip address: ')
port = raw_input('port: ')
username = raw_input('username: ')
password = raw_input('password: ')
url = 'http://{0}:{1}/jsonrpc?request='.format(ip, port)
auth = base64.encodestring('{0}:{1}'.format(username, password)).strip()
print('Querying library...')
save(request(url, movies, auth), request(url, tvshows, auth))
print('Library exported: kodi_library.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment