]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/americastestkitchen.py
8b32aa886e9696e9334f73a777a70264f28c9433
[youtube-dl.git] / youtube_dl / extractor / americastestkitchen.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     clean_html,
7     int_or_none,
8     try_get,
9     unified_strdate,
10 )
11
12
13 class AmericasTestKitchenIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?americastestkitchen\.com/(?:episode|videos)/(?P<id>\d+)'
15     _TESTS = [{
16         'url': 'https://www.americastestkitchen.com/episode/548-summer-dinner-party',
17         'md5': 'b861c3e365ac38ad319cfd509c30577f',
18         'info_dict': {
19             'id': '1_5g5zua6e',
20             'title': 'Summer Dinner Party',
21             'ext': 'mp4',
22             'description': 'md5:858d986e73a4826979b6a5d9f8f6a1ec',
23             'thumbnail': r're:^https?://.*\.jpg',
24             'timestamp': 1497285541,
25             'upload_date': '20170612',
26             'uploader_id': 'roger.metcalf@americastestkitchen.com',
27             'release_date': '20170617',
28             'series': "America's Test Kitchen",
29             'season_number': 17,
30             'episode': 'Summer Dinner Party',
31             'episode_number': 24,
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
41     def _real_extract(self, url):
42         video_id = self._match_id(url)
43
44         webpage = self._download_webpage(url, video_id)
45
46         video_data = self._parse_json(
47             self._search_regex(
48                 r'window\.__INITIAL_STATE__\s*=\s*({.+?})\s*;\s*</script>',
49                 webpage, 'initial context'),
50             video_id)
51
52         ep_data = try_get(
53             video_data,
54             (lambda x: x['episodeDetail']['content']['data'],
55              lambda x: x['videoDetail']['content']['data']), dict)
56         ep_meta = ep_data.get('full_video', {})
57
58         zype_id = ep_meta.get('zype_id')
59         if zype_id:
60             embed_url = 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % zype_id
61             ie_key = 'Zype'
62         else:
63             partner_id = self._search_regex(
64                 r'src=["\'](?:https?:)?//(?:[^/]+\.)kaltura\.com/(?:[^/]+/)*(?:p|partner_id)/(\d+)',
65                 webpage, 'kaltura partner id')
66             external_id = ep_data.get('external_id') or ep_meta['external_id']
67             embed_url = 'kaltura:%s:%s' % (partner_id, external_id)
68             ie_key = 'Kaltura'
69
70         title = ep_data.get('title') or ep_meta.get('title')
71         description = clean_html(ep_meta.get('episode_description') or ep_data.get(
72             'description') or ep_meta.get('description'))
73         thumbnail = try_get(ep_meta, lambda x: x['photo']['image_url'])
74         release_date = unified_strdate(ep_data.get('aired_at'))
75
76         season_number = int_or_none(ep_meta.get('season_number'))
77         episode = ep_meta.get('title')
78         episode_number = int_or_none(ep_meta.get('episode_number'))
79
80         return {
81             '_type': 'url_transparent',
82             'url': embed_url,
83             'ie_key': ie_key,
84             'title': title,
85             'description': description,
86             'thumbnail': thumbnail,
87             'release_date': release_date,
88             'series': "America's Test Kitchen",
89             'season_number': season_number,
90             'episode': episode,
91             'episode_number': episode_number,
92         }