thisoldhouse.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from .common import InfoExtractor
  2. from ..utils import HEADRequest
  3. class ThisOldHouseIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?thisoldhouse\.com/(?:watch|how-to|tv-episode|(?:[^/]+/)?\d+)/(?P<id>[^/?#]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.thisoldhouse.com/how-to/how-to-build-storage-bench',
  7. 'info_dict': {
  8. 'id': '5dcdddf673c3f956ef5db202',
  9. 'ext': 'mp4',
  10. 'title': 'How to Build a Storage Bench',
  11. 'description': 'In the workshop, Tom Silva and Kevin O\'Connor build a storage bench for an entryway.',
  12. 'timestamp': 1442548800,
  13. 'upload_date': '20150918',
  14. 'duration': 674,
  15. 'view_count': int,
  16. 'average_rating': 0,
  17. 'thumbnail': r're:^https?://.*\.jpg\?\d+$',
  18. 'display_id': 'how-to-build-a-storage-bench',
  19. },
  20. 'params': {
  21. 'skip_download': True,
  22. },
  23. }, {
  24. 'url': 'https://www.thisoldhouse.com/watch/arlington-arts-crafts-arts-and-crafts-class-begins',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://www.thisoldhouse.com/tv-episode/ask-toh-shelf-rough-electric',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'https://www.thisoldhouse.com/furniture/21017078/how-to-build-a-storage-bench',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'https://www.thisoldhouse.com/21113884/s41-e13-paradise-lost',
  34. 'only_matching': True,
  35. }, {
  36. # iframe www.thisoldhouse.com
  37. 'url': 'https://www.thisoldhouse.com/21083431/seaside-transformation-the-westerly-project',
  38. 'only_matching': True,
  39. }]
  40. _ZYPE_TMPL = 'https://player.zype.com/embed/%s.html?api_key=hsOk_yMSPYNrT22e9pu8hihLXjaZf0JW5jsOWv4ZqyHJFvkJn6rtToHl09tbbsbe'
  41. def _real_extract(self, url):
  42. display_id = self._match_id(url)
  43. webpage = self._download_webpage(url, display_id)
  44. if 'To Unlock This content' in webpage:
  45. self.raise_login_required(method='cookies')
  46. video_url = self._search_regex(
  47. r'<iframe[^>]+src=[\'"]((?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})[^\'"]*)[\'"]',
  48. webpage, 'video url')
  49. if 'subscription_required=true' in video_url or 'c-entry-group-labels__image' in webpage:
  50. return self.url_result(self._request_webpage(HEADRequest(video_url), display_id).geturl(), 'Zype', display_id)
  51. video_id = self._search_regex(r'(?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})', video_url, 'video id')
  52. return self.url_result(self._ZYPE_TMPL % video_id, 'Zype', video_id)