dailymail.py 2.8 KB

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