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.

82 lines
2.9 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. js_to_json,
  8. try_get,
  9. unified_strdate,
  10. )
  11. class AmericasTestKitchenIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?americastestkitchen\.com/(?:episode|videos)/(?P<id>\d+)'
  13. _TESTS = [{
  14. 'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
  15. 'md5': 'b861c3e365ac38ad319cfd509c30577f',
  16. 'info_dict': {
  17. 'id': '5b400b9ee338f922cb06450c',
  18. 'title': 'Weeknight Japanese Suppers',
  19. 'ext': 'mp4',
  20. 'description': 'md5:3d0c1a44bb3b27607ce82652db25b4a8',
  21. 'thumbnail': r're:^https?://',
  22. 'timestamp': 1523664000,
  23. 'upload_date': '20180414',
  24. 'release_date': '20180414',
  25. 'series': "America's Test Kitchen",
  26. 'season_number': 18,
  27. 'episode': 'Weeknight Japanese Suppers',
  28. 'episode_number': 15,
  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, js_to_json)
  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_data.get('zype_id') or ep_meta['zype_id']
  51. title = ep_data.get('title') or ep_meta.get('title')
  52. description = clean_html(ep_meta.get('episode_description') or ep_data.get(
  53. 'description') or ep_meta.get('description'))
  54. thumbnail = try_get(ep_meta, lambda x: x['photo']['image_url'])
  55. release_date = unified_strdate(ep_data.get('aired_at'))
  56. season_number = int_or_none(ep_meta.get('season_number'))
  57. episode = ep_meta.get('title')
  58. episode_number = int_or_none(ep_meta.get('episode_number'))
  59. return {
  60. '_type': 'url_transparent',
  61. 'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % zype_id,
  62. 'ie_key': 'Zype',
  63. 'title': title,
  64. 'description': description,
  65. 'thumbnail': thumbnail,
  66. 'release_date': release_date,
  67. 'series': "America's Test Kitchen",
  68. 'season_number': season_number,
  69. 'episode': episode,
  70. 'episode_number': episode_number,
  71. }