americastestkitchen.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. clean_html,
  8. int_or_none,
  9. try_get,
  10. unified_strdate,
  11. unified_timestamp,
  12. )
  13. class AmericasTestKitchenIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?(?:americastestkitchen|cooks(?:country|illustrated))\.com/(?P<resource_type>episode|videos)/(?P<id>\d+)'
  15. _TESTS = [{
  16. 'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
  17. 'md5': 'b861c3e365ac38ad319cfd509c30577f',
  18. 'info_dict': {
  19. 'id': '5b400b9ee338f922cb06450c',
  20. 'title': 'Japanese Suppers',
  21. 'ext': 'mp4',
  22. 'description': 'md5:64e606bfee910627efc4b5f050de92b3',
  23. 'thumbnail': r're:^https?://',
  24. 'timestamp': 1523318400,
  25. 'upload_date': '20180410',
  26. 'release_date': '20180410',
  27. 'series': "America's Test Kitchen",
  28. 'season_number': 18,
  29. 'episode': 'Japanese Suppers',
  30. 'episode_number': 15,
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. },
  35. }, {
  36. # Metadata parsing behaves differently for newer episodes (705) as opposed to older episodes (582 above)
  37. 'url': 'https://www.americastestkitchen.com/episode/705-simple-chicken-dinner',
  38. 'md5': '06451608c57651e985a498e69cec17e5',
  39. 'info_dict': {
  40. 'id': '5fbe8c61bda2010001c6763b',
  41. 'title': 'Simple Chicken Dinner',
  42. 'ext': 'mp4',
  43. 'description': 'md5:eb68737cc2fd4c26ca7db30139d109e7',
  44. 'thumbnail': r're:^https?://',
  45. 'timestamp': 1610755200,
  46. 'upload_date': '20210116',
  47. 'release_date': '20210116',
  48. 'series': "America's Test Kitchen",
  49. 'season_number': 21,
  50. 'episode': 'Simple Chicken Dinner',
  51. 'episode_number': 3,
  52. },
  53. 'params': {
  54. 'skip_download': True,
  55. },
  56. }, {
  57. 'url': 'https://www.americastestkitchen.com/videos/3420-pan-seared-salmon',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'https://www.cookscountry.com/episode/564-when-only-chocolate-will-do',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'https://www.cooksillustrated.com/videos/4478-beef-wellington',
  64. 'only_matching': True,
  65. }]
  66. def _real_extract(self, url):
  67. resource_type, video_id = re.match(self._VALID_URL, url).groups()
  68. is_episode = resource_type == 'episode'
  69. if is_episode:
  70. resource_type = 'episodes'
  71. resource = self._download_json(
  72. 'https://www.americastestkitchen.com/api/v6/%s/%s' % (resource_type, video_id), video_id)
  73. video = resource['video'] if is_episode else resource
  74. episode = resource if is_episode else resource.get('episode') or {}
  75. return {
  76. '_type': 'url_transparent',
  77. 'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % video['zypeId'],
  78. 'ie_key': 'Zype',
  79. 'description': clean_html(video.get('description')),
  80. 'timestamp': unified_timestamp(video.get('publishDate')),
  81. 'release_date': unified_strdate(video.get('publishDate')),
  82. 'episode_number': int_or_none(episode.get('number')),
  83. 'season_number': int_or_none(episode.get('season')),
  84. 'series': try_get(episode, lambda x: x['show']['title']),
  85. 'episode': episode.get('title'),
  86. }
  87. class AmericasTestKitchenSeasonIE(InfoExtractor):
  88. _VALID_URL = r'https?://(?:www\.)?(?P<show>americastestkitchen|cookscountry)\.com/episodes/browse/season_(?P<id>\d+)'
  89. _TESTS = [{
  90. # ATK Season
  91. 'url': 'https://www.americastestkitchen.com/episodes/browse/season_1',
  92. 'info_dict': {
  93. 'id': 'season_1',
  94. 'title': 'Season 1',
  95. },
  96. 'playlist_count': 13,
  97. }, {
  98. # Cooks Country Season
  99. 'url': 'https://www.cookscountry.com/episodes/browse/season_12',
  100. 'info_dict': {
  101. 'id': 'season_12',
  102. 'title': 'Season 12',
  103. },
  104. 'playlist_count': 13,
  105. }]
  106. def _real_extract(self, url):
  107. show_name, season_number = re.match(self._VALID_URL, url).groups()
  108. season_number = int(season_number)
  109. slug = 'atk' if show_name == 'americastestkitchen' else 'cco'
  110. season = 'Season %d' % season_number
  111. season_search = self._download_json(
  112. 'https://y1fnzxui30-dsn.algolia.net/1/indexes/everest_search_%s_season_desc_production' % slug,
  113. season, headers={
  114. 'Origin': 'https://www.%s.com' % show_name,
  115. 'X-Algolia-API-Key': '8d504d0099ed27c1b73708d22871d805',
  116. 'X-Algolia-Application-Id': 'Y1FNZXUI30',
  117. }, query={
  118. 'facetFilters': json.dumps([
  119. 'search_season_list:' + season,
  120. 'search_document_klass:episode',
  121. 'search_show_slug:' + slug,
  122. ]),
  123. 'attributesToRetrieve': 'description,search_%s_episode_number,search_document_date,search_url,title' % slug,
  124. 'attributesToHighlight': '',
  125. 'hitsPerPage': 1000,
  126. })
  127. def entries():
  128. for episode in (season_search.get('hits') or []):
  129. search_url = episode.get('search_url')
  130. if not search_url:
  131. continue
  132. yield {
  133. '_type': 'url',
  134. 'url': 'https://www.%s.com%s' % (show_name, search_url),
  135. 'id': try_get(episode, lambda e: e['objectID'].split('_')[-1]),
  136. 'title': episode.get('title'),
  137. 'description': episode.get('description'),
  138. 'timestamp': unified_timestamp(episode.get('search_document_date')),
  139. 'season_number': season_number,
  140. 'episode_number': int_or_none(episode.get('search_%s_episode_number' % slug)),
  141. 'ie_key': AmericasTestKitchenIE.ie_key(),
  142. }
  143. return self.playlist_result(
  144. entries(), 'season_%d' % season_number, season)