logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

americastestkitchen.py (8807B)


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