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.

84 lines
3.1 KiB

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