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.

47 lines
1.5 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. }
  14. }
  15. def _real_extract(self, url):
  16. mobj = re.match(self._VALID_URL, url)
  17. video_id = mobj.group('id')
  18. data = self._download_xml(
  19. 'http://www.firstpost.com/getvideoxml-%s.xml' % video_id, video_id,
  20. 'Downloading video XML')
  21. item = data.find('./playlist/item')
  22. thumbnail = item.find('./image').text
  23. title = item.find('./title').text
  24. formats = [
  25. {
  26. 'url': details.find('./file').text,
  27. 'format_id': details.find('./label').text.strip(),
  28. 'width': int(details.find('./width').text.strip()),
  29. 'height': int(details.find('./height').text.strip()),
  30. } for details in item.findall('./source/file_details') if details.find('./file').text
  31. ]
  32. return {
  33. 'id': video_id,
  34. 'title': title,
  35. 'thumbnail': thumbnail,
  36. 'formats': formats,
  37. }