]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/theweatherchannel.py
Prepate to upload
[youtubedl] / youtube_dl / extractor / theweatherchannel.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .theplatform import ThePlatformIE
5 from ..utils import (
6 determine_ext,
7 parse_duration,
8 )
9
10
11 class TheWeatherChannelIE(ThePlatformIE):
12 _VALID_URL = r'https?://(?:www\.)?weather\.com/(?:[^/]+/)*video/(?P<id>[^/?#]+)'
13 _TESTS = [{
14 'url': 'https://weather.com/series/great-outdoors/video/ice-climber-is-in-for-a-shock',
15 'md5': 'ab924ac9574e79689c24c6b95e957def',
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 }
24 }]
25
26 def _real_extract(self, url):
27 display_id = self._match_id(url)
28 webpage = self._download_webpage(url, display_id)
29 drupal_settings = self._parse_json(self._search_regex(
30 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
31 webpage, 'drupal settings'), display_id)
32 video_id = drupal_settings['twc']['contexts']['node']['uuid']
33 video_data = self._download_json(
34 'https://dsx.weather.com/cms/v4/asset-collection/en_US/' + video_id, video_id)
35 seo_meta = video_data.get('seometa', {})
36 title = video_data.get('title') or seo_meta['title']
37
38 urls = []
39 thumbnails = []
40 formats = []
41 for variant_id, variant_url in video_data.get('variants', []).items():
42 variant_url = variant_url.strip()
43 if not variant_url or variant_url in urls:
44 continue
45 urls.append(variant_url)
46 ext = determine_ext(variant_url)
47 if ext == 'jpg':
48 thumbnails.append({
49 'url': variant_url,
50 'id': variant_id,
51 })
52 elif ThePlatformIE.suitable(variant_url):
53 tp_formats, _ = self._extract_theplatform_smil(variant_url, video_id)
54 formats.extend(tp_formats)
55 elif ext == 'm3u8':
56 formats.extend(self._extract_m3u8_formats(
57 variant_url, video_id, 'mp4', 'm3u8_native',
58 m3u8_id=variant_id, fatal=False))
59 elif ext == 'f4m':
60 formats.extend(self._extract_f4m_formats(
61 variant_url, video_id, f4m_id=variant_id, fatal=False))
62 else:
63 formats.append({
64 'url': variant_url,
65 'format_id': variant_id,
66 })
67 self._sort_formats(formats)
68
69 return {
70 'id': video_id,
71 'display_id': display_id,
72 'title': title,
73 'description': video_data.get('description') or seo_meta.get('description') or seo_meta.get('og:description'),
74 'duration': parse_duration(video_data.get('duration')),
75 'uploader': video_data.get('providername'),
76 'uploader_id': video_data.get('providerid'),
77 'thumbnails': thumbnails,
78 'formats': formats,
79 }