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.

62 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. unescapeHTML,
  8. )
  9. class DailyMailIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?dailymail\.co\.uk/video/[^/]+/video-(?P<id>[0-9]+)'
  11. _TEST = {
  12. 'url': 'http://www.dailymail.co.uk/video/tvshowbiz/video-1295863/The-Mountain-appears-sparkling-water-ad-Heavy-Bubbles.html',
  13. 'md5': 'f6129624562251f628296c3a9ffde124',
  14. 'info_dict': {
  15. 'id': '1295863',
  16. 'ext': 'mp4',
  17. 'title': 'The Mountain appears in sparkling water ad for \'Heavy Bubbles\'',
  18. 'description': 'md5:a93d74b6da172dd5dc4d973e0b766a84',
  19. }
  20. }
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. webpage = self._download_webpage(url, video_id)
  24. video_data = self._parse_json(self._search_regex(
  25. r"data-opts='({.+?})'", webpage, 'video data'), video_id)
  26. title = unescapeHTML(video_data['title'])
  27. video_sources = self._download_json(video_data.get(
  28. 'sources', {}).get('url') or 'http://www.dailymail.co.uk/api/player/%s/video-sources.json' % video_id, video_id)
  29. formats = []
  30. for rendition in video_sources['renditions']:
  31. rendition_url = rendition.get('url')
  32. if not rendition_url:
  33. continue
  34. tbr = int_or_none(rendition.get('encodingRate'), 1000)
  35. container = rendition.get('videoContainer')
  36. is_hls = container == 'M2TS'
  37. protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url})
  38. formats.append({
  39. 'format_id': ('hls' if is_hls else protocol) + ('-%d' % tbr if tbr else ''),
  40. 'url': rendition_url,
  41. 'width': int_or_none(rendition.get('frameWidth')),
  42. 'height': int_or_none(rendition.get('frameHeight')),
  43. 'tbr': tbr,
  44. 'vcodec': rendition.get('videoCodec'),
  45. 'container': container,
  46. 'protocol': protocol,
  47. 'ext': 'mp4' if is_hls else None,
  48. })
  49. self._sort_formats(formats)
  50. return {
  51. 'id': video_id,
  52. 'title': title,
  53. 'description': unescapeHTML(video_data.get('descr')),
  54. 'thumbnail': video_data.get('poster') or video_data.get('thumbnail'),
  55. 'formats': formats,
  56. }