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.

75 lines
2.7 KiB

  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. _TESTS = [{
  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. 'url': 'http://www.buzzfeed.com/sheridanwatson/look-at-this-cute-dog-omg?utm_term=4ldqpia',
  28. 'params': {
  29. 'skip_download': True, # Got enough YouTube download tests
  30. },
  31. 'info_dict': {
  32. 'id': 'look-at-this-cute-dog-omg',
  33. 'description': 're:Munchkin the Teddy Bear is back ?!',
  34. 'title': 'You Need To Stop What You\'re Doing And Watching This Dog Walk On A Treadmill',
  35. },
  36. 'playlist': [{
  37. 'info_dict': {
  38. 'id': 'mVmBL8B-In0',
  39. 'ext': 'mp4',
  40. 'upload_date': '20141124',
  41. 'uploader_id': 'CindysMunchkin',
  42. 'description': 're:© 2014 Munchkin the',
  43. 'uploader': 're:^Munchkin the',
  44. 'title': 're:Munchkin the Teddy Bear gets her exercise',
  45. },
  46. }]
  47. }]
  48. def _real_extract(self, url):
  49. playlist_id = self._match_id(url)
  50. webpage = self._download_webpage(url, playlist_id)
  51. all_buckets = re.findall(
  52. r'(?s)<div class="video-embed[^"]*"..*?rel:bf_bucket_data=\'([^\']+)\'',
  53. webpage)
  54. entries = []
  55. for bd_json in all_buckets:
  56. bd = json.loads(bd_json)
  57. video = bd.get('video') or bd.get('progload_video')
  58. if not video:
  59. continue
  60. entries.append(self.url_result(video['url']))
  61. return {
  62. '_type': 'playlist',
  63. 'id': playlist_id,
  64. 'title': self._og_search_title(webpage),
  65. 'description': self._og_search_description(webpage),
  66. 'entries': entries,
  67. }