americastestkitchen.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. clean_html,
  5. int_or_none,
  6. try_get,
  7. unified_strdate,
  8. unified_timestamp,
  9. )
  10. class AmericasTestKitchenIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?(?:americastestkitchen|cooks(?:country|illustrated))\.com/(?:cooks(?:country|illustrated)/)?(?P<resource_type>episode|videos)/(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
  14. 'md5': 'b861c3e365ac38ad319cfd509c30577f',
  15. 'info_dict': {
  16. 'id': '5b400b9ee338f922cb06450c',
  17. 'title': 'Japanese Suppers',
  18. 'ext': 'mp4',
  19. 'display_id': 'weeknight-japanese-suppers',
  20. 'description': 'md5:64e606bfee910627efc4b5f050de92b3',
  21. 'timestamp': 1523304000,
  22. 'upload_date': '20180409',
  23. 'release_date': '20180409',
  24. 'series': 'America\'s Test Kitchen',
  25. 'season': 'Season 18',
  26. 'episode': 'Japanese Suppers',
  27. 'season_number': 18,
  28. 'episode_number': 15,
  29. 'duration': 1376,
  30. 'thumbnail': r're:^https?://',
  31. 'average_rating': 0,
  32. 'view_count': int,
  33. },
  34. 'params': {
  35. 'skip_download': True,
  36. },
  37. }, {
  38. # Metadata parsing behaves differently for newer episodes (705) as opposed to older episodes (582 above)
  39. 'url': 'https://www.americastestkitchen.com/episode/705-simple-chicken-dinner',
  40. 'md5': '06451608c57651e985a498e69cec17e5',
  41. 'info_dict': {
  42. 'id': '5fbe8c61bda2010001c6763b',
  43. 'title': 'Simple Chicken Dinner',
  44. 'ext': 'mp4',
  45. 'display_id': 'atktv_2103_simple-chicken-dinner_full-episode_web-mp4',
  46. 'description': 'md5:eb68737cc2fd4c26ca7db30139d109e7',
  47. 'timestamp': 1610737200,
  48. 'upload_date': '20210115',
  49. 'release_date': '20210115',
  50. 'series': 'America\'s Test Kitchen',
  51. 'season': 'Season 21',
  52. 'episode': 'Simple Chicken Dinner',
  53. 'season_number': 21,
  54. 'episode_number': 3,
  55. 'duration': 1397,
  56. 'thumbnail': r're:^https?://',
  57. 'view_count': int,
  58. 'average_rating': 0,
  59. },
  60. 'params': {
  61. 'skip_download': True,
  62. },
  63. }, {
  64. 'url': 'https://www.americastestkitchen.com/videos/3420-pan-seared-salmon',
  65. 'only_matching': True,
  66. }, {
  67. 'url': 'https://www.americastestkitchen.com/cookscountry/episode/564-when-only-chocolate-will-do',
  68. 'only_matching': True,
  69. }, {
  70. 'url': 'https://www.americastestkitchen.com/cooksillustrated/videos/4478-beef-wellington',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'https://www.cookscountry.com/episode/564-when-only-chocolate-will-do',
  74. 'only_matching': True,
  75. }, {
  76. 'url': 'https://www.cooksillustrated.com/videos/4478-beef-wellington',
  77. 'only_matching': True,
  78. }]
  79. def _real_extract(self, url):
  80. resource_type, video_id = self._match_valid_url(url).groups()
  81. is_episode = resource_type == 'episode'
  82. if is_episode:
  83. resource_type = 'episodes'
  84. resource = self._download_json(
  85. f'https://www.americastestkitchen.com/api/v6/{resource_type}/{video_id}', video_id)
  86. video = resource['video'] if is_episode else resource
  87. episode = resource if is_episode else resource.get('episode') or {}
  88. return {
  89. '_type': 'url_transparent',
  90. 'url': 'https://player.zype.com/embed/{}.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ'.format(video['zypeId']),
  91. 'ie_key': 'Zype',
  92. 'description': clean_html(video.get('description')),
  93. 'timestamp': unified_timestamp(video.get('publishDate')),
  94. 'release_date': unified_strdate(video.get('publishDate')),
  95. 'episode_number': int_or_none(episode.get('number')),
  96. 'season_number': int_or_none(episode.get('season')),
  97. 'series': try_get(episode, lambda x: x['show']['title']),
  98. 'episode': episode.get('title'),
  99. }
  100. class AmericasTestKitchenSeasonIE(InfoExtractor):
  101. _VALID_URL = r'https?://(?:www\.)?(?P<show>americastestkitchen|(?P<cooks>cooks(?:country|illustrated)))\.com(?:(?:/(?P<show2>cooks(?:country|illustrated)))?(?:/?$|(?<!ated)(?<!ated\.com)/episodes/browse/season_(?P<season>\d+)))'
  102. _TESTS = [{
  103. # ATK Season
  104. 'url': 'https://www.americastestkitchen.com/episodes/browse/season_1',
  105. 'info_dict': {
  106. 'id': 'season_1',
  107. 'title': 'Season 1',
  108. },
  109. 'playlist_count': 13,
  110. }, {
  111. # Cooks Country Season
  112. 'url': 'https://www.americastestkitchen.com/cookscountry/episodes/browse/season_12',
  113. 'info_dict': {
  114. 'id': 'season_12',
  115. 'title': 'Season 12',
  116. },
  117. 'playlist_count': 13,
  118. }, {
  119. # America's Test Kitchen Series
  120. 'url': 'https://www.americastestkitchen.com/',
  121. 'info_dict': {
  122. 'id': 'americastestkitchen',
  123. 'title': 'America\'s Test Kitchen',
  124. },
  125. 'playlist_count': 558,
  126. }, {
  127. # Cooks Country Series
  128. 'url': 'https://www.americastestkitchen.com/cookscountry',
  129. 'info_dict': {
  130. 'id': 'cookscountry',
  131. 'title': 'Cook\'s Country',
  132. },
  133. 'playlist_count': 199,
  134. }, {
  135. 'url': 'https://www.americastestkitchen.com/cookscountry/',
  136. 'only_matching': True,
  137. }, {
  138. 'url': 'https://www.cookscountry.com/episodes/browse/season_12',
  139. 'only_matching': True,
  140. }, {
  141. 'url': 'https://www.cookscountry.com',
  142. 'only_matching': True,
  143. }, {
  144. 'url': 'https://www.americastestkitchen.com/cooksillustrated/',
  145. 'only_matching': True,
  146. }, {
  147. 'url': 'https://www.cooksillustrated.com',
  148. 'only_matching': True,
  149. }]
  150. def _real_extract(self, url):
  151. season_number, show1, show = self._match_valid_url(url).group('season', 'show', 'show2')
  152. show_path = ('/' + show) if show else ''
  153. show = show or show1
  154. season_number = int_or_none(season_number)
  155. slug, title = {
  156. 'americastestkitchen': ('atk', 'America\'s Test Kitchen'),
  157. 'cookscountry': ('cco', 'Cook\'s Country'),
  158. 'cooksillustrated': ('cio', 'Cook\'s Illustrated'),
  159. }[show]
  160. facet_filters = [
  161. 'search_document_klass:episode',
  162. 'search_show_slug:' + slug,
  163. ]
  164. if season_number:
  165. playlist_id = f'season_{season_number}'
  166. playlist_title = f'Season {season_number}'
  167. facet_filters.append('search_season_list:' + playlist_title)
  168. else:
  169. playlist_id = show
  170. playlist_title = title
  171. season_search = self._download_json(
  172. f'https://y1fnzxui30-dsn.algolia.net/1/indexes/everest_search_{slug}_season_desc_production',
  173. playlist_id, headers={
  174. 'Origin': 'https://www.americastestkitchen.com',
  175. 'X-Algolia-API-Key': '8d504d0099ed27c1b73708d22871d805',
  176. 'X-Algolia-Application-Id': 'Y1FNZXUI30',
  177. }, query={
  178. 'facetFilters': json.dumps(facet_filters),
  179. 'attributesToRetrieve': f'description,search_{slug}_episode_number,search_document_date,search_url,title,search_atk_episode_season',
  180. 'attributesToHighlight': '',
  181. 'hitsPerPage': 1000,
  182. })
  183. def entries():
  184. for episode in (season_search.get('hits') or []):
  185. search_url = episode.get('search_url') # always formatted like '/episode/123-title-of-episode'
  186. if not search_url:
  187. continue
  188. yield {
  189. '_type': 'url',
  190. 'url': f'https://www.americastestkitchen.com{show_path or ""}{search_url}',
  191. 'id': try_get(episode, lambda e: e['objectID'].split('_')[-1]),
  192. 'title': episode.get('title'),
  193. 'description': episode.get('description'),
  194. 'timestamp': unified_timestamp(episode.get('search_document_date')),
  195. 'season_number': season_number,
  196. 'episode_number': int_or_none(episode.get(f'search_{slug}_episode_number')),
  197. 'ie_key': AmericasTestKitchenIE.ie_key(),
  198. }
  199. return self.playlist_result(
  200. entries(), playlist_id, playlist_title)