buzzfeed.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. class BuzzFeedIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?buzzfeed\.com/[^?#]*?/(?P<id>[^?#]+)'
  8. _TEST = {
  9. 'url': 'http://www.buzzfeed.com/abagg/this-angry-ram-destroys-a-punching-bag-like-a-boss?utm_term=4ldqpia',
  10. 'info_dict': {
  11. 'id': 'this-angry-ram-destroys-a-punching-bag-like-a-boss',
  12. 'title': 'This Angry Ram Destroys A Punching Bag Like A Boss',
  13. 'description': 'Rambro!',
  14. },
  15. 'playlist': [{
  16. 'info_dict': {
  17. 'id': 'aVCR29aE_OQ',
  18. 'ext': 'mp4',
  19. 'upload_date': '20141024',
  20. 'uploader_id': 'Buddhanz1',
  21. 'description': 'He likes to stay in shape with his heavy bag, he wont stop until its on the ground\n\nFollow Angry Ram on Facebook for regular updates -\nhttps://www.facebook.com/pages/Angry-Ram/1436897249899558?ref=hl',
  22. 'uploader': 'Buddhanz',
  23. 'title': 'Angry Ram destroys a punching bag',
  24. }
  25. }]
  26. }
  27. def _real_extract(self, url):
  28. playlist_id = self._match_id(url)
  29. webpage = self._download_webpage(url, playlist_id)
  30. all_buckets = re.findall(
  31. r'<div class="video-embed-videopost[^"]*".*?rel:bf_bucket_data=\'([^\']+)\'',
  32. webpage)
  33. entries = []
  34. for bd_json in all_buckets:
  35. bd = json.loads(bd_json)
  36. if 'video' not in bd:
  37. continue
  38. entries.append(self.url_result(bd['video']['url']))
  39. return {
  40. '_type': 'playlist',
  41. 'id': playlist_id,
  42. 'title': self._og_search_title(webpage),
  43. 'description': self._og_search_description(webpage),
  44. 'entries': entries,
  45. }