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