]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/thisoldhouse.py
Update changelog.
[youtubedl] / youtube_dl / extractor / thisoldhouse.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import try_get
7
8
9 class ThisOldHouseIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?thisoldhouse\.com/(?:watch|how-to|tv-episode)/(?P<id>[^/?#]+)'
11 _TESTS = [{
12 'url': 'https://www.thisoldhouse.com/how-to/how-to-build-storage-bench',
13 'md5': '568acf9ca25a639f0c4ff905826b662f',
14 'info_dict': {
15 'id': '2REGtUDQ',
16 'ext': 'mp4',
17 'title': 'How to Build a Storage Bench',
18 'description': 'In the workshop, Tom Silva and Kevin O\'Connor build a storage bench for an entryway.',
19 'timestamp': 1442548800,
20 'upload_date': '20150918',
21 }
22 }, {
23 'url': 'https://www.thisoldhouse.com/watch/arlington-arts-crafts-arts-and-crafts-class-begins',
24 'only_matching': True,
25 }, {
26 'url': 'https://www.thisoldhouse.com/tv-episode/ask-toh-shelf-rough-electric',
27 'only_matching': True,
28 }]
29
30 def _real_extract(self, url):
31 display_id = self._match_id(url)
32 webpage = self._download_webpage(url, display_id)
33 video_id = self._search_regex(
34 (r'data-mid=(["\'])(?P<id>(?:(?!\1).)+)\1',
35 r'id=(["\'])inline-video-player-(?P<id>(?:(?!\1).)+)\1'),
36 webpage, 'video id', default=None, group='id')
37 if not video_id:
38 drupal_settings = self._parse_json(self._search_regex(
39 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
40 webpage, 'drupal settings'), display_id)
41 video_id = try_get(
42 drupal_settings, lambda x: x['jwplatform']['video_id'],
43 compat_str) or list(drupal_settings['comScore'])[0]
44 return self.url_result('jwplatform:' + video_id, 'JWPlatform', video_id)