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.

61 lines
2.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. determine_protocol,
  7. )
  8. class DailyMailIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?dailymail\.co\.uk/video/[^/]+/video-(?P<id>[0-9]+)'
  10. _TEST = {
  11. 'url': 'http://www.dailymail.co.uk/video/sciencetech/video-1288527/Turn-video-impressionist-masterpiece.html',
  12. 'md5': '2f639d446394f53f3a33658b518b6615',
  13. 'info_dict': {
  14. 'id': '1288527',
  15. 'ext': 'mp4',
  16. 'title': 'Turn any video into an impressionist masterpiece',
  17. 'description': 'md5:88ddbcb504367987b2708bb38677c9d2',
  18. }
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(url, video_id)
  23. video_data = self._parse_json(self._search_regex(
  24. r"data-opts='({.+?})'", webpage, 'video data'), video_id)
  25. title = video_data['title']
  26. video_sources = self._download_json(video_data.get(
  27. 'sources', {}).get('url') or 'http://www.dailymail.co.uk/api/player/%s/video-sources.json' % video_id, video_id)
  28. formats = []
  29. for rendition in video_sources['renditions']:
  30. rendition_url = rendition.get('url')
  31. if not rendition_url:
  32. continue
  33. tbr = int_or_none(rendition.get('encodingRate'), 1000)
  34. container = rendition.get('videoContainer')
  35. is_hls = container == 'M2TS'
  36. protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url})
  37. formats.append({
  38. 'format_id': ('hls' if is_hls else protocol) + ('-%d' % tbr if tbr else ''),
  39. 'url': rendition_url,
  40. 'width': int_or_none(rendition.get('frameWidth')),
  41. 'height': int_or_none(rendition.get('frameHeight')),
  42. 'tbr': tbr,
  43. 'vcodec': rendition.get('videoCodec'),
  44. 'container': container,
  45. 'protocol': protocol,
  46. 'ext': 'mp4' if is_hls else None,
  47. })
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': title,
  52. 'description': video_data.get('descr'),
  53. 'thumbnail': video_data.get('poster') or video_data.get('thumbnail'),
  54. 'formats': formats,
  55. }