def title(self): ''' Возвращает название фотографии. @return: string ''' title_node = self._get_node_by_name('title') if title_node is None: logger.error('photo title not found') return None return title_node.text.encode('utf-8')
def remote_id(self): ''' Возвращает идентификатор фотографии. @return: string ''' id_node = self._get_node_by_name('id') if id_node is None: logger.error('photo id not found') return None return id_node.text
def content(self): ''' Возвращает прикрепленное медиа-содержимое. @return: string ''' content_node = self._get_node_by_name('content') if content_node is None: logger.error('attached media not found') return None url = content_node.attrib['src'] return _get_document(url)
def size(self): ''' Возвращает размер фотографии в байтах. @return: int ''' qname = str(QName(FOTKI_NS, 'img')) img_node = self._node.find('%s[@size="orig"]'%qname) if img_node is None: logger.error('image size value not found') return None return int(img_node.attrib['bytesize'])
def photo_count(self): ''' Возвращает количество фотографий в альбоме без их предварительной загрузки. @return: int ''' qname = str(QName(FOTKI_NS, 'image-count')) image_count_node = self._node.find(qname) if image_count_node is None: logger.error('photo count not found') return None return int(image_count_node.attrib['value'])
def _parse_resource(node): ''' Создает объект ресурса в зависимости от его типа. @param node: Element @return: Resource ''' qname = str(QName(ATOM_NS, 'id')) resource_id_node = node.find(qname) if resource_id_node is None: logger.error('resource id expected to be but not found') return None resource_id_parts = resource_id_node.text.split(':') resource_type = resource_id_parts[4] if resource_type == 'albums': return AlbumListResource(node) if resource_type == 'album': return AlbumResource(node) if resource_type == 'photo': return PhotoResource(node) logger.error('unknown resource type "%s"', resource_type) return None