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