groupon.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. class GrouponIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?groupon\.com/deals/(?P<id>[^/?#&]+)'
  5. _TEST = {
  6. 'url': 'https://www.groupon.com/deals/bikram-yoga-huntington-beach-2#ooid=tubGNycTo_9Uxg82uESj4i61EYX8nyuf',
  7. 'info_dict': {
  8. 'id': 'bikram-yoga-huntington-beach-2',
  9. 'title': '$49 for 10 Yoga Classes or One Month of Unlimited Classes at Bikram Yoga Huntington Beach ($180 Value)',
  10. 'description': 'Studio kept at 105 degrees and 40% humidity with anti-microbial and anti-slip Flotex flooring; certified instructors',
  11. },
  12. 'playlist': [{
  13. 'md5': '42428ce8a00585f9bc36e49226eae7a1',
  14. 'info_dict': {
  15. 'id': 'fk6OhWpXgIQ',
  16. 'ext': 'mp4',
  17. 'title': 'Bikram Yoga Huntington Beach | Orange County !tubGNycTo@9Uxg82uESj4i61EYX8nyuf',
  18. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  19. 'duration': 45,
  20. 'upload_date': '20160405',
  21. 'uploader_id': 'groupon',
  22. 'uploader': 'Groupon',
  23. },
  24. 'add_ie': ['Youtube'],
  25. }]
  26. }
  27. _PROVIDERS = {
  28. 'ooyala': ('ooyala:%s', 'Ooyala'),
  29. 'youtube': ('%s', 'Youtube'),
  30. }
  31. def _real_extract(self, url):
  32. playlist_id = self._match_id(url)
  33. webpage = self._download_webpage(url, playlist_id)
  34. payload = self._parse_json(self._search_regex(
  35. r'(?:var\s+|window\.)payload\s*=\s*(.*?);\n', webpage, 'payload'), playlist_id)
  36. videos = payload['carousel'].get('dealVideos', [])
  37. entries = []
  38. for v in videos:
  39. provider = v.get('provider')
  40. video_id = v.get('media') or v.get('id') or v.get('baseURL')
  41. if not provider or not video_id:
  42. continue
  43. url_pattern, ie_key = self._PROVIDERS.get(provider.lower())
  44. if not url_pattern:
  45. self.report_warning(
  46. '%s: Unsupported video provider %s, skipping video' %
  47. (playlist_id, provider))
  48. continue
  49. entries.append(self.url_result(url_pattern % video_id, ie_key))
  50. return {
  51. '_type': 'playlist',
  52. 'id': playlist_id,
  53. 'entries': entries,
  54. 'title': self._og_search_title(webpage),
  55. 'description': self._og_search_description(webpage),
  56. }