americastestkitchen.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. int_or_none,
  8. try_get,
  9. unified_strdate,
  10. unified_timestamp,
  11. )
  12. class AmericasTestKitchenIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?(?:americastestkitchen|cooks(?:country|illustrated))\.com/(?P<resource_type>episode|videos)/(?P<id>\d+)'
  14. _TESTS = [{
  15. 'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
  16. 'md5': 'b861c3e365ac38ad319cfd509c30577f',
  17. 'info_dict': {
  18. 'id': '5b400b9ee338f922cb06450c',
  19. 'title': 'Japanese Suppers',
  20. 'ext': 'mp4',
  21. 'description': 'md5:64e606bfee910627efc4b5f050de92b3',
  22. 'thumbnail': r're:^https?://',
  23. 'timestamp': 1523318400,
  24. 'upload_date': '20180410',
  25. 'release_date': '20180410',
  26. 'series': "America's Test Kitchen",
  27. 'season_number': 18,
  28. 'episode': 'Japanese Suppers',
  29. 'episode_number': 15,
  30. },
  31. 'params': {
  32. 'skip_download': True,
  33. },
  34. }, {
  35. # Metadata parsing behaves differently for newer episodes (705) as opposed to older episodes (582 above)
  36. 'url': 'https://www.americastestkitchen.com/episode/705-simple-chicken-dinner',
  37. 'md5': '06451608c57651e985a498e69cec17e5',
  38. 'info_dict': {
  39. 'id': '5fbe8c61bda2010001c6763b',
  40. 'title': 'Simple Chicken Dinner',
  41. 'ext': 'mp4',
  42. 'description': 'md5:eb68737cc2fd4c26ca7db30139d109e7',
  43. 'thumbnail': r're:^https?://',
  44. 'timestamp': 1610755200,
  45. 'upload_date': '20210116',
  46. 'release_date': '20210116',
  47. 'series': "America's Test Kitchen",
  48. 'season_number': 21,
  49. 'episode': 'Simple Chicken Dinner',
  50. 'episode_number': 3,
  51. },
  52. 'params': {
  53. 'skip_download': True,
  54. },
  55. }, {
  56. 'url': 'https://www.americastestkitchen.com/videos/3420-pan-seared-salmon',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'https://www.cookscountry.com/episode/564-when-only-chocolate-will-do',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'https://www.cooksillustrated.com/videos/4478-beef-wellington',
  63. 'only_matching': True,
  64. }]
  65. def _real_extract(self, url):
  66. resource_type, video_id = re.match(self._VALID_URL, url).groups()
  67. is_episode = resource_type == 'episode'
  68. if is_episode:
  69. resource_type = 'episodes'
  70. resource = self._download_json(
  71. 'https://www.americastestkitchen.com/api/v6/%s/%s' % (resource_type, video_id), video_id)
  72. video = resource['video'] if is_episode else resource
  73. episode = resource if is_episode else resource.get('episode') or {}
  74. return {
  75. '_type': 'url_transparent',
  76. 'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % video['zypeId'],
  77. 'ie_key': 'Zype',
  78. 'description': clean_html(video.get('description')),
  79. 'timestamp': unified_timestamp(video.get('publishDate')),
  80. 'release_date': unified_strdate(video.get('publishDate')),
  81. 'episode_number': int_or_none(episode.get('number')),
  82. 'season_number': int_or_none(episode.get('season')),
  83. 'series': try_get(episode, lambda x: x['show']['title']),
  84. 'episode': episode.get('title'),
  85. }