americastestkitchen.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. try_get,
  8. unified_strdate,
  9. )
  10. class AmericasTestKitchenIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?(?:americastestkitchen|cooks(?:country|illustrated))\.com/(?P<resource_type>episode|videos)/(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'https://www.americastestkitchen.com/episode/582-weeknight-japanese-suppers',
  14. 'md5': 'b861c3e365ac38ad319cfd509c30577f',
  15. 'info_dict': {
  16. 'id': '5b400b9ee338f922cb06450c',
  17. 'title': 'Japanese Suppers',
  18. 'ext': 'mp4',
  19. 'description': 'md5:64e606bfee910627efc4b5f050de92b3',
  20. 'thumbnail': r're:^https?://',
  21. 'timestamp': 1523664000,
  22. 'upload_date': '20180414',
  23. 'release_date': '20180410',
  24. 'series': "America's Test Kitchen",
  25. 'season_number': 18,
  26. 'episode': 'Japanese Suppers',
  27. 'episode_number': 15,
  28. },
  29. 'params': {
  30. 'skip_download': True,
  31. },
  32. }, {
  33. 'url': 'https://www.americastestkitchen.com/videos/3420-pan-seared-salmon',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'https://www.cookscountry.com/episode/564-when-only-chocolate-will-do',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'https://www.cooksillustrated.com/videos/4478-beef-wellington',
  40. 'only_matching': True,
  41. }]
  42. def _real_extract(self, url):
  43. resource_type, video_id = re.match(self._VALID_URL, url).groups()
  44. is_episode = resource_type == 'episode'
  45. if is_episode:
  46. resource_type = 'episodes'
  47. resource = self._download_json(
  48. 'https://www.americastestkitchen.com/api/v6/%s/%s' % (resource_type, video_id), video_id)
  49. video = resource['video'] if is_episode else resource
  50. episode = resource if is_episode else resource.get('episode') or {}
  51. return {
  52. '_type': 'url_transparent',
  53. 'url': 'https://player.zype.com/embed/%s.js?api_key=jZ9GUhRmxcPvX7M3SlfejB6Hle9jyHTdk2jVxG7wOHPLODgncEKVdPYBhuz9iWXQ' % video['zypeId'],
  54. 'ie_key': 'Zype',
  55. 'description': clean_html(video.get('description')),
  56. 'release_date': unified_strdate(video.get('publishDate')),
  57. 'series': try_get(episode, lambda x: x['show']['title']),
  58. 'episode': episode.get('title'),
  59. }