]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/buzzfeed.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / buzzfeed.py
1 import json
2 import re
3
4 from .common import InfoExtractor
5 from .facebook import FacebookIE
6
7
8 class BuzzFeedIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?buzzfeed\.com/[^?#]*?/(?P<id>[^?#]+)'
10 _TESTS = [{
11 'url': 'http://www.buzzfeed.com/abagg/this-angry-ram-destroys-a-punching-bag-like-a-boss?utm_term=4ldqpia',
12 'info_dict': {
13 'id': 'this-angry-ram-destroys-a-punching-bag-like-a-boss',
14 'title': 'This Angry Ram Destroys A Punching Bag Like A Boss',
15 'description': 'Rambro!',
16 },
17 'playlist': [{
18 'info_dict': {
19 'id': 'aVCR29aE_OQ',
20 'ext': 'mp4',
21 'title': 'Angry Ram destroys a punching bag..',
22 'description': 'md5:c59533190ef23fd4458a5e8c8c872345',
23 'upload_date': '20141024',
24 'uploader_id': 'Buddhanz1',
25 'uploader': 'Angry Ram',
26 },
27 }],
28 }, {
29 'url': 'http://www.buzzfeed.com/sheridanwatson/look-at-this-cute-dog-omg?utm_term=4ldqpia',
30 'params': {
31 'skip_download': True, # Got enough YouTube download tests
32 },
33 'info_dict': {
34 'id': 'look-at-this-cute-dog-omg',
35 'description': 're:Munchkin the Teddy Bear is back ?!',
36 'title': 'You Need To Stop What You\'re Doing And Watching This Dog Walk On A Treadmill',
37 },
38 'playlist': [{
39 'info_dict': {
40 'id': 'mVmBL8B-In0',
41 'ext': 'mp4',
42 'title': 're:Munchkin the Teddy Bear gets her exercise',
43 'description': 'md5:28faab95cda6e361bcff06ec12fc21d8',
44 'upload_date': '20141124',
45 'uploader_id': 'CindysMunchkin',
46 'uploader': 're:^Munchkin the',
47 },
48 }],
49 }, {
50 'url': 'http://www.buzzfeed.com/craigsilverman/the-most-adorable-crash-landing-ever#.eq7pX0BAmK',
51 'info_dict': {
52 'id': 'the-most-adorable-crash-landing-ever',
53 'title': 'Watch This Baby Goose Make The Most Adorable Crash Landing',
54 'description': 'This gosling knows how to stick a landing.',
55 },
56 'playlist': [{
57 'md5': '763ca415512f91ca62e4621086900a23',
58 'info_dict': {
59 'id': '971793786185728',
60 'ext': 'mp4',
61 'title': 'We set up crash pads so that the goslings on our roof would have a safe landi...',
62 'uploader': 'Calgary Outdoor Centre-University of Calgary',
63 },
64 }],
65 'add_ie': ['Facebook'],
66 }]
67
68 def _real_extract(self, url):
69 playlist_id = self._match_id(url)
70 webpage = self._download_webpage(url, playlist_id)
71
72 all_buckets = re.findall(
73 r'(?s)<div class="video-embed[^"]*"..*?rel:bf_bucket_data=\'([^\']+)\'',
74 webpage)
75
76 entries = []
77 for bd_json in all_buckets:
78 bd = json.loads(bd_json)
79 video = bd.get('video') or bd.get('progload_video')
80 if not video:
81 continue
82 entries.append(self.url_result(video['url']))
83
84 facebook_urls = FacebookIE._extract_embed_urls(url, webpage)
85 entries.extend([
86 self.url_result(facebook_url)
87 for facebook_url in facebook_urls])
88
89 return {
90 '_type': 'playlist',
91 'id': playlist_id,
92 'title': self._og_search_title(webpage),
93 'description': self._og_search_description(webpage),
94 'entries': entries,
95 }