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