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.

70 lines
2.6 KiB

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