logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

theweatherchannel.py (4015B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .theplatform import ThePlatformIE
  6. from ..utils import (
  7. determine_ext,
  8. parse_duration,
  9. parse_iso8601,
  10. )
  11. class TheWeatherChannelIE(ThePlatformIE):
  12. _VALID_URL = r'https?://(?:www\.)?weather\.com(?P<asset_name>(?:/(?P<locale>[a-z]{2}-[A-Z]{2}))?/(?:[^/]+/)*video/(?P<id>[^/?#]+))'
  13. _TESTS = [{
  14. 'url': 'https://weather.com/series/great-outdoors/video/ice-climber-is-in-for-a-shock',
  15. 'md5': 'c4cbe74c9c17c5676b704b950b73dd92',
  16. 'info_dict': {
  17. 'id': 'cc82397e-cc3f-4d11-9390-a785add090e8',
  18. 'ext': 'mp4',
  19. 'title': 'Ice Climber Is In For A Shock',
  20. 'description': 'md5:55606ce1378d4c72e6545e160c9d9695',
  21. 'uploader': 'TWC - Digital (No Distro)',
  22. 'uploader_id': '6ccd5455-16bb-46f2-9c57-ff858bb9f62c',
  23. 'upload_date': '20160720',
  24. 'timestamp': 1469018835,
  25. }
  26. }, {
  27. 'url': 'https://weather.com/en-CA/international/videos/video/unidentified-object-falls-from-sky-in-india',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. asset_name, locale, display_id = re.match(self._VALID_URL, url).groups()
  32. if not locale:
  33. locale = 'en-US'
  34. video_data = list(self._download_json(
  35. 'https://weather.com/api/v1/p/redux-dal', display_id, data=json.dumps([{
  36. 'name': 'getCMSAssetsUrlConfig',
  37. 'params': {
  38. 'language': locale.replace('-', '_'),
  39. 'query': {
  40. 'assetName': {
  41. '$in': asset_name,
  42. },
  43. },
  44. }
  45. }]).encode(), headers={
  46. 'Content-Type': 'application/json',
  47. })['dal']['getCMSAssetsUrlConfig'].values())[0]['data'][0]
  48. video_id = video_data['id']
  49. seo_meta = video_data.get('seometa', {})
  50. title = video_data.get('title') or seo_meta['title']
  51. urls = []
  52. thumbnails = []
  53. formats = []
  54. for variant_id, variant_url in video_data.get('variants', []).items():
  55. variant_url = variant_url.strip()
  56. if not variant_url or variant_url in urls:
  57. continue
  58. urls.append(variant_url)
  59. ext = determine_ext(variant_url)
  60. if ext == 'jpg':
  61. thumbnails.append({
  62. 'url': variant_url,
  63. 'id': variant_id,
  64. })
  65. elif ThePlatformIE.suitable(variant_url):
  66. tp_formats, _ = self._extract_theplatform_smil(variant_url, video_id)
  67. formats.extend(tp_formats)
  68. elif ext == 'm3u8':
  69. formats.extend(self._extract_m3u8_formats(
  70. variant_url, video_id, 'mp4', 'm3u8_native',
  71. m3u8_id=variant_id, fatal=False))
  72. elif ext == 'f4m':
  73. formats.extend(self._extract_f4m_formats(
  74. variant_url, video_id, f4m_id=variant_id, fatal=False))
  75. else:
  76. formats.append({
  77. 'url': variant_url,
  78. 'format_id': variant_id,
  79. })
  80. self._sort_formats(formats)
  81. cc_url = video_data.get('cc_url')
  82. return {
  83. 'id': video_id,
  84. 'display_id': display_id,
  85. 'title': title,
  86. 'description': video_data.get('description') or seo_meta.get('description') or seo_meta.get('og:description'),
  87. 'duration': parse_duration(video_data.get('duration')),
  88. 'uploader': video_data.get('providername'),
  89. 'uploader_id': video_data.get('providerid'),
  90. 'timestamp': parse_iso8601(video_data.get('publishdate')),
  91. 'subtitles': {locale[:2]: [{'url': cc_url}]} if cc_url else None,
  92. 'thumbnails': thumbnails,
  93. 'formats': formats,
  94. }