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.

44 lines
1.8 KiB

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