]> asedeno.scripts.mit.edu Git - youtube-dl.git/blob - youtube_dl/extractor/americastestkitchen.py
[americastestkitchen] Improve metadata extraction for ATK episodes (#27860)
[youtube-dl.git] / youtube_dl / extractor / americastestkitchen.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     clean_html,
9     int_or_none,
10     try_get,
11     unified_strdate,
12     unified_timestamp,
13 )
14
15
16 class AmericasTestKitchenIE(InfoExtractor):
17     _VALID_URL = r'https?://(?:www\.)?(?:americastestkitchen|cooks(?:country|illustrated))\.com/(?P<resource_type>episode|videos)/(?P<id>\d+)'
18     _TESTS = [{
19         'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
20         'md5': 'b861c3e365ac38ad319cfd509c30577f',
21         'info_dict': {
22             'id': '5b400b9ee338f922cb06450c',
23             'title': 'Japanese Suppers',
24             'ext': 'mp4',
25             'description': 'md5:64e606bfee910627efc4b5f050de92b3',
26             'thumbnail': r're:^https?://',
27             'timestamp': 1523318400,
28             'upload_date': '20180410',
29             'release_date': '20180410',
30             'series': "America's Test Kitchen",
31             'season_number': 18,
32             'episode': 'Japanese Suppers',
33             'episode_number': 15,
34         },
35         'params': {
36             'skip_download': True,
37         },
38     }, {
39         # Metadata parsing behaves differently for newer episodes (705) as opposed to older episodes (582 above)
40         'url': 'https://www.americastestkitchen.com/episode/705-simple-chicken-dinner',
41         'md5': '06451608c57651e985a498e69cec17e5',
42         'info_dict': {
43             'id': '5fbe8c61bda2010001c6763b',
44             'title': 'Simple Chicken Dinner',
45             'ext': 'mp4',
46             'description': 'md5:eb68737cc2fd4c26ca7db30139d109e7',
47             'thumbnail': r're:^https?://',
48             'timestamp': 1610755200,
49             'upload_date': '20210116',
50             'release_date': '20210116',
51             'series': "America's Test Kitchen",
52             'season_number': 21,
53             'episode': 'Simple Chicken Dinner',
54             'episode_number': 3,
55         },
56         'params': {
57             'skip_download': True,
58         },
59     }, {
60         'url': 'https://www.americastestkitchen.com/videos/3420-pan-seared-salmon',
61         'only_matching': True,
62     }, {
63         'url': 'https://www.cookscountry.com/episode/564-when-only-chocolate-will-do',
64         'only_matching': True,
65     }, {
66         'url': 'https://www.cooksillustrated.com/videos/4478-beef-wellington',
67         'only_matching': True,
68     }]
69
70     def _real_extract(self, url):
71         resource_type, video_id = re.match(self._VALID_URL, url).groups()
72         is_episode = resource_type == 'episode'
73         if is_episode:
74             resource_type = 'episodes'
75
76         resource = self._download_json(
77             'https://www.americastestkitchen.com/api/v6/%s/%s' % (resource_type, video_id), video_id)
78         video = resource['video'] if is_episode else resource
79         episode = resource if is_episode else resource.get('episode') or {}
80
81         return {
82             '_type': 'url_transparent',
83             'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % video['zypeId'],
84             'ie_key': 'Zype',
85             'description': clean_html(video.get('description')),
86             'timestamp': unified_timestamp(video.get('publishDate')),
87             'release_date': unified_strdate(video.get('publishDate')),
88             'episode_number': int_or_none(episode.get('number')),
89             'season_number': int_or_none(episode.get('season')),
90             'series': try_get(episode, lambda x: x['show']['title']),
91             'episode': episode.get('title'),
92         }