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.

52 lines
1.7 KiB

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