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.

79 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .theplatform import ThePlatformIE
  4. from ..utils import (
  5. determine_ext,
  6. parse_duration,
  7. )
  8. class TheWeatherChannelIE(ThePlatformIE):
  9. _VALID_URL = r'https?://(?:www\.)?weather\.com/(?:[^/]+/)*video/(?P<id>[^/?#]+)'
  10. _TESTS = [{
  11. 'url': 'https://weather.com/series/great-outdoors/video/ice-climber-is-in-for-a-shock',
  12. 'md5': 'ab924ac9574e79689c24c6b95e957def',
  13. 'info_dict': {
  14. 'id': 'cc82397e-cc3f-4d11-9390-a785add090e8',
  15. 'ext': 'mp4',
  16. 'title': 'Ice Climber Is In For A Shock',
  17. 'description': 'md5:55606ce1378d4c72e6545e160c9d9695',
  18. 'uploader': 'TWC - Digital (No Distro)',
  19. 'uploader_id': '6ccd5455-16bb-46f2-9c57-ff858bb9f62c',
  20. }
  21. }]
  22. def _real_extract(self, url):
  23. display_id = self._match_id(url)
  24. webpage = self._download_webpage(url, display_id)
  25. drupal_settings = self._parse_json(self._search_regex(
  26. r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
  27. webpage, 'drupal settings'), display_id)
  28. video_id = drupal_settings['twc']['contexts']['node']['uuid']
  29. video_data = self._download_json(
  30. 'https://dsx.weather.com/cms/v4/asset-collection/en_US/' + video_id, video_id)
  31. seo_meta = video_data.get('seometa', {})
  32. title = video_data.get('title') or seo_meta['title']
  33. urls = []
  34. thumbnails = []
  35. formats = []
  36. for variant_id, variant_url in video_data.get('variants', []).items():
  37. variant_url = variant_url.strip()
  38. if not variant_url or variant_url in urls:
  39. continue
  40. urls.append(variant_url)
  41. ext = determine_ext(variant_url)
  42. if ext == 'jpg':
  43. thumbnails.append({
  44. 'url': variant_url,
  45. 'id': variant_id,
  46. })
  47. elif ThePlatformIE.suitable(variant_url):
  48. tp_formats, _ = self._extract_theplatform_smil(variant_url, video_id)
  49. formats.extend(tp_formats)
  50. elif ext == 'm3u8':
  51. formats.extend(self._extract_m3u8_formats(
  52. variant_url, video_id, 'mp4', 'm3u8_native',
  53. m3u8_id=variant_id, fatal=False))
  54. elif ext == 'f4m':
  55. formats.extend(self._extract_f4m_formats(
  56. variant_url, video_id, f4m_id=variant_id, fatal=False))
  57. else:
  58. formats.append({
  59. 'url': variant_url,
  60. 'format_id': variant_id,
  61. })
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'display_id': display_id,
  66. 'title': title,
  67. 'description': video_data.get('description') or seo_meta.get('description') or seo_meta.get('og:description'),
  68. 'duration': parse_duration(video_data.get('duration')),
  69. 'uploader': video_data.get('providername'),
  70. 'uploader_id': video_data.get('providerid'),
  71. 'thumbnails': thumbnails,
  72. 'formats': formats,
  73. }