forked from ybrs/putio-xbmc-v2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.py
46 lines (35 loc) · 1.36 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from . import putio
import xbmcgui
import xbmcaddon
SETTINGS = xbmcaddon.Addon(id='plugin.video.putio')
I18N = SETTINGS.getLocalizedString
class PutioAuthFailureException(Exception):
"""An authentication error occured."""
def __init__(self, header, message, duration=10000, icon=xbmcgui.NOTIFICATION_ERROR):
self.header = header
self.message = message
self.duration = duration
self.icon = icon
class PutioApiHandler(object):
"""A Put.io API client helper."""
def __init__(self, oauth2_token):
if not oauth2_token:
raise PutioAuthFailureException(header=I18N(30001), message=I18N(30002))
self.client = putio.Client(access_token=oauth2_token, use_retry=True)
def get(self, id_):
return self.client.File.get(id_)
def list(self, parent=0):
items = []
for item in self.client.File.list(parent_id=parent):
if item.content_type and self.is_showable(item):
items.append(item)
return items
def is_showable(self, item):
if item.is_audio or item.is_video or item.is_folder:
return True
return False
def is_account_active(self):
r = self.client.Account.info()
if r['info'] and r['info']['account_status'] and r['info']['account_status'] == 'active':
return True
return False