]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bleacherreport.py
[cleanup] Fix infodict returned fields (#8906)
[yt-dlp.git] / yt_dlp / extractor / bleacherreport.py
1 from .common import InfoExtractor
2 from .amp import AMPIE
3 from ..utils import (
4 ExtractorError,
5 int_or_none,
6 parse_iso8601,
7 str_or_none,
8 )
9
10
11 class BleacherReportIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/articles/(?P<id>\d+)'
13 _TESTS = [{
14 'url': 'http://bleacherreport.com/articles/2496438-fsu-stat-projections-is-jalen-ramsey-best-defensive-player-in-college-football',
15 'md5': 'a3ffc3dc73afdbc2010f02d98f990f20',
16 'info_dict': {
17 'id': '2496438',
18 'ext': 'mp4',
19 'title': 'FSU Stat Projections: Is Jalen Ramsey Best Defensive Player in College Football?',
20 'uploader_id': '3992341',
21 'description': 'CFB, ACC, Florida State',
22 'timestamp': 1434380212,
23 'upload_date': '20150615',
24 'uploader': 'Team Stream Now ',
25 },
26 'skip': 'Video removed',
27 }, {
28 'url': 'http://bleacherreport.com/articles/2586817-aussie-golfers-get-fright-of-their-lives-after-being-chased-by-angry-kangaroo',
29 'md5': '6a5cd403418c7b01719248ca97fb0692',
30 'info_dict': {
31 'id': '2586817',
32 'ext': 'webm',
33 'title': 'Aussie Golfers Get Fright of Their Lives After Being Chased by Angry Kangaroo',
34 'timestamp': 1446839961,
35 'uploader': 'Sean Fay',
36 'description': 'md5:b1601e2314c4d8eec23b6eafe086a757',
37 'uploader_id': '6466954',
38 'upload_date': '20151011',
39 },
40 'add_ie': ['Youtube'],
41 }]
42
43 def _real_extract(self, url):
44 article_id = self._match_id(url)
45
46 article_data = self._download_json('http://api.bleacherreport.com/api/v1/articles/%s' % article_id, article_id)['article']
47
48 thumbnails = []
49 primary_photo = article_data.get('primaryPhoto')
50 if primary_photo:
51 thumbnails = [{
52 'url': primary_photo['url'],
53 'width': primary_photo.get('width'),
54 'height': primary_photo.get('height'),
55 }]
56
57 info = {
58 '_type': 'url_transparent',
59 'id': article_id,
60 'title': article_data['title'],
61 'uploader': article_data.get('author', {}).get('name'),
62 'uploader_id': str_or_none(article_data.get('authorId')),
63 'timestamp': parse_iso8601(article_data.get('createdAt')),
64 'thumbnails': thumbnails,
65 'comment_count': int_or_none(article_data.get('commentsCount')),
66 'view_count': int_or_none(article_data.get('hitCount')),
67 }
68
69 video = article_data.get('video')
70 if video:
71 video_type = video['type']
72 if video_type in ('cms.bleacherreport.com', 'vid.bleacherreport.com'):
73 info['url'] = 'http://bleacherreport.com/video_embed?id=%s' % video['id']
74 elif video_type == 'youtube.com':
75 info['url'] = video['id']
76 elif video_type == 'vine.co':
77 info['url'] = 'https://vine.co/v/%s' % video['id']
78 else:
79 info['url'] = video_type + video['id']
80 return info
81 else:
82 raise ExtractorError('no video in the article', expected=True)
83
84
85 class BleacherReportCMSIE(AMPIE):
86 _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/video_embed\?id=(?P<id>[0-9a-f-]{36}|\d{5})'
87 _TESTS = [{
88 'url': 'http://bleacherreport.com/video_embed?id=8fd44c2f-3dc5-4821-9118-2c825a98c0e1&library=video-cms',
89 'md5': '670b2d73f48549da032861130488c681',
90 'info_dict': {
91 'id': '8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
92 'ext': 'mp4',
93 'title': 'Cena vs. Rollins Would Expose the Heavyweight Division',
94 'description': 'md5:984afb4ade2f9c0db35f3267ed88b36e',
95 'upload_date': '20150723',
96 'timestamp': 1437679032,
97
98 },
99 'expected_warnings': [
100 'Unable to download f4m manifest'
101 ]
102 }]
103
104 def _real_extract(self, url):
105 video_id = self._match_id(url)
106 info = self._extract_feed_info('http://vid.bleacherreport.com/videos/%s.akamai' % video_id)
107 info['id'] = video_id
108 return info