You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. class FirstpostIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?firstpost\.com/[^/]+/.*-(?P<id>[0-9]+)\.html'
  5. _TEST = {
  6. 'url': 'http://www.firstpost.com/india/india-to-launch-indigenous-aircraft-carrier-monday-1025403.html',
  7. 'md5': 'ee9114957692f01fb1263ed87039112a',
  8. 'info_dict': {
  9. 'id': '1025403',
  10. 'ext': 'mp4',
  11. 'title': 'India to launch indigenous aircraft carrier INS Vikrant today',
  12. 'description': 'md5:feef3041cb09724e0bdc02843348f5f4',
  13. }
  14. }
  15. def _real_extract(self, url):
  16. video_id = self._match_id(url)
  17. page = self._download_webpage(url, video_id)
  18. title = self._html_search_meta('twitter:title', page, 'title', fatal=True)
  19. description = self._html_search_meta('twitter:description', page, 'title')
  20. data = self._download_xml(
  21. 'http://www.firstpost.com/getvideoxml-%s.xml' % video_id, video_id,
  22. 'Downloading video XML')
  23. item = data.find('./playlist/item')
  24. thumbnail = item.find('./image').text
  25. formats = [
  26. {
  27. 'url': details.find('./file').text,
  28. 'format_id': details.find('./label').text.strip(),
  29. 'width': int(details.find('./width').text.strip()),
  30. 'height': int(details.find('./height').text.strip()),
  31. } for details in item.findall('./source/file_details') if details.find('./file').text
  32. ]
  33. self._sort_formats(formats)
  34. return {
  35. 'id': video_id,
  36. 'title': title,
  37. 'description': description,
  38. 'thumbnail': thumbnail,
  39. 'formats': formats,
  40. }