- def _warn(self, fmt, *args):
- self.report_warning(fmt.format(*args), self._id)
-
- def _extract_format(self, elem):
- format_id = elem.tag
-
- url = elem.findtext('./url')
- if url == '':
- self._warn("{0}: url: empty, skipping", format_id)
- return None
-
- fmt = {
- 'format_id': format_id,
- 'url': compat_urlparse.urljoin(self._PREFIX, url)
- }
-
- try:
- _, ext = elem.findtext('./filename', '').rsplit('.', 1)
- except ValueError:
- self._warn('{0}: ext: missing extension', format_id)
- else:
- fmt['ext'] = ext
-
- filesize = elem.findtext('./filesize')
- if filesize is not None:
- try:
- fmt['filesize'] = int(filesize)
- except ValueError as e:
- self._warn('{0}: filesize: {1}', format_id, e)
-
- width = elem.get('width')
- if width is not None:
- try:
- fmt['width'] = int(width)
- except ValueError as e:
- self._warn('{0}: width: {1}', format_id, e)
-
- height = elem.get('height')
- if height is not None:
- try:
- fmt['height'] = int(height)
- except ValueError as e:
- self._warn('{0}: height: {1}', format_id, e)
-
- return fmt
-
- def _extract_thumbnail(self, elem):
- url = elem.findtext('./url')
- if url == '':
- return None
- thumb = {
- 'url': compat_urlparse.urljoin(self._PREFIX, url)
- }
-
- width = elem.get('width')
- if width is not None:
- try:
- thumb['width'] = int(width)
- except ValueError as e:
- self._warn('thumbnail: width: {0}', e)
-
- height = elem.get('height')
- if height is not None:
- try:
- thumb['height'] = int(height)
- except ValueError as e:
- self._warn('thumbnail: height: {0}', e)
-
- return thumb
-