Обобщил объекты
parent
37dd389aec
commit
6a43ce1926
|
@ -88,68 +88,41 @@ class Group(object):
|
||||||
def counters(self):
|
def counters(self):
|
||||||
return self.conn.groups.getById(group_id = self.id, fields = 'counters')
|
return self.conn.groups.getById(group_id = self.id, fields = 'counters')
|
||||||
def videos(self, page_items = 20, page = 1, album = None):
|
def videos(self, page_items = 20, page = 1, album = None):
|
||||||
return videos(self.conn, -self.id, page_items, page, album)
|
return media_entries('video', self.conn, -self.id, page_items, page, album)
|
||||||
|
|
||||||
class Photo(object):
|
def media_entries(e_type, conn, oid, page_items = 20, page = 1, album = None):
|
||||||
def __init__(self, pid, conn):
|
|
||||||
self.conn = conn
|
|
||||||
self.id = pid
|
|
||||||
self.info = {}
|
|
||||||
@property
|
|
||||||
def url(self):
|
|
||||||
k = filter(lambda x: x.startswith('photo_'), self.info.keys())
|
|
||||||
key_ = u'photo_' + str(max([int(x.split('_')[1]) for x in k])).decode('utf-8')
|
|
||||||
return self.info[key_]
|
|
||||||
|
|
||||||
def photos(conn, oid, page_items = 20, page = 1, album = None):
|
|
||||||
if album:
|
if album:
|
||||||
photos = conn.photos.get(owner_id = oid,
|
entries = getattr(conn, e_type).get(owner_id = oid,
|
||||||
offset = ((page_items * page) - page_items),
|
|
||||||
count = page_items,
|
|
||||||
album_id = album)
|
|
||||||
else:
|
|
||||||
photos = conn.photos.getAll(owner_id = oid,
|
|
||||||
offset = ((page_items * page) - page_items),
|
|
||||||
count = page_items)
|
|
||||||
count = photos['count']
|
|
||||||
pages = int(ceil(count / float(page_items)))
|
|
||||||
l = []
|
|
||||||
for i in photos['items']:
|
|
||||||
ph = Photo(i['id'], conn)
|
|
||||||
ph.info = i
|
|
||||||
l.append(ph)
|
|
||||||
return {'pages': pages, 'total': count, 'items': l}
|
|
||||||
|
|
||||||
def videos(conn, oid, page_items = 20, page = 1, album = None):
|
|
||||||
if album:
|
|
||||||
vids = conn.video.get(owner_id = oid,
|
|
||||||
offset = ((page_items * page) - page_items),
|
|
||||||
count = page_items)
|
|
||||||
else:
|
|
||||||
vids = conn.video.get(owner_id = oid,
|
|
||||||
offset = ((page_items * page) - page_items),
|
offset = ((page_items * page) - page_items),
|
||||||
count = page_items,
|
count = page_items,
|
||||||
album_id = album)
|
album_id = album)
|
||||||
count = vids['count']
|
else:
|
||||||
|
entries = getattr(conn, e_type).get(owner_id = oid,
|
||||||
|
offset = ((page_items * page) - page_items),
|
||||||
|
count = page_items)
|
||||||
|
count = entries['count']
|
||||||
pages = int(ceil(count / float(page_items)))
|
pages = int(ceil(count / float(page_items)))
|
||||||
l = []
|
l = []
|
||||||
for i in vids['items']:
|
for i in entries['items']:
|
||||||
vid = str(i['owner_id']) + '_' + str(i['id'])
|
entry_id = str(i['owner_id']) + '_' + str(i['id'])
|
||||||
v = Video(vid, conn)
|
e = Entry(e_type, entry_id, conn)
|
||||||
v.info = i
|
e.info = i
|
||||||
l.append(v)
|
l.append(e)
|
||||||
return {'pages': pages, 'total': count, 'items': l}
|
return {'pages': pages, 'total': count, 'items': l}
|
||||||
|
|
||||||
class Video(object):
|
class Entry(object):
|
||||||
def __init__(self, vid, conn):
|
def __init__(self, e_type, eid, conn):
|
||||||
|
self.type = e_type
|
||||||
|
self.id = eid
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
self.id = vid
|
|
||||||
self.info = {}
|
self.info = {}
|
||||||
@property
|
|
||||||
def v_url(self):
|
|
||||||
return self.info['player']
|
|
||||||
def set_info(self):
|
def set_info(self):
|
||||||
self.info = self.conn.video.get(videos = self.id)['items'][0]
|
if self.type == 'video':
|
||||||
|
self.info = self.conn.video.get(videos = self.id)['items'][0]
|
||||||
|
elif self.type == 'audio':
|
||||||
|
self.info = self.conn.audio.getById(audios = self.id)['items'][0]
|
||||||
|
elif self.type == 'photos':
|
||||||
|
self.info = self.conn.photos.getById(photos = self.id)['items'][0]
|
||||||
|
|
||||||
class User(object):
|
class User(object):
|
||||||
'''Этот класс описывает свойства и методы пользователя.'''
|
'''Этот класс описывает свойства и методы пользователя.'''
|
||||||
|
@ -188,7 +161,7 @@ class User(object):
|
||||||
l.append(g)
|
l.append(g)
|
||||||
return {'pages': pages, 'total': count, 'items': l}
|
return {'pages': pages, 'total': count, 'items': l}
|
||||||
def videos(self, page_items = 20, page = 1, album = None):
|
def videos(self, page_items = 20, page = 1, album = None):
|
||||||
return videos(self.conn, self.id, page_items, page, album)
|
return media_entries('video', self.conn, self.id, page_items, page, album)
|
||||||
|
|
||||||
class KodiVKGUIPhotos(object):
|
class KodiVKGUIPhotos(object):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
|
@ -216,8 +189,7 @@ class KodiVKGUIVideos(object):
|
||||||
oid = self.root.params['oid']
|
oid = self.root.params['oid']
|
||||||
if page > 1:
|
if page > 1:
|
||||||
self.root.add_folder(self.root.gui._string(400601), {'do': _DO_ALL_VIDEO, 'oid': self.root.u.id, 'page': page - 1})
|
self.root.add_folder(self.root.gui._string(400601), {'do': _DO_ALL_VIDEO, 'oid': self.root.u.id, 'page': page - 1})
|
||||||
vids = videos(self.root.conn, oid, page = page)
|
vids = media_entries('video', self.root.conn, oid, page = page)
|
||||||
xbmc.log('pages: %s, total videos: %s' % (vids['pages'], vids['total']))
|
|
||||||
for v in vids['items']:
|
for v in vids['items']:
|
||||||
list_item = xbmcgui.ListItem(v.info['title'])
|
list_item = xbmcgui.ListItem(v.info['title'])
|
||||||
list_item.setInfo('video', {
|
list_item.setInfo('video', {
|
||||||
|
@ -240,10 +212,15 @@ class KodiVKGUIVideos(object):
|
||||||
xbmcplugin.endOfDirectory(_addon_id)
|
xbmcplugin.endOfDirectory(_addon_id)
|
||||||
def _play_video(self):
|
def _play_video(self):
|
||||||
vid = self.root.params['vid']
|
vid = self.root.params['vid']
|
||||||
v = Video(vid, self.root.conn)
|
v = Entry('video', vid, self.root.conn)
|
||||||
v.set_info()
|
v.set_info()
|
||||||
v_url = v.info['player']
|
if 'files' in v.info:
|
||||||
paths = self.root.parse_vk_player_html(v_url)
|
paths = {}
|
||||||
|
for k in v.info['files'].keys():
|
||||||
|
paths[k.split('_')[1]] = v.info['files'][k]
|
||||||
|
else:
|
||||||
|
v_url = v.info['player']
|
||||||
|
paths = self.root.parse_vk_player_html(v_url)
|
||||||
### Здесь должно браться разрешение из настроек
|
### Здесь должно браться разрешение из настроек
|
||||||
k = max(paths.keys())
|
k = max(paths.keys())
|
||||||
play_item = xbmcgui.ListItem(path = paths[k])
|
play_item = xbmcgui.ListItem(path = paths[k])
|
||||||
|
|
Loading…
Reference in New Issue