americastestkitchen.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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\.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. def _real_extract(self, url):
  74. resource_type, video_id = self._match_valid_url(url).groups()
  75. is_episode = resource_type == 'episode'
  76. if is_episode:
  77. resource_type = 'episodes'
  78. resource = self._download_json(
  79. 'https://www.americastestkitchen.com/api/v6/%s/%s' % (resource_type, video_id), video_id)
  80. video = resource['video'] if is_episode else resource
  81. episode = resource if is_episode else resource.get('episode') or {}
  82. return {
  83. '_type': 'url_transparent',
  84. 'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % video['zypeId'],
  85. 'ie_key': 'Zype',
  86. 'description': clean_html(video.get('description')),
  87. 'timestamp': unified_timestamp(video.get('publishDate')),
  88. 'release_date': unified_strdate(video.get('publishDate')),
  89. 'episode_number': int_or_none(episode.get('number')),
  90. 'season_number': int_or_none(episode.get('season')),
  91. 'series': try_get(episode, lambda x: x['show']['title']),
  92. 'episode': episode.get('title'),
  93. }
  94. class AmericasTestKitchenSeasonIE(InfoExtractor):
  95. _VALID_URL = r'https?://(?:www\.)?americastestkitchen\.com(?P<show>/cookscountry)?/episodes/browse/season_(?P<id>\d+)'
  96. _TESTS = [{
  97. # ATK Season
  98. 'url': 'https://www.americastestkitchen.com/episodes/browse/season_1',
  99. 'info_dict': {
  100. 'id': 'season_1',
  101. 'title': 'Season 1',
  102. },
  103. 'playlist_count': 13,
  104. }, {
  105. # Cooks Country Season
  106. 'url': 'https://www.americastestkitchen.com/cookscountry/episodes/browse/season_12',
  107. 'info_dict': {
  108. 'id': 'season_12',
  109. 'title': 'Season 12',
  110. },
  111. 'playlist_count': 13,
  112. }]
  113. def _real_extract(self, url):
  114. show_path, season_number = self._match_valid_url(url).group('show', 'id')
  115. season_number = int(season_number)
  116. slug = 'cco' if show_path == '/cookscountry' else 'atk'
  117. season = 'Season %d' % season_number
  118. season_search = self._download_json(
  119. 'https://y1fnzxui30-dsn.algolia.net/1/indexes/everest_search_%s_season_desc_production' % slug,
  120. season, headers={
  121. 'Origin': 'https://www.americastestkitchen.com',
  122. 'X-Algolia-API-Key': '8d504d0099ed27c1b73708d22871d805',
  123. 'X-Algolia-Application-Id': 'Y1FNZXUI30',
  124. }, query={
  125. 'facetFilters': json.dumps([
  126. 'search_season_list:' + season,
  127. 'search_document_klass:episode',
  128. 'search_show_slug:' + slug,
  129. ]),
  130. 'attributesToRetrieve': 'description,search_%s_episode_number,search_document_date,search_url,title' % slug,
  131. 'attributesToHighlight': '',
  132. 'hitsPerPage': 1000,
  133. })
  134. def entries():
  135. for episode in (season_search.get('hits') or []):
  136. search_url = episode.get('search_url') # always formatted like '/episode/123-title-of-episode'
  137. if not search_url:
  138. continue
  139. yield {
  140. '_type': 'url',
  141. 'url': f'https://www.americastestkitchen.com{show_path or ""}{search_url}',
  142. 'id': try_get(episode, lambda e: e['objectID'].split('_')[-1]),
  143. 'title': episode.get('title'),
  144. 'description': episode.get('description'),
  145. 'timestamp': unified_timestamp(episode.get('search_document_date')),
  146. 'season_number': season_number,
  147. 'episode_number': int_or_none(episode.get('search_%s_episode_number' % slug)),
  148. 'ie_key': AmericasTestKitchenIE.ie_key(),
  149. }
  150. return self.playlist_result(
  151. entries(), 'season_%d' % season_number, season)