def do_xml_user_response(context, provider, xml): result = [] root = ET.fromstring(xml) do_xml_error(context, provider, root) contacts = root.find('contacts') if contacts is not None: for contact in contacts: user_id = contact.get('id') username = contact.get('username') display_name = contact.get('display_name') contact_item = DirectoryItem(display_name, context.create_uri(['user', user_id])) # portraits portraits = contact.find('portraits') if portraits is not None: for portrait in portraits: height = int(portrait.get('height')) if height >= 256: contact_item.set_image(portrait.text) break pass pass contact_item.set_fanart(provider.get_fanart(context)) result.append(contact_item) pass # add next page _do_next_page(result, contacts, context, provider) pass return result
def do_xml_album_response(user_id, context, provider, album): if isinstance(album, basestring): album = ET.fromstring(album) do_xml_error(context, provider, album) album = album.find('album') pass album_id = album.get('id') album_name = album.find('title').text album_item = DirectoryItem(album_name, context.create_uri(['user', user_id, 'album', album_id])) thumbnail_video = album.find('thumbnail_video') if thumbnail_video is not None: thumbnails = thumbnail_video.find('thumbnails') if thumbnails is not None: for thumbnail in thumbnails: height = int(thumbnail.get('height')) if height >= 360: album_item.set_image(thumbnail.text) break pass pass pass return album_item
def do_xml_channel_response(user_id, context, provider, channel): if isinstance(channel, basestring): channel = ET.fromstring(channel) do_xml_error(context, provider, channel) channel = channel.find('video') pass channel_id = channel.get('id') channel_name = channel.find('name').text is_subscribed = channel.get('is_subscribed') == '1' if provider.is_logged_in() and not is_subscribed: channel_name = '[I]%s[/I]' % channel_name pass image = '' logo_url = channel.find('logo_url') if logo_url is not None and logo_url.text: image = logo_url.text else: thumbnail_url = channel.find('thumbnail_url') if thumbnail_url is not None: image = thumbnail_url.text.replace('200x150', '400x300') pass pass channel_item = DirectoryItem(channel_name, context.create_uri(['user', user_id, 'channel', channel_id]), image=image) # context menu context_menu = [] if provider.is_logged_in(): # join/leave if is_subscribed: text = context.localize(provider._local_map['vimeo.channel.unfollow']) context_menu.append( (text, 'RunPlugin(%s)' % context.create_uri(['channel', 'unsubscribe'], {'channel_id': channel_id}))) else: text = context.localize(provider._local_map['vimeo.channel.follow']) context_menu.append( (text, 'RunPlugin(%s)' % context.create_uri(['channel', 'subscribe'], {'channel_id': channel_id}))) pass pass channel_item.set_context_menu(context_menu) return channel_item
def do_xml_group_response(user_id, context, provider, group): if isinstance(group, basestring): group = ET.fromstring(group) do_xml_error(context, provider, group) group = group.find('video') pass group_id = group.get('id') group_name = group.find('name').text has_joined = group.get('has_joined') == '1' if provider.is_logged_in() and not has_joined: group_name = '[I]%s[/I]' % group_name pass logo_url = group.find('logo_url') image = '' if logo_url is not None and logo_url.text: image = logo_url.text else: thumbnail_url = group.find('thumbnail_url') if thumbnail_url is not None: image = thumbnail_url.text.replace('200x150', '400x300') pass pass group_item = DirectoryItem(group_name, context.create_uri(['user', user_id, 'group', group_id]), image=image) # context menu context_menu = [] if provider.is_logged_in(): # join/leave if has_joined: leave_text = context.localize(provider._local_map['vimeo.group.leave']) context_menu.append( (leave_text, 'RunPlugin(%s)' % context.create_uri(['group', 'leave'], {'group_id': group_id}))) else: join_text = context.localize(provider._local_map['vimeo.group.join']) context_menu.append( (join_text, 'RunPlugin(%s)' % context.create_uri(['group', 'join'], {'group_id': group_id}))) pass pass group_item.set_context_menu(context_menu) return group_item
def do_xml_featured_response(context, provider, xml): root = ET.fromstring(xml) if not do_xml_error(context, provider, root): return [] result = [] for item in root: item_type = item.find('type').text if item_type == 'channel': channel_id = item.find('id').text channel_name = item.find('title').text channel_image = item.find('header_url').text channel_item = DirectoryItem(channel_name, context.create_uri(['channel', channel_id]), image=channel_image) channel_item.set_fanart(provider.get_fanart(context)) result.append(channel_item) pass else: raise kodion.KodionException('Unknown type "%s" for featured' % item_type) pass return result