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