Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import urllib
- import urlparse
- import xbmcgui
- import xbmcplugin
- import xbmcaddon
- import requests
- import pyxbmct
- base_url = sys.argv[0]
- addon_handle = int(sys.argv[1])
- args = urlparse.parse_qs(sys.argv[2][1:])
- xbmcplugin.setContent(addon_handle, 'movies')
- my_addon = xbmcaddon.Addon()
- def build_url(query):
- return base_url + '?' + urllib.urlencode(query)
- mode = args.get('mode', None)
- # begin to write api logic
- username = my_addon.getSetting('username')
- password = my_addon.getSetting('password')
- api_base = '***********'
- s = requests.Session()
- # get auth token
- token = s.get(api_base + '/token', headers = {
- 'Email': username,
- 'Password': password
- }).headers['Token']
- s.headers['Authorization'] = 'Token ' + token
- # get mount (Dropbox...)
- mounts = s.get(api_base + '/api/v2/mounts').json()['mounts']
- mount = [x for x in mounts if x['name'] == 'Digi Cloud'][0]
- print(mount['name'] + mount['id'])
- if mode is None:
- files = s.get(api_base + '/api/v2/mounts/' + mount['id'] + '/files/list', params = {'path': '/'}).json()['files']
- for file in files:
- if file['type'] == 'dir':
- url = build_url({'mode': 'folder', 'foldername': '/' + file['name']})
- li = xbmcgui.ListItem('/' + file['name'], iconImage='DefaultFolder.png')
- xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
- listitem=li, isFolder=True)
- elif '.mp3' in file['name'] or '.mkv' in file['name']:
- url = s.get(api_base + '/api/v2/mounts/' + mount['id'] + '/files/download', params = {'path': '/'+file['name']}).json()['link']
- li = xbmcgui.ListItem(file['name'], iconImage='media.png')
- xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
- xbmcplugin.endOfDirectory(addon_handle)
- elif mode[0] == 'folder':
- foldername = args['foldername'][0]
- files = s.get(api_base + '/api/v2/mounts/' + mount['id'] + '/files/list', params = {'path': foldername + '/'}).json()['files']
- for file in files:
- if file['type'] == 'dir':
- url = build_url({'mode': 'folder', 'foldername': foldername + '/' + file['name']})
- li = xbmcgui.ListItem(foldername + '/' + file['name'], iconImage='DefaultFolder.png')
- xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
- listitem=li, isFolder=True)
- elif '.mp3' in file['name'] or '.mkv' in file['name']:
- url = s.get(api_base + '/api/v2/mounts/' + mount['id'] + '/files/download', params = {'path': foldername + '/' + file['name']}).json()['link']
- li = xbmcgui.ListItem(file['name'], iconImage='media.png')
- xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
- xbmcplugin.endOfDirectory(addon_handle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement