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.

81 lines
3.0 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. formats = []
  45. for rendition in video_sources['renditions']:
  46. rendition_url = rendition.get('url')
  47. if not rendition_url:
  48. continue
  49. tbr = int_or_none(rendition.get('encodingRate'), 1000)
  50. container = rendition.get('videoContainer')
  51. is_hls = container == 'M2TS'
  52. protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url})
  53. formats.append({
  54. 'format_id': ('hls' if is_hls else protocol) + ('-%d' % tbr if tbr else ''),
  55. 'url': rendition_url,
  56. 'width': int_or_none(rendition.get('frameWidth')),
  57. 'height': int_or_none(rendition.get('frameHeight')),
  58. 'tbr': tbr,
  59. 'vcodec': rendition.get('videoCodec'),
  60. 'container': container,
  61. 'protocol': protocol,
  62. 'ext': 'mp4' if is_hls else None,
  63. })
  64. self._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'description': unescapeHTML(video_data.get('descr')),
  69. 'thumbnail': video_data.get('poster') or video_data.get('thumbnail'),
  70. 'formats': formats,
  71. }