]> asedeno.scripts.mit.edu Git - youtube-dl.git/blob - youtube_dl/extractor/americastestkitchen.py
[americastestkitchen] Fix Extraction and add support for Cook's Country and Cook...
[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     try_get,
10     unified_strdate,
11 )
12
13
14 class AmericasTestKitchenIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?(?:americastestkitchen|cooks(?:country|illustrated))\.com/(?P<resource_type>episode|videos)/(?P<id>\d+)'
16     _TESTS = [{
17         'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
18         'md5': 'b861c3e365ac38ad319cfd509c30577f',
19         'info_dict': {
20             'id': '5b400b9ee338f922cb06450c',
21             'title': 'Japanese Suppers',
22             'ext': 'mp4',
23             'description': 'md5:64e606bfee910627efc4b5f050de92b3',
24             'thumbnail': r're:^https?://',
25             'timestamp': 1523664000,
26             'upload_date': '20180414',
27             'release_date': '20180410',
28             'series': "America's Test Kitchen",
29             'season_number': 18,
30             'episode': 'Japanese Suppers',
31             'episode_number': 15,
32         },
33         'params': {
34             'skip_download': True,
35         },
36     }, {
37         'url': 'https://www.americastestkitchen.com/videos/3420-pan-seared-salmon',
38         'only_matching': True,
39     }, {
40         'url': 'https://www.cookscountry.com/episode/564-when-only-chocolate-will-do',
41         'only_matching': True,
42     }, {
43         'url': 'https://www.cooksillustrated.com/videos/4478-beef-wellington',
44         'only_matching': True,
45     }]
46
47     def _real_extract(self, url):
48         resource_type, video_id = re.match(self._VALID_URL, url).groups()
49         is_episode = resource_type == 'episode'
50         if is_episode:
51             resource_type = 'episodes'
52
53         resource = self._download_json(
54             'https://www.americastestkitchen.com/api/v6/%s/%s' % (resource_type, video_id), video_id)
55         video = resource['video'] if is_episode else resource
56         episode = resource if is_episode else resource.get('episode') or {}
57
58         return {
59             '_type': 'url_transparent',
60             'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % video['zypeId'],
61             'ie_key': 'Zype',
62             'description': clean_html(video.get('description')),
63             'release_date': unified_strdate(video.get('publishDate')),
64             'series': try_get(episode, lambda x: x['show']['title']),
65             'episode': episode.get('title'),
66         }