[buzzfeed] Add new extractor (Fixes #4259)
[youtube-dl] / youtube_dl / extractor / buzzfeed.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6
7 from .common import InfoExtractor
8
9
10 class BuzzFeedIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?buzzfeed\.com/[^?#]*?/(?P<id>[^?#]+)'
12     _TEST = {
13         'url': 'http://www.buzzfeed.com/abagg/this-angry-ram-destroys-a-punching-bag-like-a-boss?utm_term=4ldqpia',
14         'info_dict': {
15             'id': 'this-angry-ram-destroys-a-punching-bag-like-a-boss',
16             'title': 'This Angry Ram Destroys A Punching Bag Like A Boss',
17             'description': 'Rambro!',
18         },
19         'playlist': [{
20             'info_dict': {
21                 'id': 'aVCR29aE_OQ',
22                 'ext': 'mp4',
23                 'upload_date': '20141024',
24                 'uploader_id': 'Buddhanz1',
25                 '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',
26                 'uploader': 'Buddhanz',
27                 'title': 'Angry Ram destroys a punching bag',
28             }
29         }]
30     }
31
32     def _real_extract(self, url):
33         playlist_id = self._match_id(url)
34         webpage = self._download_webpage(url, playlist_id)
35
36         all_buckets = re.findall(
37             r'<div class="video-embed-videopost[^"]*".*?rel:bf_bucket_data=\'([^\']+)\'',
38             webpage)
39         entries = []
40         for bd_json in all_buckets:
41             bd = json.loads(bd_json)
42             if 'video' not in bd:
43                 continue
44             entries.append(self.url_result(bd['video']['url']))
45
46         return {
47             '_type': 'playlist',
48             'id': playlist_id,
49             'title': self._og_search_title(webpage),
50             'description': self._og_search_description(webpage),
51             'entries': entries,
52         }