You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.3 KiB

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