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