groupon.py 2.4 KB

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